Skip to content

Commit

Permalink
Merge pull request #12 from jspmic/development
Browse files Browse the repository at this point in the history
Major changes: Implementation change
  • Loading branch information
jspmic authored Nov 29, 2024
2 parents 457309f + 1d74f1d commit c573804
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 46 deletions.
43 changes: 3 additions & 40 deletions lib/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, Iterable<String?>> cache = {};
Map<String?, Iterable<String?>> cache2 = {};
Map<int, List> cache = {};
Map<String?, List> cache2 = {};

DateTime? dateSelected;
bool collineDisponible = false;

Future<String> _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<File> _localFile(String fileName) async {
final path = await _getDst();
return File('$path/$fileName');
}

Future<String> readCounter(String fileName) async {
final file = await _localFile(fileName);

// Read the file
return file.readAsString();
}

Future<File> 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);
Expand All @@ -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
Expand Down Expand Up @@ -140,8 +104,7 @@ class _StockState extends State<Stock> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(scrollDirection: Axis.horizontal,
child: DropdownButton<String?>(items: (widget.district != null ? cache2[widget.district] : cache[widget.column])
?.map((choice){
child: DropdownButton<dynamic>(items: (widget.district != null ? cache2[widget.district] : cache[widget.column])?.map((choice){
return DropdownMenuItem(value: choice, child: Text(choice.toString()));
}).toList(), onChanged: (value){
setState(() {
Expand Down
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class _LoginState extends State<Login> {
@override
void initState() {
init();
initialize();
// Remove initialize(to be replaced with cache population in rest.dart
//initialize();
super.initState();
}

Expand Down Expand Up @@ -192,8 +193,7 @@ class _LoginPageState extends State<LoginPage> {
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),),),
]))),
),
);
Expand Down
18 changes: 15 additions & 3 deletions lib/rest.dart
Original file line number Diff line number Diff line change
@@ -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();
}
Expand Down Expand Up @@ -124,7 +127,7 @@ Future<List> getTransfert(String date, String user) async {
}
return decoded;
}
on http.ClientException{
on Exception{
return [];
}
}
Expand All @@ -142,7 +145,7 @@ Future<List> getLivraison(String date, String user) async {
}
return decoded;
}
on http.ClientException{
on Exception{
return [];
}
}
Expand Down Expand Up @@ -181,11 +184,20 @@ Future<bool> 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<String, dynamic> 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;
}
}

0 comments on commit c573804

Please sign in to comment.