boutton scan qr
This commit is contained in:
parent
b1d176aa2a
commit
beb2048a7a
@ -1,27 +1,33 @@
|
||||
class Pointage {
|
||||
int? id;
|
||||
String date;
|
||||
String heureArrivee;
|
||||
String heureDepart;
|
||||
final int? id;
|
||||
final String userName;
|
||||
final String date;
|
||||
final String heureArrivee;
|
||||
final String heureDepart;
|
||||
|
||||
Pointage(
|
||||
{this.id,
|
||||
required this.date,
|
||||
required this.heureArrivee,
|
||||
required this.heureDepart});
|
||||
Pointage({
|
||||
this.id,
|
||||
required this.userName,
|
||||
required this.date,
|
||||
required this.heureArrivee,
|
||||
required this.heureDepart,
|
||||
});
|
||||
|
||||
factory Pointage.fromJson(Map<String, dynamic> json) {
|
||||
// Pour SQLite
|
||||
factory Pointage.fromMap(Map<String, dynamic> map) {
|
||||
return Pointage(
|
||||
id: json['id'],
|
||||
date: json['date'],
|
||||
heureArrivee: json['heureArrivee'],
|
||||
heureDepart: json['heureDepart'],
|
||||
id: map['id'],
|
||||
userName: map['userName'] ?? '',
|
||||
date: map['date'],
|
||||
heureArrivee: map['heureArrivee'],
|
||||
heureDepart: map['heureDepart'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'userName': userName,
|
||||
'date': date,
|
||||
'heureArrivee': heureArrivee,
|
||||
'heureDepart': heureDepart,
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
// database_helper.dart
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import '../Models/pointage_model.dart'; // Import your Pointage model
|
||||
import '../Models/pointage_model.dart';
|
||||
|
||||
class DatabaseHelper {
|
||||
static final DatabaseHelper _instance = DatabaseHelper._internal();
|
||||
@ -14,7 +12,7 @@ class DatabaseHelper {
|
||||
|
||||
Database? _db;
|
||||
|
||||
Future<Database> get db async {
|
||||
Future<Database> get database async {
|
||||
if (_db != null) return _db!;
|
||||
_db = await _initDatabase();
|
||||
return _db!;
|
||||
@ -30,6 +28,7 @@ class DatabaseHelper {
|
||||
await db.execute('''
|
||||
CREATE TABLE pointages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
userName TEXT NOT NULL,
|
||||
date TEXT NOT NULL,
|
||||
heureArrivee TEXT NOT NULL,
|
||||
heureDepart TEXT NOT NULL
|
||||
@ -38,24 +37,24 @@ class DatabaseHelper {
|
||||
}
|
||||
|
||||
Future<int> insertPointage(Pointage pointage) async {
|
||||
Database db = await this.db;
|
||||
return await db.insert('pointages', pointage.toJson());
|
||||
final db = await database;
|
||||
return await db.insert('pointages', pointage.toMap());
|
||||
}
|
||||
|
||||
Future<List<Pointage>> getPointages() async {
|
||||
Database db = await this.db;
|
||||
List<Map<String, dynamic>> pointages = await db.query('pointages');
|
||||
return pointages.map((pointage) => Pointage.fromJson(pointage)).toList();
|
||||
final db = await database;
|
||||
final pointages = await db.query('pointages');
|
||||
return pointages.map((pointage) => Pointage.fromMap(pointage)).toList();
|
||||
}
|
||||
|
||||
Future<int> updatePointage(Pointage pointage) async {
|
||||
Database db = await this.db;
|
||||
return await db.update('pointages', pointage.toJson(),
|
||||
final db = await database;
|
||||
return await db.update('pointages', pointage.toMap(),
|
||||
where: 'id = ?', whereArgs: [pointage.id]);
|
||||
}
|
||||
|
||||
Future<int> deletePointage(int id) async {
|
||||
Database db = await this.db;
|
||||
final db = await database;
|
||||
return await db.delete('pointages', where: 'id = ?', whereArgs: [id]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,8 @@ class _PointagePageState extends State<PointagePage> {
|
||||
child: Text('Ajouter'),
|
||||
onPressed: () async {
|
||||
final pointage = Pointage(
|
||||
userName:
|
||||
"Nom de l'utilisateur", // fixed value, customize if needed
|
||||
date: DateTime.now().toString().split(' ')[0],
|
||||
heureArrivee: _arrivalController.text,
|
||||
heureDepart: '',
|
||||
@ -64,6 +66,15 @@ class _PointagePageState extends State<PointagePage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _scanQRCode({required bool isEntree}) {
|
||||
// Ici tu peux intégrer ton scanner QR.
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(isEntree ? "Scan QR pour Entrée" : "Scan QR pour Sortie"),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -86,19 +97,36 @@ class _PointagePageState extends State<PointagePage> {
|
||||
),
|
||||
elevation: 4,
|
||||
shadowColor: Colors.blueGrey.shade50,
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Colors.blue.shade100,
|
||||
child: Icon(Icons.calendar_today, color: Colors.blue),
|
||||
),
|
||||
title: Text(
|
||||
pointage.date,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Column(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8.0, vertical: 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
backgroundColor: Colors.blue.shade100,
|
||||
child: Icon(Icons.person, color: Colors.blue),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
pointage
|
||||
.userName, // suppose non-null (corrige si null possible)
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Divider(),
|
||||
Text(
|
||||
pointage.date,
|
||||
style: const TextStyle(
|
||||
color: Colors.black87, fontSize: 15),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.login,
|
||||
@ -119,18 +147,43 @@ class _PointagePageState extends State<PointagePage> {
|
||||
style: TextStyle(color: Colors.red.shade700)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
],
|
||||
),
|
||||
isThreeLine: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _showAddDialog,
|
||||
tooltip: 'Ajouter Pointage',
|
||||
child: const Icon(Icons.add),
|
||||
floatingActionButton: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
FloatingActionButton.extended(
|
||||
onPressed: () => _scanQRCode(isEntree: true),
|
||||
label: Text('Entrée'),
|
||||
icon: Icon(Icons.qr_code_scanner, color: Colors.green),
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: Colors.green,
|
||||
heroTag: 'btnEntree',
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
FloatingActionButton.extended(
|
||||
onPressed: () => _scanQRCode(isEntree: false),
|
||||
label: Text('Sortie'),
|
||||
icon: Icon(Icons.qr_code_scanner, color: Colors.red),
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: Colors.red,
|
||||
heroTag: 'btnSortie',
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
FloatingActionButton(
|
||||
onPressed: _showAddDialog,
|
||||
tooltip: 'Ajouter Pointage',
|
||||
child: const Icon(Icons.add),
|
||||
heroTag: 'btnAdd',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user