Browse Source

ui action sell, packing

master
daivph 5 years ago
parent
commit
6b589361a5
2 changed files with 342 additions and 277 deletions
  1. +169
    -137
      lib/presentation/screens/actions/packing/sc_edit_action_packing.dart
  2. +173
    -140
      lib/presentation/screens/actions/sell/sc_edit_action_sell.dart

+ 169
- 137
lib/presentation/screens/actions/packing/sc_edit_action_packing.dart View File

@@ -4,9 +4,12 @@ import 'package:farm_tpf/custom_model/Harvest.dart';
import 'package:farm_tpf/custom_model/Packing.dart';
import 'package:farm_tpf/data/api/app_exception.dart';
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart';
import 'package:farm_tpf/presentation/custom_widgets/button_widget.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_text_field_description.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_text_form_field.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart';
import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart';
@@ -203,7 +206,7 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> {
)),
Icon(
Icons.date_range,
color: Colors.blue,
color: Colors.grey,
),
],
)));
@@ -250,9 +253,7 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> {
}

Widget _descriptionField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Ghi chú"),
return TextFieldDescriptionWidget(
controller: _descriptionController,
onSaved: (newValue) {
_packing.description = newValue;
@@ -270,27 +271,6 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> {
);
}

_actionAppBar() {
IconButton iconButton;
if (1 == 1) {
iconButton = IconButton(
icon: Icon(
Icons.done,
color: Colors.black,
),
onPressed: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
},
);
return <Widget>[iconButton];
}
return <Widget>[Container()];
}

@override
Widget build(BuildContext context) => KeyboardDismisser(
gestures: [
@@ -298,11 +278,22 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> {
GestureType.onPanUpdateDownDirection,
],
child: Scaffold(
backgroundColor: Colors.white,
key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title: Text(plot_action_packing),
actions: _actionAppBar()),
appBar: AppBarWidget(
isBack: true,
action: InkWell(
child: Text(
'Huỷ',
style: TextStyle(
color: Colors.red, fontWeight: FontWeight.normal),
),
onTap: () {
if (Get.isSnackbarOpen) Get.back();
Get.back();
},
),
),
body: KeyboardDismisser(
child: MultiBlocProvider(
providers: [
@@ -321,119 +312,160 @@ class _EditActionPackingScreenState extends State<EditActionPackingScreen> {
child: Form(
key: _formKey,
autovalidate: _autoValidate,
child: SingleChildScrollView(
padding: EdgeInsets.all(8.0),
child: BlocConsumer<ActionDetailBloc, ActionDetailState>(
listener: (context, state) async {
if (state is ActionDetailFailure) {
LoadingDialog.hideLoadingDialog(context);
} else if (state is ActionDetailSuccess) {
LoadingDialog.hideLoadingDialog(context);
print(state.item);
_packing = Packing.fromJson(state.item);
_packing.activityId = widget.activityId;
_l1Controller.text =
_packing.quantityLv1.formatNumtoStringDecimal();
_l2Controller.text =
_packing.quantityLv2.formatNumtoStringDecimal();
_l3Controller.text =
_packing.quantityLv3.formatNumtoStringDecimal();
_removedQuantityController.text = _packing
.removedQuantity
.formatNumtoStringDecimal();
_descriptionController.text =
_packing.description ?? "";
_executeByController.text = _packing.executeBy;
child: SafeArea(
child: SingleChildScrollView(
child:
BlocConsumer<ActionDetailBloc, ActionDetailState>(
listener: (context, state) async {
if (state is ActionDetailFailure) {
LoadingDialog.hideLoadingDialog(context);
} else if (state is ActionDetailSuccess) {
LoadingDialog.hideLoadingDialog(context);
print(state.item);
_packing = Packing.fromJson(state.item);
_packing.activityId = widget.activityId;
_l1Controller.text = _packing.quantityLv1
.formatNumtoStringDecimal();
_l2Controller.text = _packing.quantityLv2
.formatNumtoStringDecimal();
_l3Controller.text = _packing.quantityLv3
.formatNumtoStringDecimal();
_removedQuantityController.text = _packing
.removedQuantity
.formatNumtoStringDecimal();
_descriptionController.text =
_packing.description ?? "";
_executeByController.text = _packing.executeBy;

//select harvest
getHarvestBloc.getHarvests((data) {
_harvests = data;
for (var item in _harvests) {
if (item.id == _packing.harvestId) {
harvestValue = item;
break;
//select harvest
getHarvestBloc.getHarvests((data) {
_harvests = data;
for (var item in _harvests) {
if (item.id == _packing.harvestId) {
harvestValue = item;
break;
}
}
}
}, (err) {});
}, (err) {});

executeTime = _packing.executeDate
.convertStringServerDateTimeToLocalDateTime();
executeTimeView =
executeTime.displayDateTime_DDMMYYYY_HHmm();
//Show media
if (Validators.stringNotNullOrEmpty(
_packing.media)) {
BlocProvider.of<MediaHelperBloc>(context).add(
ChangeListMedia(
items: UtilAction.convertFilePathToMedia(
_packing.media)));
executeTime = _packing.executeDate
.convertStringServerDateTimeToLocalDateTime();
executeTimeView =
executeTime.displayDateTime_DDMMYYYY_HHmm();
//Show media
if (Validators.stringNotNullOrEmpty(
_packing.media)) {
BlocProvider.of<MediaHelperBloc>(context).add(
ChangeListMedia(
items:
UtilAction.convertFilePathToMedia(
_packing.media)));
}
} else if (state is ActionDetailInitial) {
} else if (state is ActionDetailLoading) {
LoadingDialog.showLoadingDialog(context);
}
} else if (state is ActionDetailInitial) {
} else if (state is ActionDetailLoading) {
LoadingDialog.showLoadingDialog(context);
}
},
builder: (context, state) {
return Column(
children: <Widget>[
Container(
width: double.infinity,
child: Text(
"Ngày thực hiện *",
style: TextStyle(
color: Colors.black54, fontSize: 13.0),
},
builder: (context, state) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
plot_action_packing,
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 22),
),
SizedBox(
height: 8.0,
),
Container(
width: double.infinity,
child: Text(
"Ngày thực hiện *",
style: TextStyle(
color: Colors.black54,
fontSize: 13.0),
),
),
_btnExecuteTimePicker(),
SizedBox(
height: 8.0,
),
_dropdownHarvest(),
SizedBox(
height: 8.0,
),
_l1Field(),
SizedBox(
height: 8.0,
),
_l2Field(),
SizedBox(
height: 8.0,
),
_l3Field(),
SizedBox(
height: 8.0,
),
_removedQuantityField(),
SizedBox(
height: 8.0,
),
_descriptionField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
],
),
),
),
_btnExecuteTimePicker(),
SizedBox(
height: 8.0,
),
_dropdownHarvest(),
SizedBox(
height: 8.0,
),
_l1Field(),
SizedBox(
height: 8.0,
),
_l2Field(),
SizedBox(
height: 8.0,
),
_l3Field(),
SizedBox(
height: 8.0,
),
_removedQuantityField(),
SizedBox(
height: 8.0,
),
_descriptionField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
BlocBuilder<MediaHelperBloc, MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
});
} else {
return Center(
child: CircularProgressIndicator());
}
}),
],
);
},
Container(
width: double.infinity,
height: 16,
color: Colors.grey[200],
),
BlocBuilder<MediaHelperBloc, MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>()
.change(newPathFiles,
deletePathFiles);
});
} else {
return Center(
child: CircularProgressIndicator());
}
}),
Padding(
padding: const EdgeInsets.all(8.0),
child: ButtonWidget(
title: 'CẬP NHẬT',
onPressed: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
}),
)
],
);
},
),
),
)),
))));

+ 173
- 140
lib/presentation/screens/actions/sell/sc_edit_action_sell.dart View File

@@ -4,9 +4,12 @@ import 'package:farm_tpf/custom_model/Harvest.dart';
import 'package:farm_tpf/custom_model/Sell.dart';
import 'package:farm_tpf/data/api/app_exception.dart';
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart';
import 'package:farm_tpf/presentation/custom_widgets/button_widget.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_text_field_description.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_text_form_field.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_utils.dart';
import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart';
@@ -259,9 +262,7 @@ class _EditActionSellScreenState extends State<EditActionSellScreen> {
}

Widget _descriptionField() {
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(labelText: "Ghi chú"),
return TextFieldDescriptionWidget(
controller: _descriptionController,
onSaved: (newValue) {
_sell.description = newValue;
@@ -279,27 +280,6 @@ class _EditActionSellScreenState extends State<EditActionSellScreen> {
);
}

_actionAppBar() {
IconButton iconButton;
if (1 == 1) {
iconButton = IconButton(
icon: Icon(
Icons.done,
color: Colors.black,
),
onPressed: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
},
);
return <Widget>[iconButton];
}
return <Widget>[Container()];
}

@override
Widget build(BuildContext context) => KeyboardDismisser(
gestures: [
@@ -307,11 +287,22 @@ class _EditActionSellScreenState extends State<EditActionSellScreen> {
GestureType.onPanUpdateDownDirection,
],
child: Scaffold(
backgroundColor: Colors.white,
key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title: Text(plot_action_sell),
actions: _actionAppBar()),
appBar: AppBarWidget(
isBack: true,
action: InkWell(
child: Text(
'Huỷ',
style: TextStyle(
color: Colors.red, fontWeight: FontWeight.normal),
),
onTap: () {
if (Get.isSnackbarOpen) Get.back();
Get.back();
},
),
),
body: KeyboardDismisser(
child: MultiBlocProvider(
providers: [
@@ -330,123 +321,165 @@ class _EditActionSellScreenState extends State<EditActionSellScreen> {
child: Form(
key: _formKey,
autovalidate: _autoValidate,
child: SingleChildScrollView(
padding: EdgeInsets.all(8.0),
child: BlocConsumer<ActionDetailBloc, ActionDetailState>(
listener: (context, state) async {
if (state is ActionDetailFailure) {
LoadingDialog.hideLoadingDialog(context);
} else if (state is ActionDetailSuccess) {
LoadingDialog.hideLoadingDialog(context);
print(state.item);
_sell = Sell.fromJson(state.item);
_sell.activityId = widget.activityId;
_l1Controller.text =
_sell.quantityLv1.formatNumtoStringDecimal();
_l2Controller.text =
_sell.quantityLv2.formatNumtoStringDecimal();
_l3Controller.text =
_sell.quantityLv3.formatNumtoStringDecimal();
_removedQuantityController.text = _sell
.removedQuantity
.formatNumtoStringDecimal();
_buyerController.text = _sell.buyer ?? "";
_descriptionController.text =
_sell.description ?? "";
_executeByController.text = _sell.executeBy;
child: SafeArea(
child: SingleChildScrollView(
child:
BlocConsumer<ActionDetailBloc, ActionDetailState>(
listener: (context, state) async {
if (state is ActionDetailFailure) {
LoadingDialog.hideLoadingDialog(context);
} else if (state is ActionDetailSuccess) {
LoadingDialog.hideLoadingDialog(context);
print(state.item);
_sell = Sell.fromJson(state.item);
_sell.activityId = widget.activityId;
_l1Controller.text =
_sell.quantityLv1.formatNumtoStringDecimal();
_l2Controller.text =
_sell.quantityLv2.formatNumtoStringDecimal();
_l3Controller.text =
_sell.quantityLv3.formatNumtoStringDecimal();
_removedQuantityController.text = _sell
.removedQuantity
.formatNumtoStringDecimal();
_buyerController.text = _sell.buyer ?? "";
_descriptionController.text =
_sell.description ?? "";
_executeByController.text = _sell.executeBy;

//select harvest
getHarvestBloc.getHarvests((data) {
_harvests = data;
for (var item in _harvests) {
if (item.id == _sell.harvestId) {
harvestValue = item;
break;
//select harvest
getHarvestBloc.getHarvests((data) {
_harvests = data;
for (var item in _harvests) {
if (item.id == _sell.harvestId) {
harvestValue = item;
break;
}
}
}
}, (err) {});
}, (err) {});

executeTime = _sell.executeDate
.convertStringServerDateTimeToLocalDateTime();
executeTimeView =
executeTime.displayDateTime_DDMMYYYY_HHmm();
//Show media
if (Validators.stringNotNullOrEmpty(_sell.media)) {
BlocProvider.of<MediaHelperBloc>(context).add(
ChangeListMedia(
items: UtilAction.convertFilePathToMedia(
_sell.media)));
executeTime = _sell.executeDate
.convertStringServerDateTimeToLocalDateTime();
executeTimeView =
executeTime.displayDateTime_DDMMYYYY_HHmm();
//Show media
if (Validators.stringNotNullOrEmpty(
_sell.media)) {
BlocProvider.of<MediaHelperBloc>(context).add(
ChangeListMedia(
items:
UtilAction.convertFilePathToMedia(
_sell.media)));
}
} else if (state is ActionDetailInitial) {
} else if (state is ActionDetailLoading) {
LoadingDialog.showLoadingDialog(context);
}
} else if (state is ActionDetailInitial) {
} else if (state is ActionDetailLoading) {
LoadingDialog.showLoadingDialog(context);
}
},
builder: (context, state) {
return Column(
children: <Widget>[
Container(
width: double.infinity,
child: Text(
"Ngày thực hiện *",
style: TextStyle(
color: Colors.black54, fontSize: 13.0),
},
builder: (context, state) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
plot_action_sell,
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 22),
),
SizedBox(
height: 8.0,
),
Container(
width: double.infinity,
child: Text(
"Ngày thực hiện *",
style: TextStyle(
color: Colors.black54,
fontSize: 13.0),
),
),
_btnExecuteTimePicker(),
SizedBox(
height: 8.0,
),
_dropdownHarvest(),
SizedBox(
height: 8.0,
),
_l1Field(),
SizedBox(
height: 8.0,
),
_l2Field(),
SizedBox(
height: 8.0,
),
_l3Field(),
SizedBox(
height: 8.0,
),
_removedQuantityField(),
SizedBox(
height: 8.0,
),
_buyerField(),
SizedBox(
height: 8.0,
),
_descriptionField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
],
),
),
),
_btnExecuteTimePicker(),
SizedBox(
height: 8.0,
),
_dropdownHarvest(),
SizedBox(
height: 8.0,
),
_l1Field(),
SizedBox(
height: 8.0,
),
_l2Field(),
SizedBox(
height: 8.0,
),
_l3Field(),
SizedBox(
height: 8.0,
),
_removedQuantityField(),
SizedBox(
height: 8.0,
),
_buyerField(),
SizedBox(
height: 8.0,
),
_descriptionField(),
SizedBox(
height: 8.0,
),
_executeByField(),
SizedBox(
height: 8.0,
),
BlocBuilder<MediaHelperBloc, MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>().change(
newPathFiles, deletePathFiles);
});
} else {
return Center(
child: CircularProgressIndicator());
}
}),
],
);
},
Container(
width: double.infinity,
height: 16,
color: Colors.grey[200],
),
BlocBuilder<MediaHelperBloc, MediaHelperState>(
builder: (context, state) {
if (state is MediaHelperSuccess) {
return WidgetMediaPicker(
currentItems: state.items,
onChangeFiles: (newPathFiles,
deletePathFiles) async {
Get.find<ChangeFileController>()
.change(newPathFiles,
deletePathFiles);
});
} else {
return Center(
child: CircularProgressIndicator());
}
}),
Padding(
padding: const EdgeInsets.all(8.0),
child: ButtonWidget(
title: 'CẬP NHẬT',
onPressed: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
}),
),
],
);
},
),
),
)),
))));

Loading…
Cancel
Save