257 lines
7.2 KiB
Dart
257 lines
7.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:fcs/model/main_model.dart';
|
|
import 'package:fcs/pages/util.dart';
|
|
import 'package:fcs/fcs/common/theme.dart';
|
|
import 'package:fcs/vo/setting.dart';
|
|
import 'package:fcs/widget/local_text.dart';
|
|
import 'package:fcs/widget/progress.dart';
|
|
|
|
class Time {
|
|
final int value;
|
|
Time(this.value);
|
|
String get getValue =>
|
|
value > 12 ? (value - 12).toString() + "PM" : value.toString() + "AM";
|
|
|
|
@override
|
|
bool operator ==(other) {
|
|
if (identical(this, other)) {
|
|
return true;
|
|
}
|
|
return other.value == this.value;
|
|
}
|
|
|
|
@override
|
|
int get hashCode {
|
|
int result = 17;
|
|
result = 37 * result + value.hashCode;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
class SettingOwner extends StatefulWidget {
|
|
final Setting setting;
|
|
const SettingOwner({this.setting});
|
|
@override
|
|
_SettingOwnerState createState() => _SettingOwnerState();
|
|
}
|
|
|
|
class _SettingOwnerState extends State<SettingOwner> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
bool _isLoading = false;
|
|
List<Day> days = [];
|
|
int poOpenAt = 0;
|
|
int poCloseAt = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
days = dayLists;
|
|
if (widget.setting != null) {
|
|
poOpenAt = widget.setting.poOpenAt;
|
|
poCloseAt = widget.setting.poCloseAt;
|
|
days.forEach((d) => widget.setting.poCloseOn.contains(d.id)
|
|
? d.isChecked = true
|
|
: d.isChecked = false);
|
|
}
|
|
}
|
|
|
|
Widget showDayList(BuildContext context, MainModel mainModel) {
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(vertical: 5.0),
|
|
height: 500.0,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 10, top: 10),
|
|
child: Text(
|
|
"PO submission closed Day",
|
|
style: TextStyle(color: Colors.black54),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: days.length,
|
|
scrollDirection: Axis.vertical,
|
|
padding: EdgeInsets.only(top: 10),
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return new Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
new Checkbox(
|
|
value: days[index].isChecked == null
|
|
? false
|
|
: days[index].isChecked,
|
|
activeColor: primaryColor,
|
|
onChanged: (bool value) {
|
|
setState(() {
|
|
days[index].isChecked = value;
|
|
});
|
|
}),
|
|
Container(
|
|
padding: EdgeInsets.only(top: 13),
|
|
child: new Text(
|
|
dayLists[index].name,
|
|
style: TextStyle(
|
|
fontSize: 15.0,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var mainModel = Provider.of<MainModel>(context);
|
|
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: primaryColor,
|
|
title: LocalText(
|
|
context,
|
|
"setting.title",
|
|
fontSize: 20,
|
|
color: Colors.white,
|
|
),
|
|
actions: <Widget>[
|
|
IconButton(
|
|
icon: Icon(Icons.send),
|
|
onPressed: () {
|
|
if (!_formKey.currentState.validate()) return;
|
|
showConfirmDialog(context, "setting.confirm", () {
|
|
_submit();
|
|
});
|
|
})
|
|
],
|
|
),
|
|
body: ListView(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 24),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text("PO submission opened at:"),
|
|
),
|
|
getDropDown(poOpenAt, (value) {
|
|
setState(() {
|
|
setState(() {
|
|
this.poOpenAt = value;
|
|
});
|
|
});
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 24),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text("PO submission closed at:"),
|
|
),
|
|
getDropDown(poCloseAt, (value) {
|
|
setState(() {
|
|
setState(() {
|
|
this.poCloseAt = value;
|
|
});
|
|
});
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
Form(
|
|
key: _formKey,
|
|
child: ListView(
|
|
shrinkWrap: true,
|
|
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
|
children: <Widget>[
|
|
showDayList(context, mainModel),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
));
|
|
}
|
|
|
|
Widget getDropDown(int initial, Function(int) onChanged) {
|
|
Time value = Time(initial);
|
|
return DropdownButton<Time>(
|
|
value: value,
|
|
icon: Icon(Icons.arrow_downward),
|
|
iconSize: 24,
|
|
elevation: 16,
|
|
style: TextStyle(color: Colors.deepPurple),
|
|
underline: Container(
|
|
height: 2,
|
|
color: primaryColor,
|
|
),
|
|
onChanged: (value) => onChanged(value.value),
|
|
items: <Time>[
|
|
Time(0),
|
|
Time(1),
|
|
Time(2),
|
|
Time(3),
|
|
Time(4),
|
|
Time(5),
|
|
Time(6),
|
|
Time(7),
|
|
Time(8),
|
|
Time(9),
|
|
Time(10),
|
|
Time(11),
|
|
Time(12),
|
|
Time(13),
|
|
Time(14),
|
|
Time(15),
|
|
Time(16),
|
|
Time(17),
|
|
Time(18),
|
|
Time(19),
|
|
Time(20),
|
|
Time(21),
|
|
Time(22),
|
|
Time(23),
|
|
].map<DropdownMenuItem<Time>>((Time value) {
|
|
return DropdownMenuItem<Time>(
|
|
value: value,
|
|
child: Text(value.getValue),
|
|
);
|
|
}).toList(),
|
|
);
|
|
}
|
|
|
|
_submit() async {
|
|
setState(() {
|
|
_isLoading = true;
|
|
});
|
|
try {
|
|
widget.setting.poCloseOn =
|
|
this.days.where((d) => d.isChecked == true).map((p) => p.id).toList();
|
|
widget.setting.poOpenAt = poOpenAt;
|
|
widget.setting.poCloseAt = poCloseAt;
|
|
var mainModel = Provider.of<MainModel>(context);
|
|
await mainModel.updateSetting(widget.setting);
|
|
Navigator.pop(context);
|
|
} catch (e) {
|
|
showMsgDialog(context, "Error", e.toString());
|
|
} finally {
|
|
setState(() {
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
}
|