Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

CLOCK

 ui/style.dart :
import 'package:flutter/material.dart';

class AppStyle {

static Color primaryColor = const Color(0xFF2253FF);

static Color primaryColorDark = const Color(0xFF193bb1);

static TextStyle mainText = const TextStyle(

color: Colors.black,

fontSize: 32.0,

fontWeight: FontWeight.bold,

);

static TextStyle mainTextWhite = const TextStyle(

color: Colors.white,

fontSize: 32.0,

fontWeight: FontWeight.bold,

);

static TextStyle mainTextThin= const TextStyle(

color: Colors.black87,

fontSize: 32.0,

fontWeight: FontWeight.w300,

);

static TextStyle mainTextThinWhite = const TextStyle(

color: Colors.white60,

fontSize: 32.0,

fontWeight: FontWeight.w300,

);
}

 utils / time_model.dart :
class TimeModel {

int? sec;

int? min;

int? hour;

TimeModel(this.hour, this.min, this.sec);

 Widget :
 clock_widget.dart :
import 'dart:math';

import 'package:flutter/material.dart';

import 'package:flutter_hello/ui/style.dart';

import 'package:flutter_hello/utils/time_model.dart';

// ignore: must_be_immutable

class ClockWidget extends StatefulWidget {

ClockWidget(this.time,{super.key});

TimeModel time;

@override

State<ClockWidget> createState() => _ClockWidgetState();

class _ClockWidgetState extends State<ClockWidget> {

@override

Widget build(BuildContext context) {


return Container(

//Let's add a decoration to the container

decoration: BoxDecoration(

shape: BoxShape.circle,

//Let's add some effects

boxShadow: [

BoxShadow(color: AppStyle.primaryColor.withAlpha(80), blurRadius: 38.0),

),

height: 300.0,

width: 300.0,

child: CustomPaint(

painter: ClockPainter(widget.time),

),

);

class ClockPainter extends CustomPainter{

//Let's set the time parameter

TimeModel? time;

ClockPainter(this.time);

@override

void paint(Canvas canvas, Size size) {

// Let's calculate the time possition

double secRad = ((pi/2) - (pi/30) * time!.sec!) % (2*pi);

double minRad = ((pi/2) - (pi/30) * time!.min!) % (2*pi);

double hourRad = ((pi/2) - (pi/6) * time!.hour!) % (2*pi);

//Let's set some important pointqs coordinates


var centerX = size.width / 2;

var centerY = size.height / 2;

var center = Offset(centerX, centerY);

var radius = min(centerX, centerY);

//setting the clock coordinate

var secHeight = radius / 2;

var minHeight = radius / 2 - 10;

var hourHeight = radius / 2 - 25;

var seconds = Offset(centerX + secHeight * cos(secRad), centerY - secHeight * sin(secRad));

var minutes = Offset(centerX + minHeight * cos(minRad), centerY - minHeight * sin(minRad));

var hours = Offset(centerX + hourHeight * cos(hourRad), centerY - hourHeight * sin(hourRad));

//Setting the Brush

var fillBrush = Paint()

..color = AppStyle.primaryColor

..strokeCap = StrokeCap.round;

var centerDotBrush = Paint()..color = const Color(0xFFEAECFF);

//setting the hand brush

var secBrush = Paint()

..color = Colors.red

..style = PaintingStyle.stroke

..strokeCap = StrokeCap.round

..strokeWidth = 2

..strokeJoin = StrokeJoin.round;

var minBrush = Paint()

..color = Colors.white

..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round

..strokeWidth = 3

..strokeJoin = StrokeJoin.round;

var hourBrush = Paint()

..color = Colors.white

..style = PaintingStyle.stroke

..strokeCap = StrokeCap.round

..strokeWidth = 4

..strokeJoin = StrokeJoin.round;

//drawing the body

canvas.drawCircle(center, radius - 40, fillBrush);

//drawing the clock hands

canvas.drawLine(center, seconds, secBrush);

canvas.drawLine(center, minutes, minBrush);

canvas.drawLine(center, hours, hourBrush);

//drawing ther center dot

canvas.drawCircle(center, 16, centerDotBrush);

@override

bool shouldRepaint(covariant CustomPainter oldDelegate) {

return true;

}
 main.dart :
//import 'dart:async';

import 'package:flutter/material.dart';

import 'package:flutter_hello/ui/style.dart';

import 'package:flutter_hello/utils/time_model.dart';

import 'package:flutter_hello/widgets/clock_widget.dart';

import 'package:timer_builder/timer_builder.dart';

void main() {

runApp(const MyApp());

class MyApp extends StatelessWidget {

const MyApp({super.key});

@override

Widget build(BuildContext context) {

return const MaterialApp(

home: HomePage(),

);

class HomePage extends StatefulWidget {

const HomePage({super.key});

@override

State<HomePage> createState() => _HomePageState();

}
class _HomePageState extends State<HomePage> {

@override

Widget build(BuildContext context) {

return Scaffold(

body: SafeArea(

child: Padding(

padding: const EdgeInsets.all(24.0),

child: Column(

children: [

//now we need to upgrade the clock value each seconds

TimerBuilder.periodic(const Duration(seconds: 1), builder: (context){

var currentTime = DateTime.now();

//Let's set the digital clock string values

String seconds = currentTime.second < 10 ?"0${currentTime.second}":"${currentTime.second}";

String minutes = currentTime.minute < 10 ?"0${currentTime.minute}":"${currentTime.minute}";

String hours = currentTime.hour < 10 ?"0${currentTime.hour}":"${currentTime.hour}";

return Column(

children: [

Row(

mainAxisAlignment: MainAxisAlignment.spaceBetween,

children: [

Text("To Dinh Phuc", style: AppStyle.mainTextThin),

Text(

"$hours:$minutes:$seconds",

style: AppStyle.mainText,

),

],

),

Center(

child: ClockWidget(TimeModel(currentTime.hour, currentTime.minute, currentTime.second))),


],

);

})

],

),

),

),

);

}
QUAN LI KHO
 main.dart :
import 'package:flutter/material.dart';

import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';

void main() => runApp(const MyApp());

class Product {

String barcode;

String name;

double price;

int quantity;

DateTime date;

Product({

required this.barcode,

required this.name,

required this.price,

required this.quantity,

required this.date,

});

class MyApp extends StatelessWidget {

const MyApp({super.key});

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'Quản Lí Kho Hàng',


theme: ThemeData(

primarySwatch: Colors.brown,

),

home: const MyHomePage(),

);

class MyHomePage extends StatefulWidget {

const MyHomePage({super.key});

@override

// ignore: library_private_types_in_public_api

_MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {

List<Product> inventory = [];

Future<void> _scanQRCode() async {

try {

String barcode = await FlutterBarcodeScanner.scanBarcode(

'#ff6666',

'Thoát',

true,

ScanMode.QR,

);

if (barcode != '-1') {

Product existingProduct = inventory.firstWhere(

(product) => product.barcode == barcode,

orElse: () => Product(


barcode: barcode,

name: '',

price: 0.0,

quantity: 0,

date: DateTime.now(),

),

);

_showAddProductDialog(existingProduct);

} catch (e) {

print('Error scanning QR code: $e');

void _showAddProductDialog(Product existingProduct) {

TextEditingController nameController =

TextEditingController(text: existingProduct.name);

TextEditingController priceController =

TextEditingController(text: existingProduct.price.toString());

TextEditingController quantityController =

TextEditingController(text: existingProduct.quantity.toString());

TextEditingController dateController =

TextEditingController(text: existingProduct.quantity.toString());

showDialog(

context: context,

builder: (BuildContext context) {

return AlertDialog(

title: const Text('Thêm sản phẩm'),

content: Column(

children: <Widget>[

Text('Quét QR Code: ${existingProduct.barcode}'),


TextField(

controller: nameController,

decoration: const InputDecoration(labelText: 'Tên sản phẩm'),

),

TextField(

controller: priceController,

keyboardType: TextInputType.number,

decoration: const InputDecoration(labelText: 'Giá cả'),

),

TextField(

controller: quantityController,

keyboardType: TextInputType.number,

decoration: const InputDecoration(labelText: 'Số lượng'),

),

],

),

actions: <Widget>[

TextButton(

child: const Text('Thoát'),

onPressed: () {

Navigator.of(context).pop();

},

),

TextButton(

child: const Text('Thêm'),

onPressed: () {

if (nameController.text.isNotEmpty &&

priceController.text.isNotEmpty &&

quantityController.text.isNotEmpty) {

if (existingProduct.name.isEmpty) {

// If the product doesn't exist, create a new one with the current date and time

Product newProduct = Product(


barcode: existingProduct.barcode,

name: nameController.text,

price: double.parse(priceController.text),

quantity: int.parse(quantityController.text),

date: DateTime.now(),

);

setState(() {

inventory.add(newProduct);

});

} else {

// If the product exists, update the quantity

int updatedQuantity = existingProduct.quantity +

int.parse(quantityController.text);

int productIndex = inventory.indexOf(existingProduct);

setState(() {

inventory[productIndex].quantity = updatedQuantity;

});

Navigator.of(context).pop();

},

),

],

);

},

);

void _showInventoryDialog() {

showDialog(

context: context,

builder: (BuildContext context) {


return AlertDialog(

title: const Text('Tồn kho'),

content: SizedBox(

width: double.maxFinite,

child: ListView.builder(

itemCount: inventory.length,

itemBuilder: (context, index) {

Product product = inventory[index];

return ListTile(

title: Text('Tên sản phẩm: ${product.name}'),

subtitle: Text(

'Mã QR: ${product.barcode}\n'

'Giá: ${product.price.toStringAsFixed(2)} VNĐ\n'

'Số lượng: ${product.quantity}\n'

'Ngày vào kho: ${product.date.toString()}',

),

);

},

),

),

actions: <Widget>[

TextButton(

child: const Text('Đóng'),

onPressed: () {

Navigator.of(context).pop();

},

),

],

);

},

);

}
void _sellProduct() async {

try {

String barcode = await FlutterBarcodeScanner.scanBarcode(

'#ff6666',

'Thoát',

true,

ScanMode.QR,

);

if (barcode != '-1') {

Product productToSell = inventory.firstWhere(

(product) => product.barcode == barcode,

orElse: () => Product(

barcode: barcode,

name: 'Unknown Product',

price: 0.0,

quantity: 0,

date: DateTime.now(),

),

);

if (productToSell.quantity > 0) {

// If the product exists and has quantity, reduce the quantity by 1

int productIndex = inventory.indexOf(productToSell);

setState(() {

inventory[productIndex].quantity -= 1;

});

if (productToSell.quantity == -1) {

_showFailDialog();

} else {
_showSuccessDialog(productToSell);

print(

'Bán 1 ${productToSell.name}. Số lượng còn lại: ${productToSell.quantity}');

} else {

print('No stock available for product with barcode $barcode');

_showFailDialog();

} catch (e) {

print('Error selling product: $e');

void _showSuccessDialog(Product soldProduct) {

showDialog(

context: context,

builder: (BuildContext context) {

return AlertDialog(

title: const Text('Bán thành công'),

content: Text(

'Bán 1 ${soldProduct.name}. Số lượng còn lại: ${soldProduct.quantity}'),

actions: [

ElevatedButton(

onPressed: () {

Navigator.of(context).pop();

},

child: const Text('OK'),

),

],

);

},
);

void _showFailDialog() {

showDialog(

context: context,

builder: (BuildContext context) {

return AlertDialog(

title: const Text('Lỗi'),

content: const Text('Không có sản phầm trong kho'),

actions: [

ElevatedButton(

onPressed: () {

Navigator.of(context).pop();

},

child: const Text('OK'),

),

],

);

},

);

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: const Text('To Dinh Phuc'),

backgroundColor: Colors.amber,

),

body: Center(

child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,

children: <Widget>[

ElevatedButton(

onPressed: _scanQRCode,

style: ButtonStyle(

backgroundColor: MaterialStateProperty.all<Color>(Colors.amber),

padding: MaterialStateProperty.all<EdgeInsets>(

const EdgeInsets.symmetric(vertical: 5, horizontal: 5),

),

),

child: const Text(

'Quét mã QR',

style: TextStyle(fontSize: 18),

),

),

const SizedBox(height: 90),

ElevatedButton(

onPressed: _showInventoryDialog,

style: ButtonStyle(

backgroundColor: MaterialStateProperty.all<Color>(Colors.amber),

padding: MaterialStateProperty.all<EdgeInsets>(

const EdgeInsets.symmetric(vertical: 5, horizontal: 5),

),

),

child: const Text(

'Hiển thị kho',

style: TextStyle(fontSize: 18),

),

),

const SizedBox(height: 90),

ElevatedButton(

onPressed: _sellProduct,
style: ButtonStyle(

backgroundColor: MaterialStateProperty.all<Color>(Colors.amber),

padding: MaterialStateProperty.all<EdgeInsets>(

const EdgeInsets.symmetric(vertical: 5, horizontal: 5),

),

),

child: const Text(

'Xuất kho',

style: TextStyle(fontSize: 18),

),

),

],

),

),

);

}
GIS-MAP HIGHSCHOOL IN THU DUC, HCM CITY
 main.dart :
import 'package:flutter/material.dart';

import 'package:flutter_map/flutter_map.dart';

import 'package:latlong2/latlong.dart';

void main() {

runApp(const MyApp());

class MyApp extends StatelessWidget {

const MyApp({super.key});

// This widget is the root of your application.

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'GIS - MAP',

theme: ThemeData(

colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),

useMaterial3: true,

),

home: const MyHomePage(title: 'Flutter Demo Home Page'),

);

class MyHomePage extends StatefulWidget {

const MyHomePage({super.key, required this.title});


final String title;

@override

State<MyHomePage> createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {

List<bool> flags = [false, false, false, false, false, false, false, false, false, false, false];

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

backgroundColor: Theme.of(context).colorScheme.inversePrimary,

title: const Text(

'TÔ ĐÌNH PHÚC - 20119366 \n Gismap about High School in Thu Duc, HCM city',

style: TextStyle(fontSize: 22),

),

),

body: content(),

);

Widget content() {

return FlutterMap(

options: const MapOptions(

initialCenter: LatLng(10.8544, 106.7564),

initialZoom: 12,

interactionOptions:

InteractionOptions(flags: ~InteractiveFlag.doubleTapZoom)
),

children: [

openStreetMapTileLayer,

//THPT Linh Trung

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.861701, 106.784413),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THPT Linh Trung') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),
//THPT Nguyen Huu Huan

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.848538, 106.768060),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THPT Nguyen Huu Huan') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),

//THPT chuyen Tran Dai Nghia

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];
});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.783547, 106.737800),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THPT chuyen Tran Dai Nghia') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),

//THPT nang khieu, Dai Hoc Quoc Gia TpHCM

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.877550, 106.799440),


width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THPT Nang Khieu, Dai Hoc Quoc Gia TpHCM') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),

//THPT Phuong Nam

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.844630, 106.700968),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [
flags[0] ? const Text('THPT Phuong Nam') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),

//THCS - THPT Nguyen Khuyen

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.838675, 106.712906),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THCS - THPT Nguyen Khuyen ') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,
),

],

),

),

],),

),

//THPT Thu Duc

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.848030, 106.761648),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THPT Thu Duc') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),
),

//THPT Tam Phu

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.864861, 106.746615),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THPT Tam Phu') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),

//THPT Hiep Binh

GestureDetector(

onTap: () {
setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.847704, 106.722209),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THPT Hiep Binh') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),

//THPT Dao Son Tay

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [
Marker(

point: const LatLng(10.877573, 106.773250),

width: 60,

height: 60,

alignment: Alignment.centerLeft,

child: Column(

children: [

flags[0] ? const Text('THPT Dao Son Tay') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),

//THPT Binh Chieu

GestureDetector(

onTap: () {

setState(() {

flags[0] = !flags[0];

});

},

child: MarkerLayer(markers: [

Marker(

point: const LatLng(10.876729, 106.740468),

width: 60,

height: 60,

alignment: Alignment.centerLeft,
child: Column(

children: [

flags[0] ? const Text('THPT Binh Chieu') : const SizedBox.shrink(),

const Icon(

Icons.location_pin,

size: 30,

color: Colors.red,

),

],

),

),

],),

),

],);

TileLayer get openStreetMapTileLayer => TileLayer(

urlTemplate: 'http://tile.openstreetmap.org/{z}/{x}/{y}.png',

userAgentPackageName: 'dev.fleaflet.flutter_map.example',

);

You might also like