From 3ad8d0264e9c5451083b6d35445bc1a31cce2668 Mon Sep 17 00:00:00 2001 From: jspmic Date: Wed, 27 Nov 2024 18:01:54 +0200 Subject: [PATCH 1/5] fix: restored to initial setup --- lib/main.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 9bd4b85..ee92bd0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -192,8 +192,7 @@ class _LoginPageState extends State { isLoading ? CircularProgressIndicator() : ElevatedButton(onPressed: authenticate, style: ElevatedButton.styleFrom(backgroundColor: Colors.lightGreen), - child: Text("Se connecter", style: TextStyle(color: Colors.black),),) - + child: Text("Se connecter", style: TextStyle(color: Colors.black),),), ]))), ), ); From b496e0bbd39db67abaa9dcf6ff7a92ed22cce292 Mon Sep 17 00:00:00 2001 From: jspmic Date: Wed, 27 Nov 2024 21:32:58 +0200 Subject: [PATCH 2/5] fix: catch all exceptions not specific one --- lib/rest.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rest.dart b/lib/rest.dart index 137ae72..20a2515 100644 --- a/lib/rest.dart +++ b/lib/rest.dart @@ -124,7 +124,7 @@ Future getTransfert(String date, String user) async { } return decoded; } - on http.ClientException{ + on Exception{ return []; } } @@ -142,7 +142,7 @@ Future getLivraison(String date, String user) async { } return decoded; } - on http.ClientException{ + on Exception{ return []; } } @@ -185,7 +185,7 @@ Future isUser(String _n_9032, String _n_9064) async { } return false; } - on http.ClientException{ + on Exception{ return false; } } From 3219690fc875395eeb4c19cd75ac1e4b95501b1d Mon Sep 17 00:00:00 2001 From: jspmic Date: Fri, 29 Nov 2024 02:20:25 +0200 Subject: [PATCH 3/5] feat: added retrieval method and population of caches using the api --- lib/custom_widgets.dart | 7 +++---- lib/main.dart | 7 ++++--- lib/rest.dart | 9 +++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/custom_widgets.dart b/lib/custom_widgets.dart index d54b5c2..fd6dc6d 100644 --- a/lib/custom_widgets.dart +++ b/lib/custom_widgets.dart @@ -6,8 +6,8 @@ import 'package:path_provider/path_provider.dart'; import 'package:soft/transfert.dart' as transfert; import 'package:soft/livraison.dart' as livraison; -Map> cache = {}; -Map> cache2 = {}; +Map cache = {}; +Map cache2 = {}; DateTime? dateSelected; bool collineDisponible = false; @@ -140,8 +140,7 @@ class _StockState extends State { @override Widget build(BuildContext context) { return SingleChildScrollView(scrollDirection: Axis.horizontal, - child: DropdownButton(items: (widget.district != null ? cache2[widget.district] : cache[widget.column]) - ?.map((choice){ + child: DropdownButton(items: (widget.district != null ? cache2[widget.district] : cache[widget.column])?.map((choice){ return DropdownMenuItem(value: choice, child: Text(choice.toString())); }).toList(), onChanged: (value){ setState(() { diff --git a/lib/main.dart b/lib/main.dart index ee92bd0..2d856c1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,7 +25,8 @@ class _LoginState extends State { @override void initState() { init(); - initialize(); + // Remove initialize(to be replaced with cache population in rest.dart + //initialize(); super.initState(); } @@ -106,8 +107,8 @@ class _LoginPageState extends State { state = Colors.green; objTransfert.user = _uname; objLivraison.user = _uname; - username.text = ""; - pssw.text = ""; + //username.text = ""; + //pssw.text = ""; Navigator.pushNamed(context, '/second', arguments: screen2.ScreenTransition(backgroundColor: background, FieldColor: fieldColor, changeThemes: changeTheme, objtransfert: objTransfert, objlivraison: objLivraison diff --git a/lib/rest.dart b/lib/rest.dart index 20a2515..c0e1f1f 100644 --- a/lib/rest.dart +++ b/lib/rest.dart @@ -1,6 +1,8 @@ import 'package:http/http.dart' as http; import 'dart:convert'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:soft/custom_widgets.dart'; +import 'package:soft/excel_fields.dart'; // Address definition String? HOST; @@ -181,6 +183,13 @@ Future isUser(String _n_9032, String _n_9064) async { return http.Response("No connection", 404); }); if (response.statusCode == 200) { + // Add column retrieval code here + // The replacement for the initialize method lies here + Map fields = jsonDecode(response.body); + cache[DISTRICT] = fields["districts"]!; + cache[TYPE_TRANSPORT] = fields["type_transports"]!; + cache[STOCK_CENTRAL] = fields["stocks"]!; + cache[INPUT] = fields["inputs"]!; return true; } return false; From 4e2354ed00cad0e4078ec5f9c082b96bd021c3c8 Mon Sep 17 00:00:00 2001 From: jspmic Date: Fri, 29 Nov 2024 03:07:59 +0200 Subject: [PATCH 4/5] fix: removed the need to initialize LIVRAISON_RETOUR --- lib/custom_widgets.dart | 36 ------------------------------------ lib/rest.dart | 1 + 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/lib/custom_widgets.dart b/lib/custom_widgets.dart index fd6dc6d..46bca9d 100644 --- a/lib/custom_widgets.dart +++ b/lib/custom_widgets.dart @@ -12,37 +12,6 @@ Map cache2 = {}; DateTime? dateSelected; bool collineDisponible = false; -Future _getDst() async { - final directory = await getApplicationDocumentsDirectory(); - - // Create the parent directory if it doesn't exist - if (!await directory.exists()) { - await directory.create(recursive: true); - } - - return directory.path; -} - -Future _localFile(String fileName) async { - final path = await _getDst(); - return File('$path/$fileName'); -} - -Future readCounter(String fileName) async { - final file = await _localFile(fileName); - - // Read the file - return file.readAsString(); -} - -Future writeCounter(String fileName, String content) async { - final file = await _localFile(fileName); - - // Write the file - return file.writeAsString(content, mode: FileMode.append); -} - - // Function to capitalize a string String capitalize(String string){ return string[0].toUpperCase() + string.substring(1, string.length); @@ -67,11 +36,6 @@ void initialize({String? district}){ list(DISTRICT+5, district: district); return; } - list(STOCK_CENTRAL); - list(TYPE_TRANSPORT); - list(INPUT); - list(DISTRICT); - list(LIVRAISON_RETOUR); } // Custom DatePicker widget diff --git a/lib/rest.dart b/lib/rest.dart index c0e1f1f..03b60fb 100644 --- a/lib/rest.dart +++ b/lib/rest.dart @@ -8,6 +8,7 @@ import 'package:soft/excel_fields.dart'; String? HOST; init() async{ + cache[LIVRAISON_RETOUR] = ["Livraison", "Retour"]; await dotenv.load(fileName: ".env"); HOST = dotenv.env["HOST"].toString(); } From 1d74f1d8e56257cc723a240b82970750b1f00423 Mon Sep 17 00:00:00 2001 From: jspmic Date: Sat, 30 Nov 2024 00:18:41 +0200 Subject: [PATCH 5/5] fix: sorted caches and cleared login text fields --- lib/main.dart | 4 ++-- lib/rest.dart | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 2d856c1..f306de2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -107,8 +107,8 @@ class _LoginPageState extends State { state = Colors.green; objTransfert.user = _uname; objLivraison.user = _uname; - //username.text = ""; - //pssw.text = ""; + username.text = ""; + pssw.text = ""; Navigator.pushNamed(context, '/second', arguments: screen2.ScreenTransition(backgroundColor: background, FieldColor: fieldColor, changeThemes: changeTheme, objtransfert: objTransfert, objlivraison: objLivraison diff --git a/lib/rest.dart b/lib/rest.dart index 03b60fb..7e0df0a 100644 --- a/lib/rest.dart +++ b/lib/rest.dart @@ -191,6 +191,8 @@ Future isUser(String _n_9032, String _n_9064) async { cache[TYPE_TRANSPORT] = fields["type_transports"]!; cache[STOCK_CENTRAL] = fields["stocks"]!; cache[INPUT] = fields["inputs"]!; + cache[INPUT]?.sort(); + cache[DISTRICT]?.sort(); return true; } return false;