-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add model for movements and create his own service for fetch
- Loading branch information
1 parent
448ceab
commit d463584
Showing
5 changed files
with
359 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import 'dart:ffi'; | ||
import 'dart:math'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
import 'dart:convert'; | ||
import 'package:flutter/material.dart'; | ||
import '../../../constant.dart'; | ||
import 'package:sendatrack/model/movementGet.dart'; | ||
import 'package:sendatrack/services/movement.dart'; | ||
|
||
class LogMovementController extends GetxController { | ||
RxBool tangerStore = false.obs; | ||
RxBool casaStore = false.obs; | ||
RxList<MovementGet> stockList = <MovementGet>[].obs; | ||
RxList<MovementGet> stockListFiltered = <MovementGet>[].obs; | ||
bool _isFetching = false; | ||
|
||
RxBool isLoading = true.obs; | ||
@override | ||
void onInit() { | ||
fetchStock(); | ||
// ever(product, (_) async { | ||
// stockList.clear(); | ||
// stockListFiltered.clear(); | ||
|
||
// await fetchStock(); | ||
// }); | ||
// ever(store, (_) async { | ||
// stockList.clear(); | ||
// stockListFiltered.clear(); | ||
// await fetchStock(); | ||
// }); | ||
super.onInit(); | ||
} | ||
|
||
void changeStateShip(String value) { | ||
if (_isFetching) return; // Ignore state changes when fetching data | ||
|
||
if (value == "tanger") { | ||
tangerStore.value = !tangerStore.value; | ||
casaStore.value = false; | ||
isLoading.value = true; | ||
} else if (value == "casa") { | ||
casaStore.value = !casaStore.value; | ||
tangerStore.value = false; | ||
|
||
isLoading.value = true; | ||
} else { | ||
tangerStore.value = false; | ||
casaStore.value = false; | ||
} | ||
|
||
_isFetching = true; // Mark that we are fetching data | ||
|
||
//! Wait for 800 milliseconds before fetching data | ||
Future.delayed(Duration(milliseconds: 1), () { | ||
fetchStock().then((_) { | ||
_isFetching = false; // Mark that data fetching is done | ||
}); | ||
}); | ||
} | ||
|
||
Future<void> fetchStock() async { | ||
isLoading.value = true; | ||
|
||
String status; | ||
if (tangerStore.value == true) { | ||
status = "tanger"; | ||
} else if (casaStore.value == true) { | ||
status = "casa"; | ||
} else { | ||
status = "all"; | ||
} | ||
List<MovementGet> data = await MovementService.GetMovements(); | ||
print(data); | ||
|
||
// Clear the lists before adding new data | ||
stockList.clear(); | ||
stockListFiltered.clear(); | ||
|
||
stockList.addAll(data); | ||
stockListFiltered.addAll(data); | ||
|
||
isLoading.value = false; | ||
} | ||
|
||
// void filterSearchResults(String query) { | ||
// List<MovementGet> result = []; | ||
|
||
// if (query.isNotEmpty) { | ||
// result = stockList.where((element) { | ||
// bool matchReference = element.Reference != null && | ||
// element.Reference!.toLowerCase().contains(query.toLowerCase()); | ||
|
||
// bool matchDesignation = element.Designation != null && | ||
// element.Designation! | ||
// .toString() | ||
// .toLowerCase() | ||
// .contains(query.toLowerCase()); | ||
// bool matchStore = element.id_Store != null && | ||
// element.id_Store!.toLowerCase().contains(query.toLowerCase()); | ||
// bool matchQte = element.Qte != null && | ||
// element.Qte!.toString().toLowerCase().contains(query.toLowerCase()); | ||
// return matchReference || matchDesignation || matchStore || matchQte; | ||
// }).toList(); | ||
// } else { | ||
// result = List.from(stockList); | ||
// } | ||
|
||
// stockListFiltered.value = result; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:get/get_rx/src/rx_types/rx_types.dart'; | ||
|
||
List<MovementGet> clientFromJson(String str) => List<MovementGet>.from( | ||
json.decode(str).map((x) => MovementGet.fromJson(x))); | ||
|
||
class MovementGet { | ||
int? id; | ||
String? id_Store; | ||
String? id_delivery; | ||
String? TypeMvt; | ||
String? id_Vehicule; | ||
String? id_TypePanne; | ||
int? DateMvt; | ||
String? Reference; | ||
String? NumBon; | ||
int? Qte; | ||
int? Tva; | ||
int? Price; | ||
String? observation; | ||
int? kilometrage; | ||
int? Extra; | ||
String? idCiterne; | ||
String? Designation; | ||
String? login; | ||
MovementGet({ | ||
this.id, | ||
this.id_Store, | ||
this.id_delivery, | ||
this.TypeMvt, | ||
this.id_Vehicule, | ||
this.id_TypePanne, | ||
this.DateMvt, | ||
this.Reference, | ||
this.NumBon, | ||
this.Qte, | ||
this.Tva, | ||
this.Price, | ||
this.observation, | ||
this.kilometrage, | ||
this.Extra, | ||
this.idCiterne, | ||
this.Designation, | ||
this.login, | ||
}); | ||
|
||
factory MovementGet.fromJson(Map<String, dynamic> json) => MovementGet( | ||
id: json["id"], | ||
id_Store: json["id_Store"], | ||
id_delivery: json["id_delivery"], | ||
TypeMvt: json["TypeMvt"], | ||
id_Vehicule: json["id_Vehicule"], | ||
id_TypePanne: json["id_TypePanne"], | ||
DateMvt: json["DateMvt"], | ||
Reference: json["Reference"], | ||
NumBon: json["NumBon"], | ||
Qte: json["Qte"], | ||
Tva: json["Tva"], | ||
Price: json["Price"], | ||
observation: json["observation"], | ||
kilometrage: json["kilometrage"], | ||
Extra: json["Extra"], | ||
idCiterne: json["idCiterne"], | ||
Designation: json["Designation"], | ||
login: json["login"], | ||
); | ||
Map<String, dynamic> toJson() => { | ||
"id": id, | ||
"id_Store": id_Store, | ||
"id_delivery": id_delivery, | ||
"TypeMvt": TypeMvt, | ||
"id_Vehicule": id_Vehicule, | ||
"id_TypePanne": id_TypePanne, | ||
"DateMvt": DateMvt, | ||
"Reference": Reference, | ||
"NumBon": NumBon, | ||
"Qte": Qte, | ||
"Tva": Tva, | ||
"Price": Price, | ||
"observation": observation, | ||
"kilometrage": kilometrage, | ||
"Extra": Extra, | ||
"idCiterne": idCiterne, | ||
"Designation": Designation, | ||
"login": login, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:sendatrack/constant.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:gap/gap.dart'; | ||
import 'package:sendatrack/constant.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:sendatrack/controllers/stock/logMovementController.dart'; | ||
|
||
class HeaderMovementList extends StatefulWidget { | ||
const HeaderMovementList({super.key}); | ||
|
||
@override | ||
State<HeaderMovementList> createState() => _HeaderMovementListState(); | ||
} | ||
|
||
class _HeaderMovementListState extends State<HeaderMovementList> { | ||
LogMovementController controller = Get.put(LogMovementController()); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Obx(() => Padding( | ||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 10), | ||
child: Column( | ||
// mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
// crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
Container( | ||
height: 40, | ||
margin: EdgeInsets.only(top: 8), | ||
decoration: BoxDecoration( | ||
color: Colors.white, | ||
border: Border.all(color: Colors.grey, width: 1), | ||
borderRadius: BorderRadius.circular(10), | ||
), | ||
child: TextField( | ||
// onChanged: (value) => controller.filterSearchResults(value), | ||
autofocus: false, | ||
cursorColor: Color.fromARGB(255, 73, 73, 73), | ||
style: const TextStyle(color: Colors.grey), | ||
decoration: const InputDecoration( | ||
hintText: 'Search', | ||
hintStyle: TextStyle(color: Colors.grey), | ||
prefixIcon: Icon(Icons.search, color: TestColor, size: 20), | ||
fillColor: Colors.white, | ||
focusedBorder: UnderlineInputBorder( | ||
// borderRadius: BorderRadius.circular(10), | ||
borderSide: BorderSide( | ||
color: Color.fromARGB(255, 255, 255, 255), width: 0), | ||
), | ||
enabledBorder: UnderlineInputBorder( | ||
// borderRadius: BorderRadius.circular(10), | ||
borderSide: BorderSide( | ||
color: Color.fromARGB(255, 255, 255, 255), width: 0), | ||
), | ||
), | ||
), | ||
), | ||
const Gap(10), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
Expanded( | ||
child: GestureDetector( | ||
onTap: () { | ||
controller.changeStateShip('tanger'); | ||
}, | ||
child: Container( | ||
// color: Colors.black38, | ||
alignment: Alignment.center, | ||
height: 40, | ||
padding: EdgeInsets.fromLTRB(10, 5, 10, 5), | ||
decoration: BoxDecoration( | ||
color: controller.tangerStore.value | ||
? TestColor | ||
: Colors.white, | ||
border: Border.all( | ||
color: controller.tangerStore.value | ||
? Colors.white | ||
: TestColor, | ||
width: 1), | ||
borderRadius: BorderRadius.circular(8), | ||
), | ||
child: Text( | ||
'tanger', | ||
style: TextStyle( | ||
color: controller.tangerStore.value | ||
? Colors.white | ||
: TestColor, | ||
fontWeight: FontWeight.w900, | ||
fontSize: 15), | ||
), | ||
))), | ||
const Gap(15), | ||
Expanded( | ||
child: GestureDetector( | ||
onTap: () { | ||
controller.changeStateShip('casa'); | ||
}, | ||
child: Container( | ||
alignment: Alignment.center, | ||
height: 40, | ||
padding: EdgeInsets.fromLTRB(10, 5, 10, 5), | ||
decoration: BoxDecoration( | ||
color: controller.casaStore.value | ||
? TestColor | ||
: Colors.white, | ||
border: Border.all( | ||
color: controller.casaStore.value | ||
? Colors.white | ||
: TestColor, | ||
width: 1), | ||
borderRadius: BorderRadius.circular(8), | ||
), | ||
child: Text( | ||
'casa', | ||
style: TextStyle( | ||
color: controller.casaStore.value | ||
? Colors.white | ||
: TestColor, | ||
fontWeight: FontWeight.w900, | ||
fontSize: 15), | ||
), | ||
))), | ||
]), | ||
], | ||
))); | ||
} | ||
} |