Skip to content

Commit

Permalink
Merge pull request #10 from jspmic/development
Browse files Browse the repository at this point in the history
feat: Added feature to upload both images simultaneously
  • Loading branch information
jspmic authored Nov 25, 2024
2 parents c46883d + b6a95a8 commit 457309f
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 23 deletions.
33 changes: 33 additions & 0 deletions lib/custom_widgets.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:io';
import 'package:soft/excel_fields.dart';
import 'package:flutter/material.dart';
import 'package:soft/screen2.dart';
import 'package:path_provider/path_provider.dart';
import 'package:soft/transfert.dart' as transfert;
import 'package:soft/livraison.dart' as livraison;

Expand All @@ -10,6 +12,37 @@ Map<String?, Iterable<String?>> 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 Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Login extends StatefulWidget {
class _LoginState extends State<Login> {
@override
void initState() {
init();
initialize();
super.initState();
}
Expand Down
44 changes: 21 additions & 23 deletions lib/rest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import 'dart:convert';
import 'package:flutter_dotenv/flutter_dotenv.dart';

// Address definition
const String HOST = "https://jspemic.pythonanywhere.com";
String? HOST;

init() async{
await dotenv.load(fileName: ".env");
HOST = dotenv.env["HOST"].toString();
}
// const String HOST = "http://192.168.43.81:5000";


Expand All @@ -24,10 +29,8 @@ class Transfert{

Future<http.Response> postMe() async{
Uri url = Uri.parse("$HOST/api/transferts");
Map imageMvt = await getUrl(photo_mvt);
Map imageJournal = await getUrl(photo_journal);
if (!imageMvt.containsKey("message") && !imageJournal.containsKey("message")){
print("Succeeded");
Map images = await getUrl(photo_mvt, photo_journal);
if (!images.containsKey("message")){
http.Response response = await http.post(
url,
headers: <String, String>{
Expand All @@ -41,8 +44,8 @@ class Transfert{
'stock_central_depart': stock_central_depart,
'stock_central_suivants': jsonEncode(stock_central_suivants),
'stock_central_retour': stock_central_retour,
'photo_mvt': imageMvt != {} ? imageMvt["url"] : "",
'photo_journal': imageJournal != {} ? imageJournal["url"] : "",
'photo_mvt': images["image1"],
'photo_journal': images["image2"],
'type_transport': type_transport,
'user': user,
'motif': motif
Expand All @@ -51,7 +54,6 @@ class Transfert{
return response;
}
else{
print("Failed");
return http.Response("{\"message\": \"Pas de connexion\"}", 404);
}
}
Expand All @@ -74,11 +76,9 @@ class Livraison{
Livraison();

Future<http.Response> postMe() async{
Map imageMvt = await getUrl(photo_mvt);
Map imageJournal = await getUrl(photo_journal);
Map images = await getUrl(photo_mvt, photo_journal);
Uri url = Uri.parse("$HOST/api/livraisons");
if (!imageMvt.containsKey("message") && !imageJournal.containsKey("message")){
print("Succeeded");
if (!images.containsKey("message")){
http.Response response = await http.post(
url,
headers: <String, String>{
Expand All @@ -93,8 +93,8 @@ class Livraison{
'stock_central_depart': stock_central_depart,
'boucle': jsonEncode(boucle),
'stock_central_retour': stock_central_retour,
'photo_mvt': imageMvt != {} ? imageMvt["url"] : "",
'photo_journal': imageJournal != {} ? imageJournal["url"] : "",
'photo_mvt': images["image1"],
'photo_journal': images["image2"],
'type_transport': type_transport,
'user': user,
'motif': motif
Expand All @@ -103,7 +103,6 @@ class Livraison{
return response;
}
else{
print("Failed");
return http.Response("{\"message\": \"Pas de connexion\"}", 404);
}
}
Expand Down Expand Up @@ -148,7 +147,7 @@ Future<List> getLivraison(String date, String user) async {
}
}

Future<dynamic> getUrl(String image) async {
Future<dynamic> getUrl(String image1, String image2) async {
Uri url = Uri.parse("$HOST/api/image");
try{
http.Response response = await http.post(
Expand All @@ -157,17 +156,16 @@ Uri url = Uri.parse("$HOST/api/image");
'Content-Type': 'application/json; charset=UTF-8'
},
body: jsonEncode(<String, dynamic>{
'image': image,
'filename': 'mouvement.jpeg'
'image1': image1,
'filename1': 'mouvement1.jpeg',
'image2': image2,
'filename2': 'mouvement2.jpeg'
})
);
return jsonDecode(response.body);
}
on http.ClientException{
return jsonDecode(http.Response("{\"message\": \"Pas de connexion internet\"}", 404).body);
}
on FormatException{
return jsonDecode(http.Response("{\"message\": \"Pas de connexion internet\"}", 404).body);
on Exception{
return jsonDecode(http.Response("{\"message\": \"Erreur du client\"}", 404).body);
}
}

Expand Down
72 changes: 72 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6"
url: "https://pub.dev"
source: hosted
version: "2.1.3"
file_selector_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -432,6 +440,54 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
path_provider:
dependency: "direct main"
description:
name: path_provider
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: "8c4967f8b7cb46dc914e178daa29813d83ae502e0529d7b0478330616a691ef7"
url: "https://pub.dev"
source: hosted
version: "2.2.14"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16
url: "https://pub.dev"
source: hosted
version: "2.4.0"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
url: "https://pub.dev"
source: hosted
version: "2.2.1"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
url: "https://pub.dev"
source: hosted
version: "2.3.0"
petitparser:
dependency: transitive
description:
Expand All @@ -440,6 +496,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.2"
platform:
dependency: transitive
description:
name: platform
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
url: "https://pub.dev"
source: hosted
version: "3.1.6"
plugin_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -533,6 +597,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
xml:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
cupertino_icons: ^1.0.8
crypto: ^3.0.6
flutter_dotenv: ^5.2.1
path_provider: ^2.1.5

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 457309f

Please sign in to comment.