Browse Source

boutton scan qr

master
Stephane 6 months ago
parent
commit
beb2048a7a
  1. 32
      lib/Models/pointage_model.dart
  2. 23
      lib/Services/pointageDatabase.dart
  3. 75
      lib/Views/pointage.dart

32
lib/Models/pointage_model.dart

@ -1,27 +1,33 @@
class Pointage { class Pointage {
int? id; final int? id;
String date; final String userName;
String heureArrivee; final String date;
String heureDepart; final String heureArrivee;
final String heureDepart;
Pointage( Pointage({
{this.id, this.id,
required this.userName,
required this.date, required this.date,
required this.heureArrivee, required this.heureArrivee,
required this.heureDepart}); required this.heureDepart,
});
factory Pointage.fromJson(Map<String, dynamic> json) { // Pour SQLite
factory Pointage.fromMap(Map<String, dynamic> map) {
return Pointage( return Pointage(
id: json['id'], id: map['id'],
date: json['date'], userName: map['userName'] ?? '',
heureArrivee: json['heureArrivee'], date: map['date'],
heureDepart: json['heureDepart'], heureArrivee: map['heureArrivee'],
heureDepart: map['heureDepart'],
); );
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toMap() {
return { return {
'id': id, 'id': id,
'userName': userName,
'date': date, 'date': date,
'heureArrivee': heureArrivee, 'heureArrivee': heureArrivee,
'heureDepart': heureDepart, 'heureDepart': heureDepart,

23
lib/Services/pointageDatabase.dart

@ -1,9 +1,7 @@
// database_helper.dart
import 'dart:async'; import 'dart:async';
import 'package:path/path.dart'; import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart'; import 'package:sqflite/sqflite.dart';
import '../Models/pointage_model.dart'; // Import your Pointage model import '../Models/pointage_model.dart';
class DatabaseHelper { class DatabaseHelper {
static final DatabaseHelper _instance = DatabaseHelper._internal(); static final DatabaseHelper _instance = DatabaseHelper._internal();
@ -14,7 +12,7 @@ class DatabaseHelper {
Database? _db; Database? _db;
Future<Database> get db async { Future<Database> get database async {
if (_db != null) return _db!; if (_db != null) return _db!;
_db = await _initDatabase(); _db = await _initDatabase();
return _db!; return _db!;
@ -30,6 +28,7 @@ class DatabaseHelper {
await db.execute(''' await db.execute('''
CREATE TABLE pointages ( CREATE TABLE pointages (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
userName TEXT NOT NULL,
date TEXT NOT NULL, date TEXT NOT NULL,
heureArrivee TEXT NOT NULL, heureArrivee TEXT NOT NULL,
heureDepart TEXT NOT NULL heureDepart TEXT NOT NULL
@ -38,24 +37,24 @@ class DatabaseHelper {
} }
Future<int> insertPointage(Pointage pointage) async { Future<int> insertPointage(Pointage pointage) async {
Database db = await this.db; final db = await database;
return await db.insert('pointages', pointage.toJson()); return await db.insert('pointages', pointage.toMap());
} }
Future<List<Pointage>> getPointages() async { Future<List<Pointage>> getPointages() async {
Database db = await this.db; final db = await database;
List<Map<String, dynamic>> pointages = await db.query('pointages'); final pointages = await db.query('pointages');
return pointages.map((pointage) => Pointage.fromJson(pointage)).toList(); return pointages.map((pointage) => Pointage.fromMap(pointage)).toList();
} }
Future<int> updatePointage(Pointage pointage) async { Future<int> updatePointage(Pointage pointage) async {
Database db = await this.db; final db = await database;
return await db.update('pointages', pointage.toJson(), return await db.update('pointages', pointage.toMap(),
where: 'id = ?', whereArgs: [pointage.id]); where: 'id = ?', whereArgs: [pointage.id]);
} }
Future<int> deletePointage(int id) async { Future<int> deletePointage(int id) async {
Database db = await this.db; final db = await database;
return await db.delete('pointages', where: 'id = ?', whereArgs: [id]); return await db.delete('pointages', where: 'id = ?', whereArgs: [id]);
} }
} }

75
lib/Views/pointage.dart

@ -49,6 +49,8 @@ class _PointagePageState extends State<PointagePage> {
child: Text('Ajouter'), child: Text('Ajouter'),
onPressed: () async { onPressed: () async {
final pointage = Pointage( final pointage = Pointage(
userName:
"Nom de l'utilisateur", // fixed value, customize if needed
date: DateTime.now().toString().split(' ')[0], date: DateTime.now().toString().split(' ')[0],
heureArrivee: _arrivalController.text, heureArrivee: _arrivalController.text,
heureDepart: '', 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -86,19 +97,36 @@ class _PointagePageState extends State<PointagePage> {
), ),
elevation: 4, elevation: 4,
shadowColor: Colors.blueGrey.shade50, shadowColor: Colors.blueGrey.shade50,
child: ListTile( child: Padding(
leading: CircleAvatar( padding: const EdgeInsets.symmetric(
horizontal: 8.0, vertical: 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
CircleAvatar(
backgroundColor: Colors.blue.shade100, backgroundColor: Colors.blue.shade100,
child: Icon(Icons.calendar_today, color: Colors.blue), 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),
),
), ),
title: Text( ],
),
Divider(),
Text(
pointage.date, pointage.date,
style: TextStyle(fontWeight: FontWeight.bold), style: const TextStyle(
color: Colors.black87, fontSize: 15),
), ),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Row( Row(
children: [ children: [
Icon(Icons.login, Icon(Icons.login,
@ -119,18 +147,43 @@ class _PointagePageState extends State<PointagePage> {
style: TextStyle(color: Colors.red.shade700)), style: TextStyle(color: Colors.red.shade700)),
], ],
), ),
const SizedBox(height: 6),
], ],
), ),
isThreeLine: true,
), ),
), ),
); );
}, },
), ),
floatingActionButton: FloatingActionButton( 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, onPressed: _showAddDialog,
tooltip: 'Ajouter Pointage', tooltip: 'Ajouter Pointage',
child: const Icon(Icons.add), child: const Icon(Icons.add),
heroTag: 'btnAdd',
),
],
), ),
); );
} }

Loading…
Cancel
Save