Files
fcs/lib/pages/fcs_shipment/fcs_shipment_list.dart
2024-02-05 11:13:12 +06:30

129 lines
4.1 KiB
Dart

import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/local_popupmenu.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:fcs/pagination/paginator_listview.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
import '../../domain/entities/fcs_shipment.dart';
import 'fcs_shipment_editor.dart';
import 'fcs_shipment_list_row.dart';
class FcsShipmentList extends StatefulWidget {
@override
_FcsShipmentListState createState() => _FcsShipmentListState();
}
class _FcsShipmentListState extends State<FcsShipmentList> {
bool _isLoading = false;
int _selectedIndex = 0;
@override
void initState() {
super.initState();
_init();
}
_init() {
var model = context.read<FcsShipmentModel>();
_selectedIndex = model.selectedIndex;
model.loadFcsShipments(_selectedIndex);
if (mounted) {
setState(() {});
}
}
@override
Widget build(BuildContext context) {
var shipmentModel = Provider.of<FcsShipmentModel>(context);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: LocalAppBar(
labelKey: "FCSshipment.list.title", actions: [
//popupMenu,
_menuFilteringWidget(context),
]),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
_newShipment();
},
icon: Icon(Icons.add),
label:
LocalText(context, "FCSshipment.add", color: Colors.white),
backgroundColor: primaryColor),
body: PaginatorListView<FcsShipment>(
paginatorListener: shipmentModel.fcsShipments!,
rowBuilder: (p) => FcsShipmentListRow(shipment: p),
color: primaryColor)));
}
_newShipment() {
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) => FcsShipmentEditor()));
}
Widget _menuFilteringWidget(BuildContext context) {
return PopupMenuButton<LocalPopupMenu>(
splashRadius: 25,
padding: const EdgeInsets.only(right: 15),
elevation: 3.2,
tooltip: 'This is tooltip',
onSelected: (choice) async {
setState(() {
_selectedIndex = choice.id;
});
await context.read<FcsShipmentModel>().onChanged(choice.id);
},
icon: Stack(
alignment: Alignment.center,
children: <Widget>[
const Icon(
Ionicons.filter,
color: Colors.white,
),
_selectedIndex != 0
? Positioned(
bottom: 15,
right: 0,
child: Container(
width: 10,
height: 10,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.red,
),
),
)
: Container()
],
),
itemBuilder: (BuildContext context) {
return shipFiteringMenu.map((LocalPopupMenu choice) {
return PopupMenuItem<LocalPopupMenu>(
value: choice,
child: Row(
children: <Widget>[
Flexible(child: Text("${choice.text}")),
const SizedBox(
width: 10,
),
_selectedIndex == choice.id
? const Icon(
Icons.check,
color: Colors.grey,
)
: const SizedBox(),
],
),
);
}).toList();
});
}
}