From beb2048a7a6fea9f77d279a03c460ffb2af2fd2d Mon Sep 17 00:00:00 2001 From: Stephane Date: Sat, 31 May 2025 00:17:19 +0300 Subject: [PATCH] boutton scan qr --- lib/Models/pointage_model.dart | 36 +++++++------ lib/Services/pointageDatabase.dart | 23 ++++---- lib/Views/pointage.dart | 85 ++++++++++++++++++++++++------ 3 files changed, 101 insertions(+), 43 deletions(-) diff --git a/lib/Models/pointage_model.dart b/lib/Models/pointage_model.dart index 3f5c33b..f7afeed 100644 --- a/lib/Models/pointage_model.dart +++ b/lib/Models/pointage_model.dart @@ -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 json) { + // Pour SQLite + factory Pointage.fromMap(Map 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 toJson() { + Map toMap() { return { 'id': id, + 'userName': userName, 'date': date, 'heureArrivee': heureArrivee, 'heureDepart': heureDepart, diff --git a/lib/Services/pointageDatabase.dart b/lib/Services/pointageDatabase.dart index 24aa0af..cc162ff 100644 --- a/lib/Services/pointageDatabase.dart +++ b/lib/Services/pointageDatabase.dart @@ -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 get db async { + Future 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 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> getPointages() async { - Database db = await this.db; - List> 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 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 deletePointage(int id) async { - Database db = await this.db; + final db = await database; return await db.delete('pointages', where: 'id = ?', whereArgs: [id]); } } diff --git a/lib/Views/pointage.dart b/lib/Views/pointage.dart index a33f671..934ac29 100644 --- a/lib/Views/pointage.dart +++ b/lib/Views/pointage.dart @@ -49,6 +49,8 @@ class _PointagePageState extends State { 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 { ); } + 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 { ), 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 { 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', + ), + ], ), ); }