Browse Source

action plant

master
daivph 5 years ago
parent
commit
1494808bd3
7 changed files with 564 additions and 9 deletions
  1. +1
    -1
      ios/Flutter/.last_build_id
  2. +12
    -5
      ios/Runner.xcodeproj/project.pbxproj
  3. +13
    -1
      lib/custom_model/SuppliesUsing.dart
  4. +21
    -1
      lib/presentation/screens/actions/plant/sc_edit_action_plant.dart
  5. +480
    -0
      lib/presentation/screens/actions/plant/widget_plant_supply.dart
  6. +6
    -1
      lib/presentation/screens/actions/state_management_helper/change_supply.dart
  7. +31
    -0
      lib/presentation/screens/actions/util_action.dart

+ 1
- 1
ios/Flutter/.last_build_id View File

0d1f90510e22958a585802bb59f9c570
eb141365fb69a4e0decadd2584d53516

+ 12
- 5
ios/Runner.xcodeproj/project.pbxproj View File

9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FA128B3A24FC9B6100A49ACD /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; }; FA128B3A24FC9B6100A49ACD /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
FAC381012522E8BF00B28531 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/Main.strings; sourceTree = "<group>"; };
FAC381022522E8C000B28531 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
FAC381032522E8DC00B28531 /* vi */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = vi; path = vi.lproj/Main.storyboard; sourceTree = "<group>"; };
FAC381042522E8DF00B28531 /* vi */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = vi; path = vi.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
FAD6CEB024FC9E250067930A /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; }; FAD6CEB024FC9E250067930A /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */


hasScannedForEncodings = 0; hasScannedForEncodings = 0;
knownRegions = ( knownRegions = (
en, en,
Base,
vi,
); );
mainGroup = 97C146E51CF9000F007C117D; mainGroup = 97C146E51CF9000F007C117D;
productRefGroup = 97C146EF1CF9000F007C117D /* Products */; productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
97C146FA1CF9000F007C117D /* Main.storyboard */ = { 97C146FA1CF9000F007C117D /* Main.storyboard */ = {
isa = PBXVariantGroup; isa = PBXVariantGroup;
children = ( children = (
97C146FB1CF9000F007C117D /* Base */,
FAC381012522E8BF00B28531 /* vi */,
FAC381032522E8DC00B28531 /* vi */,
); );
name = Main.storyboard; name = Main.storyboard;
sourceTree = "<group>"; sourceTree = "<group>";
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup; isa = PBXVariantGroup;
children = ( children = (
97C147001CF9000F007C117D /* Base */,
FAC381022522E8C000B28531 /* vi */,
FAC381042522E8DF00B28531 /* vi */,
); );
name = LaunchScreen.storyboard; name = LaunchScreen.storyboard;
sourceTree = "<group>"; sourceTree = "<group>";
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++"; CLANG_CXX_LIBRARY = "libc++";
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++"; CLANG_CXX_LIBRARY = "libc++";
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++"; CLANG_CXX_LIBRARY = "libc++";

+ 13
- 1
lib/custom_model/SuppliesUsing.dart View File

String howToUse; String howToUse;
int suppliesInWarehouseId; int suppliesInWarehouseId;
int equipmentOfCustomerId; int equipmentOfCustomerId;
int tbSuppliesInWarehouseId;
String supplyName;
String supplyUnit;


SuppliesUsing( SuppliesUsing(
{this.id, {this.id,
this.unit, this.unit,
this.howToUse, this.howToUse,
this.suppliesInWarehouseId, this.suppliesInWarehouseId,
this.equipmentOfCustomerId});
this.equipmentOfCustomerId,
this.tbSuppliesInWarehouseId,
this.supplyName,
this.supplyUnit});


SuppliesUsing.fromJson(Map<String, dynamic> json) { SuppliesUsing.fromJson(Map<String, dynamic> json) {
id = json['id']; id = json['id'];
howToUse = json['howToUse']; howToUse = json['howToUse'];
suppliesInWarehouseId = json['suppliesInWarehouseId']; suppliesInWarehouseId = json['suppliesInWarehouseId'];
equipmentOfCustomerId = json['equipmentOfCustomerId']; equipmentOfCustomerId = json['equipmentOfCustomerId'];
tbSuppliesInWarehouseId = json['tbSuppliesInWarehouseId'];
supplyName = json['supplyName'];
supplyUnit = json['supplyUnit'];
} }


Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
data['howToUse'] = this.howToUse; data['howToUse'] = this.howToUse;
data['suppliesInWarehouseId'] = this.suppliesInWarehouseId; data['suppliesInWarehouseId'] = this.suppliesInWarehouseId;
data['equipmentOfCustomerId'] = this.equipmentOfCustomerId; data['equipmentOfCustomerId'] = this.equipmentOfCustomerId;
data['tbSuppliesInWarehouseId'] = this.tbSuppliesInWarehouseId;
data['supplyName'] = this.supplyName;
data['supplyUnit'] = this.supplyUnit;
return data; return data;
} }
} }

+ 21
- 1
lib/presentation/screens/actions/plant/sc_edit_action_plant.dart View File

import 'package:farm_tpf/presentation/custom_widgets/widget_loading.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_media_picker.dart';
import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart';
import 'package:farm_tpf/presentation/screens/actions/plant/widget_plant_supply.dart';
import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_file_controller.dart'; import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_file_controller.dart';
import 'package:farm_tpf/utils/const_common.dart'; import 'package:farm_tpf/utils/const_common.dart';
import 'package:farm_tpf/utils/const_string.dart'; import 'package:farm_tpf/utils/const_string.dart';
final _quantityController = TextEditingController(); final _quantityController = TextEditingController();
final _densityController = TextEditingController(); final _densityController = TextEditingController();
final _executeByController = TextEditingController(); final _executeByController = TextEditingController();
List<SuppliesUsing> suppliesUsing;
List<SuppliesUsing> suppliesUsing = new List<SuppliesUsing>();


String executeTimeView; String executeTimeView;
DateTime executeTime = DateTime.now(); DateTime executeTime = DateTime.now();
_formKey.currentState.save(); _formKey.currentState.save();
LoadingDialog.showLoadingDialog(context); LoadingDialog.showLoadingDialog(context);
filePaths = Get.find<ChangeFileController>().files; filePaths = Get.find<ChangeFileController>().files;
List<SuppliesUsing> newSups = [];
suppliesUsing.forEach((sup) {
var newSup = sup;
newSup.suppliesInWarehouseId = sup.tbSuppliesInWarehouseId;
newSups.add(newSup);
});
_plant.suppliesUsing = newSups;
var activityPlant = jsonEncode(_plant.toJson()).toString(); var activityPlant = jsonEncode(_plant.toJson()).toString();
//ADD NEW //ADD NEW
if (_plant.activityId == null) { if (_plant.activityId == null) {
print("completed"); print("completed");
}); });
} }
//list supply
suppliesUsing = _plant.suppliesUsing;
Get.find<ChangeSupplyUsing>()
.changeInitList(suppliesUsing);
} else if (state is ActionDetailInitial) { } else if (state is ActionDetailInitial) {
print("init"); print("init");
} else if (state is ActionDetailLoading) { } else if (state is ActionDetailLoading) {
SizedBox( SizedBox(
height: 8.0, height: 8.0,
), ),
WidgetPlantSupply(
currentItems: [],
onChangeSupplies: (value) {
suppliesUsing = value;
}),
SizedBox(
height: 8.0,
),
BlocBuilder<MediaHelperBloc, BlocBuilder<MediaHelperBloc,
MediaHelperState>( MediaHelperState>(
builder: (context, state) { builder: (context, state) {

+ 480
- 0
lib/presentation/screens/actions/plant/widget_plant_supply.dart View File

import 'package:farm_tpf/custom_model/SuppliesUsing.dart';
import 'package:farm_tpf/custom_model/Supply.dart';
import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_supply.dart';
import 'package:farm_tpf/presentation/screens/actions/util_action.dart';
import 'package:farm_tpf/presentation/screens/resources/sc_resource_helper.dart';
import 'package:farm_tpf/utils/const_color.dart';
import 'package:farm_tpf/utils/const_common.dart';
import 'package:farm_tpf/utils/const_style.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:farm_tpf/utils/formatter.dart';
import 'package:intl/intl.dart';
import 'package:pattern_formatter/pattern_formatter.dart';

class WidgetPlantSupply extends StatefulWidget {
final List<SuppliesUsing> currentItems;
final Function(List<SuppliesUsing> supplyChanges) onChangeSupplies;
WidgetPlantSupply({this.currentItems, @required this.onChangeSupplies});
@override
_WidgetPlantSupplyState createState() => _WidgetPlantSupplyState();
}

class _WidgetPlantSupplyState extends State<WidgetPlantSupply> {
final _dosageController = TextEditingController();
final _quantityController = TextEditingController();
final changeSelectedSupply = Get.put(ChangeSupply());
final changeSupplyUsing = Get.put(ChangeSupplyUsing());
final changeUnit = Get.put(ChangeUnit());
final changeQuantity = Get.put(ChangeValueQuantity());
final changeButton = Get.put(ChangeButtonInForm());

@override
void initState() {
super.initState();
changeSelectedSupply.initValue();
changeSupplyUsing.init(widget.currentItems);
changeUnit.initValue();
changeQuantity.changeQuantity("");
changeButton.resetValue();
}

Widget _buildListSupply() {
return GetBuilder<ChangeSupplyUsing>(builder: (value) {
widget.onChangeSupplies(value.currentItems);
if (value.currentItems.isEmpty) {
return Container();
} else {
return Container(
height: 80,
child: ListView.builder(
physics: ClampingScrollPhysics(),
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: value.currentItems.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
print("edit");
changeSupplyUsing.changeIndexEdit(index);
changeButton.updateToEdit(true);
var editedSupplyUsing = value.currentItems[index];
var editedSupply = Supply()
..id = editedSupplyUsing.tbSuppliesInWarehouseId
..tbSuppliesName = editedSupplyUsing.supplyName
..unit = editedSupplyUsing.supplyUnit;
changeSelectedSupply.change(editedSupply);
changeQuantity.changeQuantity(editedSupplyUsing.quantity
.formatNumtoStringDecimal());
changeUnit
.updateListByUnitName(editedSupplyUsing.supplyUnit);
changeUnit.updateSelected(editedSupplyUsing.supplyUnit);
_dosageController.text = editedSupplyUsing.dosage;
},
child: Card(
child: Stack(
alignment: Alignment.bottomCenter,
overflow: Overflow.visible,
children: <Widget>[
Positioned(
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Container(
padding: EdgeInsets.all(4),
width: 150,
child: Column(
children: [
SizedBox(
height: 12.0,
),
Flexible(
child: Text(
value.currentItems[index].supplyName ??
"",
overflow: TextOverflow.ellipsis,
maxLines: 1),
),
Flexible(
child: Text(
"${value.currentItems[index].dosage ?? ""}")),
Flexible(
child: Text(
"${value.currentItems[index].quantity.formatNumtoStringDecimal() ?? ""} ${value.currentItems[index].supplyUnit ?? ""}")),
],
),
),
)),
Positioned(
top: -10,
right: -10,
child: IconButton(
icon: Icon(
Icons.cancel,
color: Colors.redAccent,
),
onPressed: () {
print("Delete");
changeSupplyUsing.deleteSupply(index);
}),
)
],
)));
}));
}
});
}

Widget _btnSelectSubstrates() {
return GetBuilder<ChangeSupply>(builder: (data) {
return FlatButton(
padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => ResourceHelperScreen(
titleName: "Hoá chất xử lý",
type: ConstCommon.supplyTypeAll,
selectedId: changeSelectedSupply.selectedSupplyId),
fullscreenDialog: false))
.then((value) {
if (value != null) {
var result = value as Supply;
changeSelectedSupply.change(result);
changeUnit.updateListByUnitName(result.unit);
}
});
},
child: Container(
padding: EdgeInsets.only(
top: 0.0, right: 0.0, bottom: 10.5, left: 0.0),
decoration: BoxDecoration(
border: kBorderTextField,
),
child: Row(
children: [
GetBuilder<ChangeSupply>(
builder: (_) => Expanded(
child: Text(
changeSelectedSupply.selectedSupplyName ??
"Hoá chất xử lý",
style: TextStyle(
fontSize: 14.0, color: Colors.black87)))),
Icon(
Icons.arrow_drop_down,
color: Colors.grey,
),
],
)));
});
}

Widget _dropdownUnitTypes() {
return GetBuilder<ChangeUnit>(builder: (data) {
return DropdownButtonFormField<String>(
itemHeight: 100,
value: data.selectedUnit.isEmpty ? null : data.selectedUnit,
items: data.currentUnits
.map((label) => DropdownMenuItem(
child: Text(label),
value: label,
))
.toList(),
onChanged: (value) {
var currentQuantity = _quantityController.text;
changeQuantity.changeQuantity(currentQuantity);
num assignValue = changeQuantity.quantity.parseDoubleThousand();
if (assignValue != null) {
var oldSelected = data.selectedUnit;
if (oldSelected == value) {
} else {
assignValue = UtilAction.convertUnit(
inputValue: assignValue,
oldUnit: oldSelected,
newUnit: value);
}
changeQuantity
.changeQuantity(assignValue.formatNumtoStringDecimal());
}
changeUnit.updateSelected(value);
},
);
});
}

_quantityField() {
return GetBuilder<ChangeValueQuantity>(builder: (_) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
var quantityValue = changeQuantity.quantity;
_quantityController.text = quantityValue;
});

return TextFormField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: [
ThousandsFormatter(
formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
],
decoration: InputDecoration(labelText: "Tổng lượng sử dụng"),
controller: _quantityController,
);
});
}

_buttonInForm() {
return GetBuilder<ChangeButtonInForm>(builder: (_) {
return Align(
alignment: Alignment.centerRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_.isEdit
? OutlineButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
child: Text("Huỷ"),
onPressed: () {
changeButton.resetValue();
_resetForm();
_hidenKeyboard(context);
})
: SizedBox(),
_.isEdit
? FlatButton(
color: COLOR_CONST.DEFAULT,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
var currentSupply = changeSelectedSupply.currentSupply;
changeQuantity.changeQuantity(_quantityController.text);
var quantityWithCurrentSupplyUnit =
UtilAction.convertUnit(
inputValue:
changeQuantity.quantity.parseDoubleThousand(),
oldUnit: changeUnit.selectedUnit,
newUnit: changeSelectedSupply.currentSupply.unit);
if (currentSupply.id != null) {
SuppliesUsing newSup = SuppliesUsing()
..dosage = _dosageController.text
..quantity = quantityWithCurrentSupplyUnit
..tbSuppliesInWarehouseId = currentSupply.id
..suppliesInWarehouseId = currentSupply.id
..supplyName = currentSupply.tbSuppliesName
..supplyUnit = currentSupply.unit
..unit = currentSupply.unit;
changeSupplyUsing.editSupply(
changeSupplyUsing.currentIndex, newSup);
_resetForm();
_hidenKeyboard(context);
}
},
child: Text(
"Sửa",
style: TextStyle(color: Colors.white),
))
: FlatButton(
color: COLOR_CONST.DEFAULT,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0)),
onPressed: () {
var currentSupply = changeSelectedSupply.currentSupply;
if (currentSupply.id != null) {
changeQuantity.changeQuantity(_quantityController.text);
var quantityWithCurrentSupplyUnit =
UtilAction.convertUnit(
inputValue: changeQuantity.quantity
.parseDoubleThousand(),
oldUnit: changeUnit.selectedUnit,
newUnit:
changeSelectedSupply.currentSupply.unit);
SuppliesUsing newSup = SuppliesUsing()
..dosage = _dosageController.text
..quantity = quantityWithCurrentSupplyUnit
..tbSuppliesInWarehouseId = currentSupply.id
..suppliesInWarehouseId = currentSupply.id
..supplyName = currentSupply.tbSuppliesName
..supplyUnit = currentSupply.unit
..unit = currentSupply.unit;
changeSupplyUsing.addSupply(newSup);
_resetForm();
_hidenKeyboard(context);
}
},
child: Text(
"Thêm",
style: TextStyle(color: Colors.white),
))
],
),
);
});
}

Widget _formEdit() {
return Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10),
color: Colors.white,
border: Border.all(color: COLOR_CONST.DEFAULT)),
child: Column(
children: [
Container(
width: double.infinity,
child: Text(
"Hoá chất xử lý",
style: TextStyle(color: Colors.black54, fontSize: 13.0),
),
),
_btnSelectSubstrates(),
TextFormField(
keyboardType: TextInputType.text,
controller: _dosageController,
decoration: InputDecoration(labelText: "Liều lượng"),
onSaved: (newValue) {},
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: Container(
height: 70,
child: _quantityField(),
),
),
SizedBox(
width: 16.0,
),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomCenter,
child: _dropdownUnitTypes(),
)),
]),
_buttonInForm()
],
));
}

_resetForm() {
changeSupplyUsing.changeIndexEdit(-1);
changeButton.resetValue();
_dosageController.text = "";
_quantityController.text = "";
changeUnit.initValue();
changeSelectedSupply.initValue();
changeQuantity.changeQuantity("");
}

_hidenKeyboard(BuildContext context) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
}

@override
Widget build(BuildContext context) {
return Column(
children: [_formEdit(), _buildListSupply()],
);
}
}

class ChangeUnit extends GetxController {
List<String> currentUnits;
String selectedUnit;

initValue() {
currentUnits = [];
selectedUnit = "";
update();
}

updateListByUnitName(String unitName) {
if (unitName == "kg" || unitName == "g") {
currentUnits = ["kg", "g"];
selectedUnit = unitName;
} else if (unitName == "l" || unitName == "m") {
currentUnits = ["l", "ml"];
selectedUnit = unitName;
} else if (unitName == "m" || unitName == "cm" || unitName == "mm") {
currentUnits = ["m", "cm", "mm"];
selectedUnit = unitName;
} else {
currentUnits = [];
}
update();
}

updateSelected(String selected) {
selectedUnit = selected;
update();
}
}

class ChangeValueQuantity extends GetxController {
String quantity = "";
void changeQuantity(String newQuantity) {
quantity = newQuantity;
update();
}
}

class ChangeButtonInForm extends GetxController {
bool isEdit;
void resetValue() {
isEdit = false;
update();
}

void updateToEdit(bool isChangeEdit) {
isEdit = isChangeEdit;
update();
}
}

class ChangeSupplyUsing extends GetxController {
List<SuppliesUsing> currentItems;
SuppliesUsing currentSupplyUsing;
int currentIndex;
void init(List<SuppliesUsing> initItems) {
currentItems = initItems;
currentSupplyUsing = SuppliesUsing();
currentIndex = -1;
update();
}

void changeIndexEdit(int index) {
currentIndex = index;
update();
}

void changeInitList(List<SuppliesUsing> sups) {
currentItems = sups;
update();
}

void addSupply(SuppliesUsing supplyUsing) {
currentItems.insert(0, supplyUsing);
currentSupplyUsing = SuppliesUsing();
update();
}

void deleteSupply(int index) {
currentItems.removeAt(index);
currentSupplyUsing = SuppliesUsing();
update();
}

void editSupply(int index, SuppliesUsing supplyUsing) {
currentItems[index] = supplyUsing;
currentSupplyUsing = SuppliesUsing();
update();
}
}

+ 6
- 1
lib/presentation/screens/actions/state_management_helper/change_supply.dart View File

Supply currentSupply; Supply currentSupply;
int selectedSupplyId; int selectedSupplyId;
String selectedSupplyName; String selectedSupplyName;
String unit;


void initValue() { void initValue() {
currentSupply = Supply(); currentSupply = Supply();
selectedSupplyName = "";
selectedSupplyId = -1; selectedSupplyId = -1;
unit = "";
update(); update();
} }


currentSupply = supply; currentSupply = supply;
selectedSupplyId = supply.id; selectedSupplyId = supply.id;
selectedSupplyName = supply.tbSuppliesName; selectedSupplyName = supply.tbSuppliesName;
unit = supply.unit;
update(); update();
} }


void changeByIdAndName(int supplyId, String supplyName) {
void changeByIdAndName(int supplyId, String supplyName, {String unitName}) {
selectedSupplyId = supplyId; selectedSupplyId = supplyId;
selectedSupplyName = supplyName; selectedSupplyName = supplyName;
unit = unitName;
update(); update();
} }
} }

+ 31
- 0
lib/presentation/screens/actions/util_action.dart View File

} }
return medias; return medias;
} }

static num convertUnit({num inputValue, String oldUnit, String newUnit}) {
num result = inputValue;
if (newUnit.isEmpty || newUnit == oldUnit) {
return result;
}
if (oldUnit == "kg" || oldUnit == "l") {
result = result * 1000;
} else if (oldUnit == "g" || oldUnit == "ml") {
result = result / 1000;
} else if (oldUnit == "m") {
if (newUnit == "cm") {
result = result * 100;
} else if (newUnit == "mm") {
result = result * 1000;
}
} else if (oldUnit == "cm") {
if (newUnit == "m") {
result = result / 100;
} else if (newUnit == "mm") {
result = result * 10;
}
} else if (oldUnit == "mm") {
if (newUnit == "m") {
result = result / 1000;
} else if (newUnit == "cm") {
result = result / 10;
}
}
return result;
}
} }

Loading…
Cancel
Save