diff --git a/lib/custom_widgets.dart b/lib/custom_widgets.dart index d54b5c2..46bca9d 100644 --- a/lib/custom_widgets.dart +++ b/lib/custom_widgets.dart @@ -6,43 +6,12 @@ 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; -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 @@ -140,8 +104,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 9bd4b85..f306de2 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(); } @@ -192,8 +193,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),),), ]))), ), ); diff --git a/lib/rest.dart b/lib/rest.dart index 137ae72..7e0df0a 100644 --- a/lib/rest.dart +++ b/lib/rest.dart @@ -1,11 +1,14 @@ 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; init() async{ + cache[LIVRAISON_RETOUR] = ["Livraison", "Retour"]; await dotenv.load(fileName: ".env"); HOST = dotenv.env["HOST"].toString(); } @@ -124,7 +127,7 @@ Future getTransfert(String date, String user) async { } return decoded; } - on http.ClientException{ + on Exception{ return []; } } @@ -142,7 +145,7 @@ Future getLivraison(String date, String user) async { } return decoded; } - on http.ClientException{ + on Exception{ return []; } } @@ -181,11 +184,20 @@ 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"]!; + cache[INPUT]?.sort(); + cache[DISTRICT]?.sort(); return true; } return false; } - on http.ClientException{ + on Exception{ return false; } }