192 lines
6.9 KiB
Dart
192 lines
6.9 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
import 'package:fcs/model/storage_model.dart';
|
||
|
|
import 'package:fcs/pages/storage/storage_addition.dart';
|
||
|
|
import 'package:fcs/theme/theme.dart';
|
||
|
|
import 'package:fcs/vo/popup_menu.dart';
|
||
|
|
import 'package:fcs/vo/storage.dart';
|
||
|
|
import 'package:fcs/widget/local_text.dart';
|
||
|
|
import 'package:fcs/widget/my_data_table.dart';
|
||
|
|
import 'package:fcs/widget/number_cell.dart';
|
||
|
|
import 'package:fcs/widget/popupmenu.dart';
|
||
|
|
import 'package:fcs/widget/progress.dart';
|
||
|
|
|
||
|
|
import 'inventory_taking_list.dart';
|
||
|
|
|
||
|
|
class StorageList extends StatefulWidget {
|
||
|
|
@override
|
||
|
|
_StorageListState createState() => _StorageListState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _StorageListState extends State<StorageList> {
|
||
|
|
final double dotSize = 15.0;
|
||
|
|
PopupMenu selectedChoices = storageMenus[0];
|
||
|
|
bool _isLoading = false;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
var storageModel = Provider.of<StorageModel>(context);
|
||
|
|
|
||
|
|
void _select(PopupMenu choice) async {
|
||
|
|
selectedChoices = choice;
|
||
|
|
if (choice.status == "Inventory Takings") {
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(builder: (context) => InventoryTakingList()),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return LocalProgress(
|
||
|
|
inAsyncCall: _isLoading,
|
||
|
|
child: Scaffold(
|
||
|
|
appBar: AppBar(
|
||
|
|
backgroundColor: primaryColor,
|
||
|
|
title: LocalText(
|
||
|
|
context,
|
||
|
|
"storage.title",
|
||
|
|
color: Colors.white,
|
||
|
|
fontSize: 20,
|
||
|
|
),
|
||
|
|
actions: <Widget>[
|
||
|
|
PopupMenuButton<PopupMenu>(
|
||
|
|
elevation: 3.2,
|
||
|
|
onSelected: _select,
|
||
|
|
itemBuilder: (BuildContext context) {
|
||
|
|
return storageMenus.map((PopupMenu choice) {
|
||
|
|
return PopupMenuItem<PopupMenu>(
|
||
|
|
value: choice,
|
||
|
|
child: Text(choice.status),
|
||
|
|
);
|
||
|
|
}).toList();
|
||
|
|
})
|
||
|
|
],
|
||
|
|
),
|
||
|
|
floatingActionButton: FloatingActionButton(
|
||
|
|
backgroundColor: primaryColor,
|
||
|
|
child: Icon(Icons.add),
|
||
|
|
onPressed: () {
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(builder: (context) => StorageAddition()),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
body: new ListView.builder(
|
||
|
|
padding: EdgeInsets.only(left: 10, right: 10, top: 15),
|
||
|
|
shrinkWrap: true,
|
||
|
|
itemCount: storageModel.storages.length,
|
||
|
|
itemBuilder: (BuildContext context, int index) {
|
||
|
|
return Card(
|
||
|
|
elevation: 10,
|
||
|
|
color: Colors.white,
|
||
|
|
child: Theme(
|
||
|
|
data: ThemeData(accentColor: Colors.grey),
|
||
|
|
child: ExpansionTile(
|
||
|
|
onExpansionChanged: (e) =>
|
||
|
|
_onExpend(context, e, storageModel.storages[index]),
|
||
|
|
title: Row(
|
||
|
|
children: <Widget>[
|
||
|
|
new Row(
|
||
|
|
children: <Widget>[
|
||
|
|
new Padding(
|
||
|
|
padding: new EdgeInsets.symmetric(
|
||
|
|
horizontal: 10.0 - dotSize / 2),
|
||
|
|
child: Padding(
|
||
|
|
padding: EdgeInsets.all(10.0),
|
||
|
|
child: Image.asset(
|
||
|
|
"assets/inventory.png",
|
||
|
|
width: 40,
|
||
|
|
color: primaryColor,
|
||
|
|
)),
|
||
|
|
),
|
||
|
|
Padding(
|
||
|
|
padding: const EdgeInsets.all(8.0),
|
||
|
|
child: new Text(
|
||
|
|
storageModel.storages[index].name == null
|
||
|
|
? ""
|
||
|
|
: storageModel.storages[index].name,
|
||
|
|
style: textStyle),
|
||
|
|
),
|
||
|
|
Padding(
|
||
|
|
padding: const EdgeInsets.only(left: 8.0),
|
||
|
|
child: IconButton(
|
||
|
|
icon: Icon(Icons.edit),
|
||
|
|
onPressed: () {
|
||
|
|
Navigator.push(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(
|
||
|
|
builder: (context) => StorageAddition(
|
||
|
|
storage:
|
||
|
|
storageModel.storages[index])),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
SizedBox(
|
||
|
|
height: 15,
|
||
|
|
)
|
||
|
|
],
|
||
|
|
),
|
||
|
|
children: <Widget>[
|
||
|
|
storageModel.storages[index].productsLoaded
|
||
|
|
? Container(
|
||
|
|
padding: EdgeInsets.only(top: 10),
|
||
|
|
child: SingleChildScrollView(
|
||
|
|
scrollDirection: Axis.horizontal,
|
||
|
|
child: MyDataTable(
|
||
|
|
headingRowHeight: 40,
|
||
|
|
columnSpacing: 50,
|
||
|
|
columns: [
|
||
|
|
MyDataColumn(
|
||
|
|
label: LocalText(
|
||
|
|
context, "inventory.product"),
|
||
|
|
),
|
||
|
|
MyDataColumn(
|
||
|
|
label: LocalText(
|
||
|
|
context, "inventory.quantity"),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
rows: getProductRow(
|
||
|
|
storageModel.storages[index]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
: Text("Loading..."),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
List<MyDataRow> getProductRow(Storage storage) {
|
||
|
|
return storage.products.map((p) {
|
||
|
|
return MyDataRow(
|
||
|
|
cells: [
|
||
|
|
MyDataCell(
|
||
|
|
new Text(
|
||
|
|
p.name,
|
||
|
|
style: textStyle,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
MyDataCell(
|
||
|
|
NumberCell(p.quantity)
|
||
|
|
),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
}).toList();
|
||
|
|
}
|
||
|
|
|
||
|
|
_onExpend(BuildContext context, expended, Storage storage) {
|
||
|
|
if (!expended) return;
|
||
|
|
storage.productsLoaded = false;
|
||
|
|
StorageModel storageModel = Provider.of<StorageModel>(context);
|
||
|
|
storageModel.loadProducts(storage);
|
||
|
|
}
|
||
|
|
}
|