add pagination for pages
This commit is contained in:
@@ -1,181 +0,0 @@
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'total_weight_edit.dart';
|
||||
|
||||
typedef OnAdd(CargoType cargoType);
|
||||
typedef OnRemove(CargoType cargoType);
|
||||
|
||||
class CargoTable extends StatefulWidget {
|
||||
final List<CargoType>? cargoTypes;
|
||||
final OnAdd? onAdd;
|
||||
final OnRemove? onRemove;
|
||||
|
||||
const CargoTable({Key? key, this.cargoTypes, this.onAdd, this.onRemove})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_CargoTableState createState() => _CargoTableState();
|
||||
}
|
||||
|
||||
class _CargoTableState extends State<CargoTable> {
|
||||
double totalWeight = 0;
|
||||
List<CargoType> _cargos = [];
|
||||
double remainingWeight = 0;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DataTable(
|
||||
headingRowHeight: 40,
|
||||
showCheckboxColumn: false,
|
||||
columns: [
|
||||
DataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"cargo.type",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 50),
|
||||
child: LocalText(
|
||||
context,
|
||||
"cargo.weight",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
rows: getCargoRows(context),
|
||||
);
|
||||
}
|
||||
|
||||
List<DataRow> getCargoRows(BuildContext context) {
|
||||
if (widget.cargoTypes == null) {
|
||||
return [];
|
||||
}
|
||||
List<String> _list = [];
|
||||
List<String> _types = [];
|
||||
double _total = 0;
|
||||
|
||||
var rows = widget.cargoTypes!.map((c) {
|
||||
_total += c.weight;
|
||||
return DataRow(
|
||||
onSelectChanged: (bool? selected) async {},
|
||||
cells: [
|
||||
DataCell(Row(
|
||||
children: [
|
||||
new Text(
|
||||
c.name ?? "",
|
||||
style: textStyle,
|
||||
),
|
||||
new Text(
|
||||
c.qty == 0 ? "" : " x ${c.qty.toString()}",
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
)),
|
||||
DataCell(
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(c.weight.toStringAsFixed(2), style: textStyle),
|
||||
widget.onRemove == null
|
||||
? SizedBox(
|
||||
width: 50,
|
||||
)
|
||||
: IconButton(
|
||||
icon: Icon(
|
||||
Icons.remove_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
if (widget.onRemove != null) widget.onRemove!(c);
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
var totalRow = DataRow(
|
||||
onSelectChanged: (bool? selected) {},
|
||||
cells: [
|
||||
DataCell(Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
"shipment.cargo.total",
|
||||
color: Colors.black87,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
)),
|
||||
DataCell(
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 40.0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
double? _t = await Navigator.of(context).push<double>(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
TotalWeightEdit(totalWeight: totalWeight)));
|
||||
if (_t == null) return;
|
||||
setState(() {
|
||||
totalWeight = _t;
|
||||
this.remainingWeight = this.totalWeight - _total;
|
||||
widget.cargoTypes!.forEach((c) {
|
||||
this._cargos.add(c);
|
||||
});
|
||||
this._cargos.forEach((c) {
|
||||
_list.add(c.name!);
|
||||
});
|
||||
widget.cargoTypes!.forEach((c) {
|
||||
_types.add(c.name!);
|
||||
});
|
||||
if (this._cargos.length ==
|
||||
widget.cargoTypes!.length - 1) {
|
||||
_types.forEach((t) {
|
||||
if (!_list.contains(t)) {
|
||||
widget.cargoTypes!.forEach((c) {
|
||||
if (c.name == t) {
|
||||
c.weight = this.remainingWeight;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(7.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
||||
),
|
||||
child: Text(totalWeight.toStringAsFixed(2),
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
rows.add(totalRow);
|
||||
return rows;
|
||||
}
|
||||
|
||||
double getRemainBalance(double total) {
|
||||
double _r = this.totalWeight < total ? 0 : this.totalWeight - total;
|
||||
return _r;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../domain/entities/carton.dart';
|
||||
import '../../pagination/paginator_listview.dart';
|
||||
import 'carton_editor.dart';
|
||||
import 'carton_list_row.dart';
|
||||
|
||||
@@ -18,42 +20,44 @@ class CartonList extends StatefulWidget {
|
||||
|
||||
class _CartonListState extends State<CartonList> {
|
||||
bool _isLoading = false;
|
||||
var _controller = ScrollController();
|
||||
int _selectedIndex = 1;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.addListener(() async {
|
||||
if (_controller.position.pixels == _controller.position.maxScrollExtent) {
|
||||
Provider.of<CartonModel>(context, listen: false).loadMore();
|
||||
}
|
||||
});
|
||||
Provider.of<CartonModel>(context, listen: false).initData();
|
||||
_init();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_init() {
|
||||
var model = context.read<CartonModel>();
|
||||
_selectedIndex = model.selectedIndex;
|
||||
model.loadPaginationBoxes(_selectedIndex);
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "box.popupmenu.active",
|
||||
selected: boxModel.selectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "box.popupmenu.delivered",
|
||||
selected: boxModel.selectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) => this.setState(() {
|
||||
boxModel.selectedIndex = p.id;
|
||||
}),
|
||||
);
|
||||
popmenus: [
|
||||
LocalPopupMenu(
|
||||
id: 1,
|
||||
textKey: "box.popupmenu.active",
|
||||
selected: boxModel.selectedIndex == 1),
|
||||
LocalPopupMenu(
|
||||
id: 2,
|
||||
textKey: "box.popupmenu.delivered",
|
||||
selected: boxModel.selectedIndex == 2)
|
||||
],
|
||||
popupMenuCallback: (p) {
|
||||
setState(() {
|
||||
_selectedIndex = p.id;
|
||||
});
|
||||
context.read<CartonModel>().onChanged(_selectedIndex);
|
||||
});
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: DefaultTabController(
|
||||
@@ -78,43 +82,10 @@ class _CartonListState extends State<CartonList> {
|
||||
label: LocalText(context, "boxes.new", color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
child: new ListView.separated(
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
controller: _controller,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.black,
|
||||
height: 1,
|
||||
),
|
||||
scrollDirection: Axis.vertical,
|
||||
shrinkWrap: true,
|
||||
itemCount: boxModel.boxes.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return CartonListRow(
|
||||
key: ValueKey(boxModel.boxes[index].id),
|
||||
box: boxModel.boxes[index]);
|
||||
}),
|
||||
onRefresh: () => boxModel.refresh(),
|
||||
),
|
||||
),
|
||||
boxModel.isLoading
|
||||
? Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
color: primaryColor,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Loading...",
|
||||
style: TextStyle(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
body: PaginatorListView<Carton>(
|
||||
paginatorListener: boxModel.getBoxes!,
|
||||
rowBuilder: (p) => CartonListRow(box: p),
|
||||
color: primaryColor),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_title.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
typedef OnSelect = Function(Carton carton, bool checked);
|
||||
|
||||
class CartonMixTable extends StatelessWidget {
|
||||
final List<Carton>? cartons;
|
||||
final OnSelect? onSelect;
|
||||
|
||||
const CartonMixTable({Key? key, this.cartons, this.onSelect})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tableTitle = Container(
|
||||
padding: EdgeInsets.only(right: 10.0, top: 20),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 30,
|
||||
),
|
||||
Expanded(
|
||||
child: LocalText(context, 'box.mix.number', color: Colors.grey),
|
||||
),
|
||||
LocalText(context, 'box.cargo.total', color: Colors.grey),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final rows = cartons == null
|
||||
? [Container()]
|
||||
: cartons!.asMap().entries.map((p) {
|
||||
return Container(
|
||||
color: (p.value.isChecked ?? false)
|
||||
? Colors.grey.withOpacity(0.2)
|
||||
: Colors.grey.shade50.withOpacity(0.2),
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: 0.0, right: 10.0, top: 3.0, bottom: 3.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: p.key == cartons!.length - 1
|
||||
? Colors.white
|
||||
: Colors.grey.shade300,
|
||||
width: 1),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: p.value.isChecked,
|
||||
activeColor: primaryColor,
|
||||
onChanged: (bool? check) {
|
||||
if (onSelect != null) onSelect!(p.value, check!);
|
||||
}),
|
||||
Expanded(
|
||||
child: new Text(
|
||||
p.value.cartonNumber ?? "",
|
||||
style: textStyle,
|
||||
)),
|
||||
new Text(
|
||||
p.value.actualWeight.toString(),
|
||||
style: textStyle,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
LocalTitle(textKey: "box.shipment.boxes"),
|
||||
tableTitle,
|
||||
Divider(
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
Column(
|
||||
children: rows,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
typedef OnAdd(String value);
|
||||
|
||||
class InputTextBorder extends StatelessWidget {
|
||||
final OnAdd? onAdd;
|
||||
final TextEditingController? controller;
|
||||
|
||||
const InputTextBorder({Key? key, this.onAdd, this.controller})
|
||||
: super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
textAlign: TextAlign.center,
|
||||
controller: controller,
|
||||
onChanged: (v) {
|
||||
if (onAdd != null) onAdd!(v);
|
||||
},
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration(
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,62 +4,20 @@ import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/carton.dart';
|
||||
import 'package:fcs/domain/vo/shipment_status.dart';
|
||||
import 'package:fcs/helpers/paginator.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:fcs/pagination/paginator_listener.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class CartonModel extends BaseModel {
|
||||
List<Carton> _boxes = [];
|
||||
PaginatorListener<Carton>? cartonsByFilter;
|
||||
|
||||
final log = Logger('CartonModel');
|
||||
List<Carton> get boxes => _selectedIndex == 1
|
||||
? _boxes
|
||||
: List<Carton>.from(_delivered?.values ?? []);
|
||||
|
||||
Paginator? _delivered;
|
||||
int _selectedIndex = 1;
|
||||
PaginatorListener<Carton>? cartonsByFilter;
|
||||
PaginatorListener<Carton>? getBoxes;
|
||||
|
||||
int selectedIndex = 1;
|
||||
int _selectedIndexFilter = 1;
|
||||
bool isLoading = false;
|
||||
|
||||
StreamSubscription<QuerySnapshot>? listener;
|
||||
StreamSubscription<QuerySnapshot>? cartonListener;
|
||||
static List<ShipmentStatus> statusHistory = [
|
||||
ShipmentStatus(status: "Packed", date: DateTime(2020, 6, 1), done: true),
|
||||
ShipmentStatus(status: "Shipped", date: DateTime(2020, 6, 5), done: false),
|
||||
ShipmentStatus(
|
||||
status: "Delivered", date: DateTime(2020, 6, 15), done: false)
|
||||
];
|
||||
|
||||
// List<Carton> get completed {
|
||||
// return boxes.where((e) => e.status == "Delivered").toList()
|
||||
// ..sort((e1, e2) {
|
||||
// return e2.packageNumber.compareTo(e1.packageNumber);
|
||||
// });
|
||||
// }
|
||||
|
||||
// List<Carton> get processed {
|
||||
// return boxes.where((e) => e.status == "Packed").toList()
|
||||
// ..sort((e1, e2) {
|
||||
// return e2.packageNumber.compareTo(e1.packageNumber);
|
||||
// });
|
||||
// }
|
||||
|
||||
// List<Carton> get upcoming {
|
||||
// return boxes
|
||||
// .where((e) =>
|
||||
// e.status == "Packed" ||
|
||||
// // e.status == "Received" ||
|
||||
// e.status == "Shipped" ||
|
||||
// e.status == "Arrived")
|
||||
// .toList()
|
||||
// ..sort((e1, e2) {
|
||||
// return e2.packageNumber.compareTo(e1.packageNumber);
|
||||
// });
|
||||
// }
|
||||
|
||||
List<String> cartonTypes = [
|
||||
carton_from_packages,
|
||||
carton_from_cartons,
|
||||
@@ -74,10 +32,7 @@ class CartonModel extends BaseModel {
|
||||
carton_small_bag
|
||||
];
|
||||
|
||||
set selectedIndex(int index) {
|
||||
_selectedIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
int get selectedIndexFilter => _selectedIndexFilter;
|
||||
|
||||
set selectedIndexFilter(int index) {
|
||||
_selectedIndexFilter = index;
|
||||
@@ -86,19 +41,6 @@ class CartonModel extends BaseModel {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
int get selectedIndex => _selectedIndex;
|
||||
int get selectedIndexFilter => _selectedIndexFilter;
|
||||
|
||||
initData() async {
|
||||
_selectedIndex = 1;
|
||||
_selectedIndexFilter = 1;
|
||||
_loadBoxes();
|
||||
|
||||
if (_delivered != null) _delivered!.close();
|
||||
_delivered = _getDelivered();
|
||||
_delivered!.load();
|
||||
}
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
if (user != null || !user!.hasCarton()) {
|
||||
@@ -106,40 +48,54 @@ class CartonModel extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
getBoxes?.close();
|
||||
cartonsByFilter?.close();
|
||||
}
|
||||
|
||||
Future<void> _initData() async {
|
||||
logout();
|
||||
_selectedIndexFilter = 1;
|
||||
|
||||
_loadPaginationCartons(
|
||||
_selectedIndexFilter == 1 ? "carton_weight" : "user_name");
|
||||
}
|
||||
|
||||
Future<void> _loadBoxes() async {
|
||||
onChanged(int index) {
|
||||
selectedIndex = index;
|
||||
loadPaginationBoxes(selectedIndex);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadPaginationBoxes(int index) async {
|
||||
if (user == null || !user!.hasCarton()) return;
|
||||
String path = "/$cartons_collection/";
|
||||
if (listener != null) listener!.cancel();
|
||||
_boxes = [];
|
||||
try {
|
||||
listener = FirebaseFirestore.instance
|
||||
.collection("$path")
|
||||
.where("status",
|
||||
whereIn: [carton_packed_status, carton_shipped_status])
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.orderBy("created_at", descending: true)
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
_boxes.clear();
|
||||
_boxes = snapshot.docs.map((documentSnapshot) {
|
||||
var s = Carton.fromMap(
|
||||
documentSnapshot.data() as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return s;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
|
||||
String path = "/$cartons_collection";
|
||||
Query col = FirebaseFirestore.instance.collection(path);
|
||||
Query pageQuery = FirebaseFirestore.instance.collection(path);
|
||||
|
||||
if (index == 1) {
|
||||
col = col.where("status",
|
||||
whereIn: [carton_packed_status, carton_shipped_status]);
|
||||
pageQuery = pageQuery.where("status",
|
||||
whereIn: [carton_packed_status, carton_shipped_status]);
|
||||
}
|
||||
|
||||
if (index == 2) {
|
||||
col = col.where("is_delivered", isEqualTo: true);
|
||||
pageQuery = pageQuery.where("is_delivered", isEqualTo: true);
|
||||
}
|
||||
|
||||
pageQuery = pageQuery.orderBy("created_at", descending: true);
|
||||
|
||||
getBoxes?.close();
|
||||
getBoxes = PaginatorListener<Carton>(
|
||||
col, pageQuery, (data, id) => Carton.fromMap(data, id),
|
||||
rowPerLoad: 30);
|
||||
}
|
||||
|
||||
_loadPaginationCartons(String orderName) {
|
||||
@@ -164,49 +120,6 @@ class CartonModel extends BaseModel {
|
||||
rowPerLoad: 30);
|
||||
}
|
||||
|
||||
Paginator? _getDelivered() {
|
||||
if (user == null || !user!.hasCarton()) return null;
|
||||
|
||||
var pageQuery = FirebaseFirestore.instance
|
||||
.collection("/$cartons_collection")
|
||||
.where("is_delivered", isEqualTo: true)
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
var paginator = new Paginator(pageQuery, rowPerLoad: 20, toObj: (data, id) {
|
||||
return Carton.fromMap(data, id);
|
||||
});
|
||||
return paginator;
|
||||
}
|
||||
|
||||
Future<void> loadMore() async {
|
||||
if (_delivered == null && _delivered!.ended || selectedIndex == 1) return;
|
||||
isLoading = true;
|
||||
notifyListeners();
|
||||
await _delivered!.load(onFinished: () {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
if (selectedIndex == 1) return;
|
||||
await _delivered?.refresh(onFinished: () {
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
void initUser(user) {
|
||||
super.initUser(user);
|
||||
}
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener!.cancel();
|
||||
if (cartonListener != null) await cartonListener!.cancel();
|
||||
if (_delivered != null) _delivered!.close();
|
||||
if (cartonsByFilter != null) cartonsByFilter!.close();
|
||||
_boxes = [];
|
||||
}
|
||||
|
||||
Future<List<Carton>> getCartons(String shipmentID) async {
|
||||
String path = "/$cartons_collection";
|
||||
var querySnap = await FirebaseFirestore.instance
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
|
||||
typedef void ProfileCallback();
|
||||
|
||||
class TotalWeightEdit extends StatefulWidget {
|
||||
final double? totalWeight;
|
||||
|
||||
const TotalWeightEdit({Key? key, this.totalWeight}) : super(key: key);
|
||||
@override
|
||||
_TotalWeightEditState createState() => _TotalWeightEditState();
|
||||
}
|
||||
|
||||
class _TotalWeightEditState extends State<TotalWeightEdit> {
|
||||
final TextEditingController totalController = new TextEditingController();
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
totalController.text = widget.totalWeight!.toStringAsFixed(2);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final totalInputBox = InputText(
|
||||
labelTextKey: 'shipment.cargo.total',
|
||||
iconData: FontAwesomeIcons.weightHanging,
|
||||
textInputType: TextInputType.number,
|
||||
controller: totalController);
|
||||
|
||||
final saveBtn =
|
||||
fcsButton(context, getLocalString(context, "btn.save"), callack: _save);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _loading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: LocalText(
|
||||
context,
|
||||
"box.cargo_total_title",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
shadowColor: Colors.transparent,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
CupertinoIcons.back,
|
||||
size: 35,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
padding: EdgeInsets.all(18),
|
||||
children: <Widget>[totalInputBox, SizedBox(height: 30), saveBtn],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
});
|
||||
try {
|
||||
double total = double.parse(totalController.text);
|
||||
Navigator.pop<double>(context, total);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user