add structure
This commit is contained in:
158
lib/pages/do/po_selection.dart
Normal file
158
lib/pages/do/po_selection.dart
Normal file
@@ -0,0 +1,158 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/po.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
|
||||
class POSelection extends StatefulWidget {
|
||||
final List<POSubmission> pos;
|
||||
final List<POSubmission> selectedPOs;
|
||||
|
||||
POSelection({Key key, this.pos, this.selectedPOs}) : super(key: key);
|
||||
|
||||
@override
|
||||
_POSelectionState createState() => new _POSelectionState();
|
||||
|
||||
static Future<void> showPOSelection(BuildContext context,
|
||||
List<POSubmission> pos, List<POSubmission> selectedPOs,
|
||||
{ok(List<POSubmission> pos)}) async {
|
||||
List<POSubmission> _selectedPOs = [];
|
||||
selectedPOs.forEach((i) => _selectedPOs.add(i));
|
||||
|
||||
final poselection = POSelection(
|
||||
pos: pos,
|
||||
selectedPOs: _selectedPOs,
|
||||
);
|
||||
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (_) {
|
||||
return AlertDialog(
|
||||
title: Center(
|
||||
child: LocalText(context, "po.title"),
|
||||
),
|
||||
content: Container(
|
||||
width: double.maxFinite,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: <Widget>[
|
||||
poselection,
|
||||
Container(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
FlatButton(
|
||||
child: LocalText(context, "Cancel"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
FlatButton(
|
||||
color: primaryColor,
|
||||
child: LocalText(context, "Ok"),
|
||||
onPressed: () async {
|
||||
if (ok != null) ok(_selectedPOs);
|
||||
Navigator.of(context).pop();
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _POSelectionState extends State<POSelection> {
|
||||
List<POSubmission> pos;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
pos = widget.pos;
|
||||
pos.sort((p1, p2) => p1.poNumber.compareTo(p2.poNumber));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var width = MediaQuery.of(context).size.width * 0.8;
|
||||
var height = MediaQuery.of(context).size.height * 0.5;
|
||||
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
FlatButton(
|
||||
child: Text("Select All"),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
widget.selectedPOs.clear();
|
||||
widget.selectedPOs.addAll(pos);
|
||||
});
|
||||
}),
|
||||
Container(
|
||||
width: width,
|
||||
height: height,
|
||||
child: Column(
|
||||
children: pos.asMap().entries.map((p) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (widget.selectedPOs.contains(p.value)) {
|
||||
widget.selectedPOs.remove(p.value);
|
||||
} else {
|
||||
widget.selectedPOs.add(p.value);
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
onChanged: (v) => {_update(p.key)},
|
||||
value: widget.selectedPOs.contains(p.value),
|
||||
),
|
||||
Text(p.value.poNumber),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
// child: ListView.builder(
|
||||
// itemCount: pos.length,
|
||||
// scrollDirection: Axis.vertical,
|
||||
// itemBuilder: (BuildContext ctxt, int index) {
|
||||
// return InkWell(
|
||||
// onTap: () {
|
||||
// setState(() {
|
||||
// if (widget.selectedPOs.contains(pos[index])) {
|
||||
// widget.selectedPOs.remove(pos[index]);
|
||||
// } else {
|
||||
// widget.selectedPOs.add(pos[index]);
|
||||
// }
|
||||
// });
|
||||
// },
|
||||
// child: Row(
|
||||
// children: <Widget>[
|
||||
// Checkbox(
|
||||
// onChanged: (v) => {_update(index)},
|
||||
// value: widget.selectedPOs.contains(pos[index]),
|
||||
// ),
|
||||
// Text(pos[index].poNumber),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_update(int index) {
|
||||
setState(() {
|
||||
if (widget.selectedPOs.contains(pos[index])) {
|
||||
widget.selectedPOs.remove(pos[index]);
|
||||
} else {
|
||||
widget.selectedPOs.add(pos[index]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user