| /Users/daivph/fvm/versions/3.0.5 |
| { | |||||
| "flutterSdkVersion": "3.0.5", | |||||
| "flavors": {} | |||||
| } |
| { | |||||
| "dart.flutterSdkPath": "/Users/daivph/fvm/versions/3.0.5" | |||||
| } |
| } | } | ||||
| android { | android { | ||||
| compileSdkVersion 29 | |||||
| compileSdkVersion 33 | |||||
| sourceSets { | sourceSets { | ||||
| main.java.srcDirs += 'src/main/kotlin' | main.java.srcDirs += 'src/main/kotlin' | ||||
| // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). | ||||
| applicationId "vn.azteam.tpfarm" | applicationId "vn.azteam.tpfarm" | ||||
| minSdkVersion 21 | minSdkVersion 21 | ||||
| targetSdkVersion 29 | |||||
| targetSdkVersion 33 | |||||
| versionCode flutterVersionCode.toInteger() | versionCode flutterVersionCode.toInteger() | ||||
| versionName flutterVersionName | versionName flutterVersionName | ||||
| } | } |
| class App extends StatelessWidget { | class App extends StatelessWidget { | ||||
| const App({ | const App({ | ||||
| Key key, | |||||
| @required this.authenticationRepository, | |||||
| Key? key, | |||||
| required this.authenticationRepository, | |||||
| }) : assert(authenticationRepository != null), | }) : assert(authenticationRepository != null), | ||||
| super(key: key); | super(key: key); | ||||
| value: authenticationRepository, | value: authenticationRepository, | ||||
| child: BlocProvider( | child: BlocProvider( | ||||
| create: (_) => AuthenticationBloc( | create: (_) => AuthenticationBloc( | ||||
| authenticationRepository: authenticationRepository, | |||||
| repository: authenticationRepository, | |||||
| ), | ), | ||||
| child: AppView(), | child: AppView(), | ||||
| ), | ), | ||||
| class _AppViewState extends State<AppView> { | class _AppViewState extends State<AppView> { | ||||
| final _navigatorKey = GlobalKey<NavigatorState>(); | final _navigatorKey = GlobalKey<NavigatorState>(); | ||||
| NavigatorState get _navigator => _navigatorKey.currentState; | |||||
| NavigatorState get _navigator => _navigatorKey.currentState!; | |||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { |
| part 'authentication_event.dart'; | part 'authentication_event.dart'; | ||||
| part 'authentication_state.dart'; | part 'authentication_state.dart'; | ||||
| class AuthenticationBloc | |||||
| extends Bloc<AuthenticationEvent, AuthenticationState> { | |||||
| AuthenticationBloc( | |||||
| {@required AuthenticationRepository authenticationRepository}) | |||||
| : assert(authenticationRepository != null), | |||||
| _authenticationRepository = authenticationRepository, | |||||
| super(const AuthenticationState.unknown()) { | |||||
| _authenticationStatusSubscription = _authenticationRepository.status.listen( | |||||
| (status) => add(AuthenticationStatusChanged(status)), | |||||
| ); | |||||
| } | |||||
| class AuthenticationBloc extends Bloc<AuthenticationEvent, AuthenticationState> { | |||||
| AuthenticationBloc({required AuthenticationRepository repository}) | |||||
| : _authenticationRepository = repository, | |||||
| super(const AuthenticationState.unknown()) {} | |||||
| final AuthenticationRepository _authenticationRepository; | final AuthenticationRepository _authenticationRepository; | ||||
| StreamSubscription<AuthenticationStatus> _authenticationStatusSubscription; | |||||
| StreamSubscription<AuthenticationStatus>? _authenticationStatusSubscription; | |||||
| @override | @override | ||||
| Stream<AuthenticationState> mapEventToState( | Stream<AuthenticationState> mapEventToState( | ||||
| case AuthenticationStatus.unauthenticated: | case AuthenticationStatus.unauthenticated: | ||||
| return const AuthenticationState.unauthenticated(); | return const AuthenticationState.unauthenticated(); | ||||
| case AuthenticationStatus.authenticated: | case AuthenticationStatus.authenticated: | ||||
| return AuthenticationState.authenticated(); | |||||
| return const AuthenticationState.authenticated(); | |||||
| default: | default: | ||||
| return const AuthenticationState.unknown(); | return const AuthenticationState.unknown(); | ||||
| } | } |
| class ActionEnd { | class ActionEnd { | ||||
| int id; | |||||
| int activityId; | |||||
| String executeDate; | |||||
| String description; | |||||
| int? id; | |||||
| int? activityId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| ActionEnd({this.id, this.activityId, this.executeDate, this.description}); | ActionEnd({this.id, this.activityId, this.executeDate, this.description}); | ||||
| class CropPlot { | class CropPlot { | ||||
| TbCropDTO tbCropDTO; | |||||
| List<Activities> activities; | |||||
| String sowingDate; | |||||
| int soakSeedsTime; | |||||
| int seedIncubationTime; | |||||
| int numberPlants; | |||||
| int numberCurrentPlants; | |||||
| String endOfFarmingDate; | |||||
| TbCropDTO? tbCropDTO; | |||||
| List<Activities>? activities; | |||||
| String? sowingDate; | |||||
| int? soakSeedsTime; | |||||
| int? seedIncubationTime; | |||||
| int? numberPlants; | |||||
| int? numberCurrentPlants; | |||||
| String? endOfFarmingDate; | |||||
| CropPlot( | CropPlot( | ||||
| {this.tbCropDTO, | {this.tbCropDTO, | ||||
| this.endOfFarmingDate}); | this.endOfFarmingDate}); | ||||
| CropPlot.fromJson(Map<String, dynamic> json) { | CropPlot.fromJson(Map<String, dynamic> json) { | ||||
| tbCropDTO = json['tbCropDTO'] != null | |||||
| ? new TbCropDTO.fromJson(json['tbCropDTO']) | |||||
| : null; | |||||
| tbCropDTO = json['tbCropDTO'] != null ? TbCropDTO.fromJson(json['tbCropDTO']) : null; | |||||
| if (json['activities'] != null) { | if (json['activities'] != null) { | ||||
| activities = new List<Activities>(); | |||||
| activities = <Activities>[]; | |||||
| json['activities'].forEach((v) { | json['activities'].forEach((v) { | ||||
| activities.add(new Activities.fromJson(v)); | |||||
| activities?.add(Activities.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| sowingDate = json['sowingDate']; | sowingDate = json['sowingDate']; | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| if (this.tbCropDTO != null) { | |||||
| data['tbCropDTO'] = this.tbCropDTO.toJson(); | |||||
| final data = <String, dynamic>{}; | |||||
| if (tbCropDTO != null) { | |||||
| data['tbCropDTO'] = tbCropDTO?.toJson(); | |||||
| } | } | ||||
| if (this.activities != null) { | |||||
| data['activities'] = this.activities.map((v) => v.toJson()).toList(); | |||||
| if (activities != null) { | |||||
| data['activities'] = activities?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| data['sowingDate'] = this.sowingDate; | |||||
| data['soakSeedsTime'] = this.soakSeedsTime; | |||||
| data['seedIncubationTime'] = this.seedIncubationTime; | |||||
| data['numberPlants'] = this.numberPlants; | |||||
| data['numberCurrentPlants'] = this.numberCurrentPlants; | |||||
| data['endOfFarmingDate'] = this.endOfFarmingDate; | |||||
| data['sowingDate'] = sowingDate; | |||||
| data['soakSeedsTime'] = soakSeedsTime; | |||||
| data['seedIncubationTime'] = seedIncubationTime; | |||||
| data['numberPlants'] = numberPlants; | |||||
| data['numberCurrentPlants'] = numberCurrentPlants; | |||||
| data['endOfFarmingDate'] = endOfFarmingDate; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } | ||||
| class TbCropDTO { | class TbCropDTO { | ||||
| int id; | |||||
| String qrCode; | |||||
| String code; | |||||
| num areaM2; | |||||
| int type; | |||||
| String startDate; | |||||
| String endDate; | |||||
| String status; | |||||
| String description; | |||||
| int ageDayStartAt; | |||||
| int tbSuppliesId; | |||||
| String suppliesName; | |||||
| int tbGuidelineId; | |||||
| int netHouseId; | |||||
| String netHouseName; | |||||
| int areaId; | |||||
| String area; | |||||
| List<TbDetailUsers> tbDetailUsers; | |||||
| int? id; | |||||
| String? qrCode; | |||||
| String? code; | |||||
| num? areaM2; | |||||
| int? type; | |||||
| String? startDate; | |||||
| String? endDate; | |||||
| String? status; | |||||
| String? description; | |||||
| int? ageDayStartAt; | |||||
| int? tbSuppliesId; | |||||
| String? suppliesName; | |||||
| int? tbGuidelineId; | |||||
| int? netHouseId; | |||||
| String? netHouseName; | |||||
| int? areaId; | |||||
| String? area; | |||||
| List<TbDetailUsers>? tbDetailUsers; | |||||
| TbCropDTO( | TbCropDTO( | ||||
| {this.id, | {this.id, | ||||
| areaId = json['areaId']; | areaId = json['areaId']; | ||||
| area = json['area']; | area = json['area']; | ||||
| if (json['tbDetailUsers'] != null) { | if (json['tbDetailUsers'] != null) { | ||||
| tbDetailUsers = new List<TbDetailUsers>(); | |||||
| tbDetailUsers = <TbDetailUsers>[]; | |||||
| json['tbDetailUsers'].forEach((v) { | json['tbDetailUsers'].forEach((v) { | ||||
| tbDetailUsers.add(new TbDetailUsers.fromJson(v)); | |||||
| tbDetailUsers?.add(TbDetailUsers.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['qrCode'] = this.qrCode; | |||||
| data['code'] = this.code; | |||||
| data['areaM2'] = this.areaM2; | |||||
| data['type'] = this.type; | |||||
| data['startDate'] = this.startDate; | |||||
| data['endDate'] = this.endDate; | |||||
| data['status'] = this.status; | |||||
| data['description'] = this.description; | |||||
| data['ageDayStartAt'] = this.ageDayStartAt; | |||||
| data['tbSuppliesId'] = this.tbSuppliesId; | |||||
| data['suppliesName'] = this.suppliesName; | |||||
| data['tbGuidelineId'] = this.tbGuidelineId; | |||||
| data['netHouseId'] = this.netHouseId; | |||||
| data['netHouseName'] = this.netHouseName; | |||||
| data['areaId'] = this.areaId; | |||||
| data['area'] = this.area; | |||||
| if (this.tbDetailUsers != null) { | |||||
| data['tbDetailUsers'] = | |||||
| this.tbDetailUsers.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['qrCode'] = qrCode; | |||||
| data['code'] = code; | |||||
| data['areaM2'] = areaM2; | |||||
| data['type'] = type; | |||||
| data['startDate'] = startDate; | |||||
| data['endDate'] = endDate; | |||||
| data['status'] = status; | |||||
| data['description'] = description; | |||||
| data['ageDayStartAt'] = ageDayStartAt; | |||||
| data['tbSuppliesId'] = tbSuppliesId; | |||||
| data['suppliesName'] = suppliesName; | |||||
| data['tbGuidelineId'] = tbGuidelineId; | |||||
| data['netHouseId'] = netHouseId; | |||||
| data['netHouseName'] = netHouseName; | |||||
| data['areaId'] = areaId; | |||||
| data['area'] = area; | |||||
| if (tbDetailUsers != null) { | |||||
| data['tbDetailUsers'] = tbDetailUsers?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } | ||||
| } | } | ||||
| class TbDetailUsers { | class TbDetailUsers { | ||||
| int id; | |||||
| String fullName; | |||||
| String phone; | |||||
| int? id; | |||||
| String? fullName; | |||||
| String? phone; | |||||
| TbDetailUsers({this.id, this.fullName, this.phone}); | TbDetailUsers({this.id, this.fullName, this.phone}); | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['fullName'] = this.fullName; | |||||
| data['phone'] = this.phone; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['fullName'] = fullName; | |||||
| data['phone'] = phone; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } | ||||
| class Activities { | class Activities { | ||||
| int id; | |||||
| int ageDay; | |||||
| int cropId; | |||||
| String executeDate; | |||||
| String description; | |||||
| int activityTypeId; | |||||
| String activityTypeName; | |||||
| String activityTypeDescription; | |||||
| int? id; | |||||
| int? ageDay; | |||||
| int? cropId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| int? activityTypeId; | |||||
| String? activityTypeName; | |||||
| String? activityTypeDescription; | |||||
| Activities( | Activities( | ||||
| {this.id, | {this.id, | ||||
| this.activityTypeDescription}); | this.activityTypeDescription}); | ||||
| Activities.clone(Activities activities) { | Activities.clone(Activities activities) { | ||||
| this.id = activities.id; | |||||
| this.cropId = activities.cropId; | |||||
| this.activityTypeName = activities.activityTypeName; | |||||
| this.activityTypeDescription = activities.activityTypeDescription; | |||||
| this.executeDate = activities.executeDate; | |||||
| id = activities.id; | |||||
| cropId = activities.cropId; | |||||
| activityTypeName = activities.activityTypeName; | |||||
| activityTypeDescription = activities.activityTypeDescription; | |||||
| executeDate = activities.executeDate; | |||||
| } | } | ||||
| Activities.fromJson(Map<String, dynamic> json) { | Activities.fromJson(Map<String, dynamic> json) { | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['ageDay'] = this.ageDay; | |||||
| data['cropId'] = this.cropId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['activityTypeId'] = this.activityTypeId; | |||||
| data['activityTypeName'] = this.activityTypeName; | |||||
| data['activityTypeDescription'] = this.activityTypeDescription; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['ageDay'] = ageDay; | |||||
| data['cropId'] = cropId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['activityTypeId'] = activityTypeId; | |||||
| data['activityTypeName'] = activityTypeName; | |||||
| data['activityTypeDescription'] = activityTypeDescription; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class CropStatus { | class CropStatus { | ||||
| int id; | |||||
| int cropId; | |||||
| int activityId; | |||||
| String executeDate; | |||||
| String cropRate; | |||||
| String numberOfTreeToGrow; | |||||
| String heightOfTree; | |||||
| String numberOfLeaf; | |||||
| String leafSize; | |||||
| String leafColor; | |||||
| String abilityProduceBuds; | |||||
| String internodeLength; | |||||
| String description; | |||||
| String executeBy; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| int? id; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| String? executeDate; | |||||
| String? cropRate; | |||||
| String? numberOfTreeToGrow; | |||||
| String? heightOfTree; | |||||
| String? numberOfLeaf; | |||||
| String? leafSize; | |||||
| String? leafColor; | |||||
| String? abilityProduceBuds; | |||||
| String? internodeLength; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| CropStatus( | CropStatus( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['cropRate'] = this.cropRate; | |||||
| data['numberOfTreeToGrow'] = this.numberOfTreeToGrow; | |||||
| data['heightOfTree'] = this.heightOfTree; | |||||
| data['numberOfLeaf'] = this.numberOfLeaf; | |||||
| data['leafSize'] = this.leafSize; | |||||
| data['leafColor'] = this.leafColor; | |||||
| data['abilityProduceBuds'] = this.abilityProduceBuds; | |||||
| data['internodeLength'] = this.internodeLength; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['cropRate'] = cropRate; | |||||
| data['numberOfTreeToGrow'] = numberOfTreeToGrow; | |||||
| data['heightOfTree'] = heightOfTree; | |||||
| data['numberOfLeaf'] = numberOfLeaf; | |||||
| data['leafSize'] = leafSize; | |||||
| data['leafColor'] = leafColor; | |||||
| data['abilityProduceBuds'] = abilityProduceBuds; | |||||
| data['internodeLength'] = internodeLength; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Device { | class Device { | ||||
| int id; | |||||
| String name; | |||||
| String status; | |||||
| String location; | |||||
| num mode; | |||||
| bool isSelected; | |||||
| int? id; | |||||
| String? name; | |||||
| String? status; | |||||
| String? location; | |||||
| num? mode; | |||||
| bool? isSelected; | |||||
| Device({this.id, this.name, this.status, this.location, this.mode}); | Device({this.id, this.name, this.status, this.location, this.mode}); | ||||
| Device.clone(Device device) { | Device.clone(Device device) { | ||||
| this.id = device.id; | |||||
| this.name = device.name; | |||||
| this.status = device.status; | |||||
| this.location = device.location; | |||||
| this.mode = device.mode; | |||||
| id = device.id; | |||||
| name = device.name; | |||||
| status = device.status; | |||||
| location = device.location; | |||||
| mode = device.mode; | |||||
| } | } | ||||
| Device.fromJson(Map<String, dynamic> json) { | Device.fromJson(Map<String, dynamic> json) { | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['name'] = this.name; | |||||
| data['status'] = this.status; | |||||
| data['location'] = this.location; | |||||
| data['mode'] = this.mode; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['name'] = name; | |||||
| data['status'] = status; | |||||
| data['location'] = location; | |||||
| data['mode'] = mode; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Disease { | class Disease { | ||||
| int id; | |||||
| int activityId; | |||||
| int cropId; | |||||
| String executeDate; | |||||
| String media; | |||||
| String typesOfPest; | |||||
| String harmLevel; | |||||
| String treePercent; | |||||
| String location; | |||||
| String naturalEnemy; | |||||
| String treatmentMeasures; | |||||
| String description; | |||||
| String executeBy; | |||||
| int? id; | |||||
| int? activityId; | |||||
| int? cropId; | |||||
| String? executeDate; | |||||
| String? media; | |||||
| String? typesOfPest; | |||||
| String? harmLevel; | |||||
| String? treePercent; | |||||
| String? location; | |||||
| String? naturalEnemy; | |||||
| String? treatmentMeasures; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| Disease( | Disease( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['activityId'] = this.activityId; | |||||
| data['cropId'] = this.cropId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['media'] = this.media; | |||||
| data['typesOfPest'] = this.typesOfPest; | |||||
| data['harmLevel'] = this.harmLevel; | |||||
| data['treePercent'] = this.treePercent; | |||||
| data['location'] = this.location; | |||||
| data['naturalEnemy'] = this.naturalEnemy; | |||||
| data['treatmentMeasures'] = this.treatmentMeasures; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['activityId'] = activityId; | |||||
| data['cropId'] = cropId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['media'] = media; | |||||
| data['typesOfPest'] = typesOfPest; | |||||
| data['harmLevel'] = harmLevel; | |||||
| data['treePercent'] = treePercent; | |||||
| data['location'] = location; | |||||
| data['naturalEnemy'] = naturalEnemy; | |||||
| data['treatmentMeasures'] = treatmentMeasures; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| import 'SuppliesUsing.dart'; | import 'SuppliesUsing.dart'; | ||||
| class Dung { | class Dung { | ||||
| int id; | |||||
| int activityId; | |||||
| int cropId; | |||||
| String executeDate; | |||||
| String description; | |||||
| String media; | |||||
| num quarantinePeriod; | |||||
| String weatherConditions; | |||||
| String purpose; | |||||
| String executeBy; | |||||
| List<String> mediaDel; | |||||
| List<SuppliesUsing> suppliesUsing; | |||||
| int? id; | |||||
| int? activityId; | |||||
| int? cropId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? media; | |||||
| num? quarantinePeriod; | |||||
| String? weatherConditions; | |||||
| String? purpose; | |||||
| String? executeBy; | |||||
| List<String>? mediaDel; | |||||
| List<SuppliesUsing>? suppliesUsing; | |||||
| Dung( | Dung( | ||||
| {this.id, | {this.id, | ||||
| purpose = json['purpose']; | purpose = json['purpose']; | ||||
| executeBy = json['executeBy']; | executeBy = json['executeBy']; | ||||
| if (json['suppliesUsing'] != null) { | if (json['suppliesUsing'] != null) { | ||||
| suppliesUsing = new List<SuppliesUsing>(); | |||||
| suppliesUsing = <SuppliesUsing>[]; | |||||
| json['suppliesUsing'].forEach((v) { | json['suppliesUsing'].forEach((v) { | ||||
| suppliesUsing.add(new SuppliesUsing.fromJson(v)); | |||||
| suppliesUsing?.add(SuppliesUsing.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['media'] = this.media; | |||||
| data['quarantinePeriod'] = this.quarantinePeriod; | |||||
| data['weatherConditions'] = this.weatherConditions; | |||||
| data['purpose'] = this.purpose; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['media_del'] = this.mediaDel; | |||||
| if (this.suppliesUsing != null) { | |||||
| data['suppliesUsing'] = | |||||
| this.suppliesUsing.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['media'] = media; | |||||
| data['quarantinePeriod'] = quarantinePeriod; | |||||
| data['weatherConditions'] = weatherConditions; | |||||
| data['purpose'] = purpose; | |||||
| data['executeBy'] = executeBy; | |||||
| data['media_del'] = mediaDel; | |||||
| if (suppliesUsing != null) { | |||||
| data['suppliesUsing'] = suppliesUsing?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } |
| class End { | class End { | ||||
| int id; | |||||
| int cropId; | |||||
| int activityId; | |||||
| String executeDate; | |||||
| String description; | |||||
| String createdByName; | |||||
| List<String> mediaDel; | |||||
| String media; | |||||
| int? id; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? createdByName; | |||||
| List<String>? mediaDel; | |||||
| String? media; | |||||
| End( | |||||
| {this.id, | |||||
| this.cropId, | |||||
| this.activityId, | |||||
| this.executeDate, | |||||
| this.description, | |||||
| this.createdByName, | |||||
| this.mediaDel, | |||||
| this.media}); | |||||
| End({this.id, this.cropId, this.activityId, this.executeDate, this.description, this.createdByName, this.mediaDel, this.media}); | |||||
| End.fromJson(Map<String, dynamic> json) { | End.fromJson(Map<String, dynamic> json) { | ||||
| id = json['id']; | id = json['id']; | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['createdByName'] = this.createdByName; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['createdByName'] = createdByName; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Environment { | class Environment { | ||||
| int id; | |||||
| int activityId; | |||||
| int cropId; | |||||
| String executeDate; | |||||
| String media; | |||||
| String description; | |||||
| String executeBy; | |||||
| String pH; | |||||
| String ec; | |||||
| String ocdd; | |||||
| String temperature; | |||||
| String dodo; | |||||
| String lln; | |||||
| List<EnvironmentUpdates> environmentUpdates; | |||||
| int? id; | |||||
| int? activityId; | |||||
| int? cropId; | |||||
| String? executeDate; | |||||
| String? media; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| String? pH; | |||||
| String? ec; | |||||
| String? ocdd; | |||||
| String? temperature; | |||||
| String? dodo; | |||||
| String? lln; | |||||
| List<EnvironmentUpdates>? environmentUpdates; | |||||
| Environment( | Environment( | ||||
| {this.id, | {this.id, | ||||
| dodo = json['dodo']; | dodo = json['dodo']; | ||||
| lln = json['lln']; | lln = json['lln']; | ||||
| if (json['environmentUpdates'] != null) { | if (json['environmentUpdates'] != null) { | ||||
| environmentUpdates = new List<EnvironmentUpdates>(); | |||||
| environmentUpdates = <EnvironmentUpdates>[]; | |||||
| json['environmentUpdates'].forEach((v) { | json['environmentUpdates'].forEach((v) { | ||||
| environmentUpdates.add(new EnvironmentUpdates.fromJson(v)); | |||||
| environmentUpdates?.add(EnvironmentUpdates.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['activityId'] = this.activityId; | |||||
| data['cropId'] = this.cropId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['media'] = this.media; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['pH'] = this.pH; | |||||
| data['ec'] = this.ec; | |||||
| data['ocdd'] = this.ocdd; | |||||
| data['temperature'] = this.temperature; | |||||
| data['dodo'] = this.dodo; | |||||
| data['lln'] = this.lln; | |||||
| if (this.environmentUpdates != null) { | |||||
| data['environmentUpdates'] = | |||||
| this.environmentUpdates.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['activityId'] = activityId; | |||||
| data['cropId'] = cropId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['media'] = media; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| data['pH'] = pH; | |||||
| data['ec'] = ec; | |||||
| data['ocdd'] = ocdd; | |||||
| data['temperature'] = temperature; | |||||
| data['dodo'] = dodo; | |||||
| data['lln'] = lln; | |||||
| if (environmentUpdates != null) { | |||||
| data['environmentUpdates'] = environmentUpdates?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } | ||||
| } | } | ||||
| class EnvironmentUpdates { | class EnvironmentUpdates { | ||||
| int id; | |||||
| num index; | |||||
| num times; | |||||
| int tbEnvironmentalId; | |||||
| String tbEnvironmentalName; | |||||
| String tbEnvironmentalUnit; | |||||
| String tbEnvironmentalDescription; | |||||
| int tbActivityId; | |||||
| num tbEquipmentOfCustomerId; | |||||
| int? id; | |||||
| num? index; | |||||
| num? times; | |||||
| int? tbEnvironmentalId; | |||||
| String? tbEnvironmentalName; | |||||
| String? tbEnvironmentalUnit; | |||||
| String? tbEnvironmentalDescription; | |||||
| int? tbActivityId; | |||||
| num? tbEquipmentOfCustomerId; | |||||
| EnvironmentUpdates( | EnvironmentUpdates( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['index'] = this.index; | |||||
| data['times'] = this.times; | |||||
| data['tbEnvironmentalId'] = this.tbEnvironmentalId; | |||||
| data['tbEnvironmentalName'] = this.tbEnvironmentalName; | |||||
| data['tbEnvironmentalUnit'] = this.tbEnvironmentalUnit; | |||||
| data['tbEnvironmentalDescription'] = this.tbEnvironmentalDescription; | |||||
| data['tbActivityId'] = this.tbActivityId; | |||||
| data['tbEquipmentOfCustomerId'] = this.tbEquipmentOfCustomerId; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['index'] = index; | |||||
| data['times'] = times; | |||||
| data['tbEnvironmentalId'] = tbEnvironmentalId; | |||||
| data['tbEnvironmentalName'] = tbEnvironmentalName; | |||||
| data['tbEnvironmentalUnit'] = tbEnvironmentalUnit; | |||||
| data['tbEnvironmentalDescription'] = tbEnvironmentalDescription; | |||||
| data['tbActivityId'] = tbActivityId; | |||||
| data['tbEquipmentOfCustomerId'] = tbEquipmentOfCustomerId; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class EnvironmentParameter { | class EnvironmentParameter { | ||||
| int id; | |||||
| String name; | |||||
| num index; | |||||
| int activityId; | |||||
| String executeDate; | |||||
| bool status; | |||||
| int? id; | |||||
| String? name; | |||||
| num? index; | |||||
| int? activityId; | |||||
| String? executeDate; | |||||
| bool? status; | |||||
| EnvironmentParameter( | |||||
| {this.id, | |||||
| this.name, | |||||
| this.index, | |||||
| this.activityId, | |||||
| this.executeDate, | |||||
| this.status}); | |||||
| EnvironmentParameter({this.id, this.name, this.index, this.activityId, this.executeDate, this.status}); | |||||
| EnvironmentParameter.clone(EnvironmentParameter e) { | EnvironmentParameter.clone(EnvironmentParameter e) { | ||||
| this.id = e.id; | |||||
| this.name = e.name; | |||||
| this.index = e.index; | |||||
| this.activityId = e.activityId; | |||||
| this.executeDate = e.executeDate; | |||||
| this.status = e.status; | |||||
| id = e.id; | |||||
| name = e.name; | |||||
| index = e.index; | |||||
| activityId = e.activityId; | |||||
| executeDate = e.executeDate; | |||||
| status = e.status; | |||||
| } | } | ||||
| EnvironmentParameter.fromJson(Map<String, dynamic> json) { | EnvironmentParameter.fromJson(Map<String, dynamic> json) { | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['name'] = this.name; | |||||
| data['index'] = this.index; | |||||
| data['activityId'] = this.activityId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['status'] = this.status; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['name'] = name; | |||||
| data['index'] = index; | |||||
| data['activityId'] = activityId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['status'] = status; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class ErrorCommon { | class ErrorCommon { | ||||
| String entityName; | |||||
| String errorKey; | |||||
| int status; | |||||
| String? entityName; | |||||
| String? errorKey; | |||||
| int? status; | |||||
| ErrorCommon({this.entityName, this.errorKey, this.status}); | ErrorCommon({this.entityName, this.errorKey, this.status}); | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['entityName'] = this.entityName; | |||||
| data['errorKey'] = this.errorKey; | |||||
| data['status'] = this.status; | |||||
| final data = <String, dynamic>{}; | |||||
| data['entityName'] = entityName; | |||||
| data['errorKey'] = errorKey; | |||||
| data['status'] = status; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Harvest { | class Harvest { | ||||
| int id; | |||||
| int cropId; | |||||
| int activityId; | |||||
| String executeDate; | |||||
| String description; | |||||
| String executeBy; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| num collectedQuantityLv1; | |||||
| num collectedQuantityLv2; | |||||
| num collectedQuantityLv3; | |||||
| num removedQuantity; | |||||
| int? id; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| num? collectedQuantityLv1; | |||||
| num? collectedQuantityLv2; | |||||
| num? collectedQuantityLv3; | |||||
| num? removedQuantity; | |||||
| Harvest( | Harvest( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| data['collectedQuantityLv1'] = this.collectedQuantityLv1; | |||||
| data['collectedQuantityLv2'] = this.collectedQuantityLv2; | |||||
| data['collectedQuantityLv3'] = this.collectedQuantityLv3; | |||||
| data['removedQuantity'] = this.removedQuantity; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| data['collectedQuantityLv1'] = collectedQuantityLv1; | |||||
| data['collectedQuantityLv2'] = collectedQuantityLv2; | |||||
| data['collectedQuantityLv3'] = collectedQuantityLv3; | |||||
| data['removedQuantity'] = removedQuantity; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| import 'SuppliesUsing.dart'; | import 'SuppliesUsing.dart'; | ||||
| class HarvestProcess { | class HarvestProcess { | ||||
| int id; | |||||
| int cropId; | |||||
| int activityId; | |||||
| int harvestId; | |||||
| String executeDate; | |||||
| String description; | |||||
| String executeBy; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| num quantityLv1; | |||||
| num quantityLv2; | |||||
| num quantityLv3; | |||||
| num removedQuantity; | |||||
| List<SuppliesUsing> suppliesUsing; | |||||
| int? id; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| int? harvestId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| num? quantityLv1; | |||||
| num? quantityLv2; | |||||
| num? quantityLv3; | |||||
| num? removedQuantity; | |||||
| List<SuppliesUsing>? suppliesUsing; | |||||
| HarvestProcess( | HarvestProcess( | ||||
| {this.id, | {this.id, | ||||
| quantityLv3 = json['quantityLv3']; | quantityLv3 = json['quantityLv3']; | ||||
| removedQuantity = json['removedQuantity']; | removedQuantity = json['removedQuantity']; | ||||
| if (json['suppliesUsing'] != null) { | if (json['suppliesUsing'] != null) { | ||||
| suppliesUsing = new List<SuppliesUsing>(); | |||||
| suppliesUsing = <SuppliesUsing>[]; | |||||
| json['suppliesUsing'].forEach((v) { | json['suppliesUsing'].forEach((v) { | ||||
| suppliesUsing.add(new SuppliesUsing.fromJson(v)); | |||||
| suppliesUsing?.add(SuppliesUsing.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['harvestId'] = this.harvestId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| data['quantityLv1'] = this.quantityLv1; | |||||
| data['quantityLv2'] = this.quantityLv2; | |||||
| data['quantityLv3'] = this.quantityLv3; | |||||
| data['removedQuantity'] = this.removedQuantity; | |||||
| if (this.suppliesUsing != null) { | |||||
| data['suppliesUsing'] = | |||||
| this.suppliesUsing.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['harvestId'] = harvestId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| data['quantityLv1'] = quantityLv1; | |||||
| data['quantityLv2'] = quantityLv2; | |||||
| data['quantityLv3'] = quantityLv3; | |||||
| data['removedQuantity'] = removedQuantity; | |||||
| if (suppliesUsing != null) { | |||||
| data['suppliesUsing'] = suppliesUsing?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } |
| class LocationUnit { | class LocationUnit { | ||||
| int id; | |||||
| String name; | |||||
| bool isSelected; | |||||
| int? id; | |||||
| String? name; | |||||
| bool? isSelected; | |||||
| LocationUnit({this.id, this.name}); | LocationUnit({this.id, this.name}); | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['name'] = this.name; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['name'] = name; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Media { | class Media { | ||||
| String pathFile; | |||||
| bool isVideo; | |||||
| bool isServerFile = false; | |||||
| String? pathFile; | |||||
| bool? isVideo; | |||||
| bool? isServerFile = false; | |||||
| } | } |
| class NotificationDTO { | class NotificationDTO { | ||||
| int id; | |||||
| String subject; | |||||
| String message; | |||||
| int tbCropId; | |||||
| int tbEntityId; | |||||
| String contents; | |||||
| String createdDate; | |||||
| String sendDate; | |||||
| int isRead; | |||||
| String type; | |||||
| int? id; | |||||
| String? subject; | |||||
| String? message; | |||||
| int? tbCropId; | |||||
| int? tbEntityId; | |||||
| String? contents; | |||||
| String? createdDate; | |||||
| String? sendDate; | |||||
| int? isRead; | |||||
| String? type; | |||||
| NotificationDTO( | NotificationDTO( | ||||
| {this.id, | |||||
| this.subject, | |||||
| this.message, | |||||
| this.tbCropId, | |||||
| this.tbEntityId, | |||||
| this.contents, | |||||
| this.createdDate, | |||||
| this.sendDate, | |||||
| this.type, | |||||
| this.isRead}); | |||||
| {this.id, this.subject, this.message, this.tbCropId, this.tbEntityId, this.contents, this.createdDate, this.sendDate, this.type, this.isRead}); | |||||
| NotificationDTO.clone(NotificationDTO noti) { | NotificationDTO.clone(NotificationDTO noti) { | ||||
| this.id = noti.id; | |||||
| this.contents = noti.contents; | |||||
| this.tbCropId = noti.tbCropId; | |||||
| this.tbEntityId = noti.tbEntityId; | |||||
| this.subject = noti.subject; | |||||
| this.message = noti.message; | |||||
| this.createdDate = noti.createdDate; | |||||
| this.sendDate = noti.sendDate; | |||||
| this.type = noti.type; | |||||
| this.isRead = noti.isRead; | |||||
| id = noti.id; | |||||
| contents = noti.contents; | |||||
| tbCropId = noti.tbCropId; | |||||
| tbEntityId = noti.tbEntityId; | |||||
| subject = noti.subject; | |||||
| message = noti.message; | |||||
| createdDate = noti.createdDate; | |||||
| sendDate = noti.sendDate; | |||||
| type = noti.type; | |||||
| isRead = noti.isRead; | |||||
| } | } | ||||
| NotificationDTO.fromJson(Map<String, dynamic> json) { | NotificationDTO.fromJson(Map<String, dynamic> json) { | ||||
| id = json['id']; | id = json['id']; | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['subject'] = this.subject; | |||||
| data['message'] = this.message; | |||||
| data['tbCropId'] = this.tbCropId; | |||||
| data['tbEntityId'] = this.tbEntityId; | |||||
| data['contents'] = this.contents; | |||||
| data['createdDate'] = this.createdDate; | |||||
| data['sendDate'] = this.sendDate; | |||||
| data['type'] = this.type; | |||||
| data['isRead'] = this.isRead; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['subject'] = subject; | |||||
| data['message'] = message; | |||||
| data['tbCropId'] = tbCropId; | |||||
| data['tbEntityId'] = tbEntityId; | |||||
| data['contents'] = contents; | |||||
| data['createdDate'] = createdDate; | |||||
| data['sendDate'] = sendDate; | |||||
| data['type'] = type; | |||||
| data['isRead'] = isRead; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| import 'NotificationDTO.dart'; | import 'NotificationDTO.dart'; | ||||
| class NotificationObjectDTO { | class NotificationObjectDTO { | ||||
| int numberUnreadPage; | |||||
| int numberReadPage; | |||||
| int numberUnreadTotal; | |||||
| int numberReadTotal; | |||||
| List<NotificationDTO> notificationDTO; | |||||
| int? numberUnreadPage; | |||||
| int? numberReadPage; | |||||
| int? numberUnreadTotal; | |||||
| int? numberReadTotal; | |||||
| List<NotificationDTO>? notificationDTO; | |||||
| NotificationObjectDTO( | |||||
| {this.numberUnreadPage, | |||||
| this.numberReadPage, | |||||
| this.numberUnreadTotal, | |||||
| this.numberReadTotal, | |||||
| this.notificationDTO}); | |||||
| NotificationObjectDTO({this.numberUnreadPage, this.numberReadPage, this.numberUnreadTotal, this.numberReadTotal, this.notificationDTO}); | |||||
| NotificationObjectDTO.fromJson(Map<String, dynamic> json) { | NotificationObjectDTO.fromJson(Map<String, dynamic> json) { | ||||
| numberUnreadPage = json['numberUnreadPage']; | numberUnreadPage = json['numberUnreadPage']; | ||||
| numberUnreadTotal = json['numberUnreadTotal']; | numberUnreadTotal = json['numberUnreadTotal']; | ||||
| numberReadTotal = json['numberReadTotal']; | numberReadTotal = json['numberReadTotal']; | ||||
| if (json['tbnotificationDTOs'] != null) { | if (json['tbnotificationDTOs'] != null) { | ||||
| notificationDTO = new List<NotificationDTO>(); | |||||
| notificationDTO = <NotificationDTO>[]; | |||||
| json['tbnotificationDTOs'].forEach((v) { | json['tbnotificationDTOs'].forEach((v) { | ||||
| notificationDTO.add(new NotificationDTO.fromJson(v)); | |||||
| notificationDTO?.add(NotificationDTO.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['numberUnreadPage'] = this.numberUnreadPage; | |||||
| data['numberReadPage'] = this.numberReadPage; | |||||
| data['numberUnreadTotal'] = this.numberUnreadTotal; | |||||
| data['numberReadTotal'] = this.numberReadTotal; | |||||
| if (this.notificationDTO != null) { | |||||
| data['tbnotificationDTOs'] = | |||||
| this.notificationDTO.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['numberUnreadPage'] = numberUnreadPage; | |||||
| data['numberReadPage'] = numberReadPage; | |||||
| data['numberUnreadTotal'] = numberUnreadTotal; | |||||
| data['numberReadTotal'] = numberReadTotal; | |||||
| if (notificationDTO != null) { | |||||
| data['tbnotificationDTOs'] = notificationDTO?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } |
| import 'NurseryDetail.dart'; | import 'NurseryDetail.dart'; | ||||
| class Nursery { | class Nursery { | ||||
| int id; | |||||
| int activityId; | |||||
| int cropId; | |||||
| String executeDate; | |||||
| String description; | |||||
| String executeBy; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| String seedName; | |||||
| num substratesId; | |||||
| String substrateName; | |||||
| num seedLength; | |||||
| num quantity; | |||||
| num seedIncubationTime; | |||||
| List<NurseryDetail> nurseryDetail; | |||||
| int? id; | |||||
| int? activityId; | |||||
| int? cropId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| String? seedName; | |||||
| num? substratesId; | |||||
| String? substrateName; | |||||
| num? seedLength; | |||||
| num? quantity; | |||||
| num? seedIncubationTime; | |||||
| List<NurseryDetail>? nurseryDetail; | |||||
| Nursery( | Nursery( | ||||
| {this.id, | {this.id, | ||||
| quantity = json['quantity']; | quantity = json['quantity']; | ||||
| seedIncubationTime = json['seedIncubationTime']; | seedIncubationTime = json['seedIncubationTime']; | ||||
| if (json['nurseryDetail'] != null) { | if (json['nurseryDetail'] != null) { | ||||
| nurseryDetail = new List<NurseryDetail>(); | |||||
| nurseryDetail = <NurseryDetail>[]; | |||||
| json['nurseryDetail'].forEach((v) { | json['nurseryDetail'].forEach((v) { | ||||
| nurseryDetail.add(new NurseryDetail.fromJson(v)); | |||||
| nurseryDetail?.add(NurseryDetail.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['activityId'] = this.activityId; | |||||
| data['cropId'] = this.cropId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| data['seedName'] = this.seedName; | |||||
| data['substratesId'] = this.substratesId; | |||||
| data['substrateName'] = this.substrateName; | |||||
| data['seedLength'] = this.seedLength; | |||||
| data['quantity'] = this.quantity; | |||||
| data['seedIncubationTime'] = this.seedIncubationTime; | |||||
| if (this.nurseryDetail != null) { | |||||
| data['nurseryDetail'] = | |||||
| this.nurseryDetail.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['activityId'] = activityId; | |||||
| data['cropId'] = cropId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| data['seedName'] = seedName; | |||||
| data['substratesId'] = substratesId; | |||||
| data['substrateName'] = substrateName; | |||||
| data['seedLength'] = seedLength; | |||||
| data['quantity'] = quantity; | |||||
| data['seedIncubationTime'] = seedIncubationTime; | |||||
| if (nurseryDetail != null) { | |||||
| data['nurseryDetail'] = nurseryDetail?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } |
| class NurseryDetail { | class NurseryDetail { | ||||
| int id; | |||||
| String workerName; | |||||
| String trayNumber; | |||||
| int tbNurseryId; | |||||
| int? id; | |||||
| String? workerName; | |||||
| String? trayNumber; | |||||
| int? tbNurseryId; | |||||
| NurseryDetail({this.id, this.workerName, this.trayNumber, this.tbNurseryId}); | NurseryDetail({this.id, this.workerName, this.trayNumber, this.tbNurseryId}); | ||||
| NurseryDetail.clone(NurseryDetail nurseryDetail) { | NurseryDetail.clone(NurseryDetail nurseryDetail) { | ||||
| this.id = nurseryDetail.id; | |||||
| this.workerName = nurseryDetail.workerName; | |||||
| this.trayNumber = nurseryDetail.trayNumber; | |||||
| this.tbNurseryId = nurseryDetail.tbNurseryId; | |||||
| id = nurseryDetail.id; | |||||
| workerName = nurseryDetail.workerName; | |||||
| trayNumber = nurseryDetail.trayNumber; | |||||
| tbNurseryId = nurseryDetail.tbNurseryId; | |||||
| } | } | ||||
| NurseryDetail.fromJson(Map<String, dynamic> json) { | NurseryDetail.fromJson(Map<String, dynamic> json) { | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['workerName'] = this.workerName; | |||||
| data['trayNumber'] = this.trayNumber; | |||||
| data['tbNurseryId'] = this.tbNurseryId; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['workerName'] = workerName; | |||||
| data['trayNumber'] = trayNumber; | |||||
| data['tbNurseryId'] = tbNurseryId; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Other { | class Other { | ||||
| int id; | |||||
| int cropId; | |||||
| int activityId; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| String executeDate; | |||||
| String description; | |||||
| String createdByName; | |||||
| String activityTypeName; | |||||
| int? id; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? createdByName; | |||||
| String? activityTypeName; | |||||
| Other( | Other( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['createdByName'] = this.createdByName; | |||||
| data['activityTypeName'] = this.activityTypeName; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['createdByName'] = createdByName; | |||||
| data['activityTypeName'] = activityTypeName; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Packing { | class Packing { | ||||
| int id; | |||||
| int cropId; | |||||
| int activityId; | |||||
| int harvestId; | |||||
| String executeDate; | |||||
| String description; | |||||
| String executeBy; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| num quantityLv1; | |||||
| num quantityLv2; | |||||
| num quantityLv3; | |||||
| num removedQuantity; | |||||
| int? id; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| int? harvestId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| num? quantityLv1; | |||||
| num? quantityLv2; | |||||
| num? quantityLv3; | |||||
| num? removedQuantity; | |||||
| Packing( | Packing( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['harvestId'] = this.harvestId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| data['quantityLv1'] = this.quantityLv1; | |||||
| data['quantityLv2'] = this.quantityLv2; | |||||
| data['quantityLv3'] = this.quantityLv3; | |||||
| data['removedQuantity'] = this.removedQuantity; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['harvestId'] = harvestId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| data['quantityLv1'] = quantityLv1; | |||||
| data['quantityLv2'] = quantityLv2; | |||||
| data['quantityLv3'] = quantityLv3; | |||||
| data['removedQuantity'] = removedQuantity; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| import 'SuppliesUsing.dart'; | import 'SuppliesUsing.dart'; | ||||
| class Plant { | class Plant { | ||||
| int id; | |||||
| int cropId; | |||||
| int activityId; | |||||
| String executeDate; | |||||
| String description; | |||||
| String executeBy; | |||||
| String density; | |||||
| num quantity; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| List<SuppliesUsing> suppliesUsing; | |||||
| int? id; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| String? density; | |||||
| num? quantity; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| List<SuppliesUsing>? suppliesUsing; | |||||
| Plant( | Plant( | ||||
| {this.id, | {this.id, | ||||
| quantity = json['quantity']; | quantity = json['quantity']; | ||||
| media = json['media']; | media = json['media']; | ||||
| if (json['suppliesUsing'] != null) { | if (json['suppliesUsing'] != null) { | ||||
| suppliesUsing = new List<SuppliesUsing>(); | |||||
| suppliesUsing = <SuppliesUsing>[]; | |||||
| json['suppliesUsing'].forEach((v) { | json['suppliesUsing'].forEach((v) { | ||||
| suppliesUsing.add(new SuppliesUsing.fromJson(v)); | |||||
| suppliesUsing?.add(SuppliesUsing.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['activityId'] = this.activityId; | |||||
| data['cropId'] = this.cropId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['density'] = this.density; | |||||
| data['quantity'] = this.quantity; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| if (this.suppliesUsing != null) { | |||||
| data['suppliesUsing'] = | |||||
| this.suppliesUsing.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['activityId'] = activityId; | |||||
| data['cropId'] = cropId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| data['density'] = density; | |||||
| data['quantity'] = quantity; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| if (suppliesUsing != null) { | |||||
| data['suppliesUsing'] = suppliesUsing?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } |
| class RequestDisease { | class RequestDisease { | ||||
| int id; | |||||
| int activityId; | |||||
| int cropId; | |||||
| String executeDate; | |||||
| String description; | |||||
| List<String> mediaDel; | |||||
| List<ObjectUpdateDetail> objectUpdateDetail; | |||||
| int? id; | |||||
| int? activityId; | |||||
| int? cropId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| List<String>? mediaDel; | |||||
| List<ObjectUpdateDetail>? objectUpdateDetail; | |||||
| RequestDisease( | |||||
| {this.id, | |||||
| this.activityId, | |||||
| this.cropId, | |||||
| this.executeDate, | |||||
| this.description, | |||||
| this.mediaDel, | |||||
| this.objectUpdateDetail}); | |||||
| RequestDisease({this.id, this.activityId, this.cropId, this.executeDate, this.description, this.mediaDel, this.objectUpdateDetail}); | |||||
| RequestDisease.fromJson(Map<String, dynamic> json) { | RequestDisease.fromJson(Map<String, dynamic> json) { | ||||
| id = json['id']; | id = json['id']; | ||||
| executeDate = json['executeDate']; | executeDate = json['executeDate']; | ||||
| description = json['description']; | description = json['description']; | ||||
| if (json['objectUpdateDetail'] != null) { | if (json['objectUpdateDetail'] != null) { | ||||
| objectUpdateDetail = new List<ObjectUpdateDetail>(); | |||||
| objectUpdateDetail = <ObjectUpdateDetail>[]; | |||||
| json['objectUpdateDetail'].forEach((v) { | json['objectUpdateDetail'].forEach((v) { | ||||
| objectUpdateDetail.add(new ObjectUpdateDetail.fromJson(v)); | |||||
| objectUpdateDetail?.add(ObjectUpdateDetail.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['media_del'] = this.mediaDel; | |||||
| if (this.objectUpdateDetail != null) { | |||||
| data['objectUpdateDetail'] = | |||||
| this.objectUpdateDetail.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['media_del'] = mediaDel; | |||||
| if (objectUpdateDetail != null) { | |||||
| data['objectUpdateDetail'] = objectUpdateDetail?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } | ||||
| } | } | ||||
| class ObjectUpdateDetail { | class ObjectUpdateDetail { | ||||
| int id; | |||||
| String name; | |||||
| String index; | |||||
| int? id; | |||||
| String? name; | |||||
| String? index; | |||||
| ObjectUpdateDetail({this.id, this.name, this.index}); | ObjectUpdateDetail({this.id, this.name, this.index}); | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['name'] = this.name; | |||||
| data['index'] = this.index; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['name'] = name; | |||||
| data['index'] = index; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class RequestEnvironment { | class RequestEnvironment { | ||||
| int activityId; | |||||
| int cropId; | |||||
| String executeDate; | |||||
| String description; | |||||
| List<String> mediaDel; | |||||
| List<EnvDetail> envDetail; | |||||
| int? activityId; | |||||
| int? cropId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| List<String>? mediaDel; | |||||
| List<EnvDetail>? envDetail; | |||||
| RequestEnvironment( | |||||
| {this.activityId, | |||||
| this.cropId, | |||||
| this.executeDate, | |||||
| this.description, | |||||
| this.mediaDel, | |||||
| this.envDetail}); | |||||
| RequestEnvironment({this.activityId, this.cropId, this.executeDate, this.description, this.mediaDel, this.envDetail}); | |||||
| RequestEnvironment.fromJson(Map<String, dynamic> json) { | RequestEnvironment.fromJson(Map<String, dynamic> json) { | ||||
| activityId = json['activityId']; | activityId = json['activityId']; | ||||
| executeDate = json['executeDate']; | executeDate = json['executeDate']; | ||||
| description = json['description']; | description = json['description']; | ||||
| if (json['envDetail'] != null) { | if (json['envDetail'] != null) { | ||||
| envDetail = new List<EnvDetail>(); | |||||
| envDetail = <EnvDetail>[]; | |||||
| json['envDetail'].forEach((v) { | json['envDetail'].forEach((v) { | ||||
| envDetail.add(new EnvDetail.fromJson(v)); | |||||
| envDetail?.add(EnvDetail.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['activityId'] = this.activityId; | |||||
| data['cropId'] = this.cropId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['media_del'] = this.mediaDel; | |||||
| if (this.envDetail != null) { | |||||
| data['envDetail'] = this.envDetail.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['activityId'] = activityId; | |||||
| data['cropId'] = cropId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['media_del'] = mediaDel; | |||||
| if (envDetail != null) { | |||||
| data['envDetail'] = envDetail?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } | ||||
| } | } | ||||
| class EnvDetail { | class EnvDetail { | ||||
| String name; | |||||
| String index; | |||||
| String? name; | |||||
| String? index; | |||||
| EnvDetail({this.name, this.index}); | EnvDetail({this.name, this.index}); | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['name'] = this.name; | |||||
| data['index'] = this.index; | |||||
| final data = <String, dynamic>{}; | |||||
| data['name'] = name; | |||||
| data['index'] = index; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class RequestGeneralModel { | class RequestGeneralModel { | ||||
| int cropId; | |||||
| int activityId; | |||||
| String executeDate; | |||||
| String description; | |||||
| List<String> mediaDel; | |||||
| List<ObjectUpdateDetail> objectUpdateDetail; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| List<String>? mediaDel; | |||||
| List<ObjectUpdateDetail>? objectUpdateDetail; | |||||
| RequestGeneralModel( | |||||
| {this.cropId, | |||||
| this.activityId, | |||||
| this.executeDate, | |||||
| this.description, | |||||
| this.mediaDel, | |||||
| this.objectUpdateDetail}); | |||||
| RequestGeneralModel({this.cropId, this.activityId, this.executeDate, this.description, this.mediaDel, this.objectUpdateDetail}); | |||||
| RequestGeneralModel.fromJson(Map<String, dynamic> json) { | RequestGeneralModel.fromJson(Map<String, dynamic> json) { | ||||
| cropId = json['cropId']; | cropId = json['cropId']; | ||||
| executeDate = json['executeDate']; | executeDate = json['executeDate']; | ||||
| description = json['description']; | description = json['description']; | ||||
| if (json['objectUpdateDetail'] != null) { | if (json['objectUpdateDetail'] != null) { | ||||
| objectUpdateDetail = new List<ObjectUpdateDetail>(); | |||||
| objectUpdateDetail = <ObjectUpdateDetail>[]; | |||||
| json['objectUpdateDetail'].forEach((v) { | json['objectUpdateDetail'].forEach((v) { | ||||
| objectUpdateDetail.add(new ObjectUpdateDetail.fromJson(v)); | |||||
| objectUpdateDetail?.add(ObjectUpdateDetail.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['media_del'] = this.mediaDel; | |||||
| if (this.objectUpdateDetail != null) { | |||||
| data['objectUpdateDetail'] = | |||||
| this.objectUpdateDetail.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['media_del'] = mediaDel; | |||||
| if (objectUpdateDetail != null) { | |||||
| data['objectUpdateDetail'] = objectUpdateDetail?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } | ||||
| } | } | ||||
| class ObjectUpdateDetail { | class ObjectUpdateDetail { | ||||
| String name; | |||||
| String index; | |||||
| String? name; | |||||
| String? index; | |||||
| ObjectUpdateDetail({this.name, this.index}); | ObjectUpdateDetail({this.name, this.index}); | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['name'] = this.name; | |||||
| data['index'] = this.index; | |||||
| final data = <String, dynamic>{}; | |||||
| data['name'] = name; | |||||
| data['index'] = index; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Sell { | class Sell { | ||||
| int id; | |||||
| int cropId; | |||||
| int activityId; | |||||
| int harvestId; | |||||
| String executeDate; | |||||
| String description; | |||||
| String executeBy; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| num quantityLv1; | |||||
| num quantityLv2; | |||||
| num quantityLv3; | |||||
| num removedQuantity; | |||||
| String buyer; | |||||
| int? id; | |||||
| int? cropId; | |||||
| int? activityId; | |||||
| int? harvestId; | |||||
| String? executeDate; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| num? quantityLv1; | |||||
| num? quantityLv2; | |||||
| num? quantityLv3; | |||||
| num? removedQuantity; | |||||
| String? buyer; | |||||
| Sell( | Sell( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['cropId'] = this.cropId; | |||||
| data['activityId'] = this.activityId; | |||||
| data['harvestId'] = this.harvestId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| data['quantityLv1'] = this.quantityLv1; | |||||
| data['quantityLv2'] = this.quantityLv2; | |||||
| data['quantityLv3'] = this.quantityLv3; | |||||
| data['removedQuantity'] = this.removedQuantity; | |||||
| data['buyer'] = this.buyer; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['cropId'] = cropId; | |||||
| data['activityId'] = activityId; | |||||
| data['harvestId'] = harvestId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| data['quantityLv1'] = quantityLv1; | |||||
| data['quantityLv2'] = quantityLv2; | |||||
| data['quantityLv3'] = quantityLv3; | |||||
| data['removedQuantity'] = removedQuantity; | |||||
| data['buyer'] = buyer; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| import 'SuppliesUsing.dart'; | import 'SuppliesUsing.dart'; | ||||
| class Spraying { | class Spraying { | ||||
| int id; | |||||
| int activityId; | |||||
| int cropId; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| String executeDate; | |||||
| num quarantinePeriod; | |||||
| String resultAt; | |||||
| String weatherConditions; | |||||
| String purpose; | |||||
| String description; | |||||
| String executeBy; | |||||
| List<SuppliesUsing> suppliesUsing; | |||||
| int? id; | |||||
| int? activityId; | |||||
| int? cropId; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| String? executeDate; | |||||
| num? quarantinePeriod; | |||||
| String? resultAt; | |||||
| String? weatherConditions; | |||||
| String? purpose; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| List<SuppliesUsing>? suppliesUsing; | |||||
| Spraying( | Spraying( | ||||
| {this.id, | {this.id, | ||||
| description = json['description']; | description = json['description']; | ||||
| executeBy = json['executeBy']; | executeBy = json['executeBy']; | ||||
| if (json['suppliesUsing'] != null) { | if (json['suppliesUsing'] != null) { | ||||
| suppliesUsing = new List<SuppliesUsing>(); | |||||
| suppliesUsing = <SuppliesUsing>[]; | |||||
| json['suppliesUsing'].forEach((v) { | json['suppliesUsing'].forEach((v) { | ||||
| suppliesUsing.add(new SuppliesUsing.fromJson(v)); | |||||
| suppliesUsing?.add(SuppliesUsing.fromJson(v)); | |||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['activityId'] = this.activityId; | |||||
| data['cropId'] = this.cropId; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['quarantinePeriod'] = this.quarantinePeriod; | |||||
| data['resultAt'] = this.resultAt; | |||||
| data['weatherConditions'] = this.weatherConditions; | |||||
| data['purpose'] = this.purpose; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| if (this.suppliesUsing != null) { | |||||
| data['suppliesUsing'] = | |||||
| this.suppliesUsing.map((v) => v.toJson()).toList(); | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['activityId'] = activityId; | |||||
| data['cropId'] = cropId; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| data['executeDate'] = executeDate; | |||||
| data['quarantinePeriod'] = quarantinePeriod; | |||||
| data['resultAt'] = resultAt; | |||||
| data['weatherConditions'] = weatherConditions; | |||||
| data['purpose'] = purpose; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| if (suppliesUsing != null) { | |||||
| data['suppliesUsing'] = suppliesUsing?.map((v) => v.toJson()).toList(); | |||||
| } | } | ||||
| return data; | return data; | ||||
| } | } |
| class SuppliesUsing { | class SuppliesUsing { | ||||
| int id; | |||||
| String dosage; | |||||
| num quantity; | |||||
| String unit; | |||||
| String howToUse; | |||||
| int suppliesInWarehouseId; | |||||
| int tbSuppliesInWarehouseId; | |||||
| String supplyName; | |||||
| String supplyUnit; | |||||
| int tbEquipmentOfCustomerId; | |||||
| int equipmentOfCustomerId; | |||||
| String equipmentName; | |||||
| int? id; | |||||
| String? dosage; | |||||
| num? quantity; | |||||
| String? unit; | |||||
| String? howToUse; | |||||
| int? suppliesInWarehouseId; | |||||
| int? tbSuppliesInWarehouseId; | |||||
| String? supplyName; | |||||
| String? supplyUnit; | |||||
| int? tbEquipmentOfCustomerId; | |||||
| int? equipmentOfCustomerId; | |||||
| String? equipmentName; | |||||
| SuppliesUsing( | SuppliesUsing( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['dosage'] = this.dosage; | |||||
| data['quantity'] = this.quantity; | |||||
| data['unit'] = this.unit; | |||||
| data['howToUse'] = this.howToUse; | |||||
| data['suppliesInWarehouseId'] = this.suppliesInWarehouseId; | |||||
| data['tbEquipmentOfCustomerId'] = this.tbEquipmentOfCustomerId; | |||||
| data['equipmentOfCustomerId'] = this.equipmentOfCustomerId; | |||||
| data['equipmentName'] = this.equipmentName; | |||||
| data['tbSuppliesInWarehouseId'] = this.tbSuppliesInWarehouseId; | |||||
| data['supplyName'] = this.supplyName; | |||||
| data['supplyUnit'] = this.supplyUnit; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['dosage'] = dosage; | |||||
| data['quantity'] = quantity; | |||||
| data['unit'] = unit; | |||||
| data['howToUse'] = howToUse; | |||||
| data['suppliesInWarehouseId'] = suppliesInWarehouseId; | |||||
| data['tbEquipmentOfCustomerId'] = tbEquipmentOfCustomerId; | |||||
| data['equipmentOfCustomerId'] = equipmentOfCustomerId; | |||||
| data['equipmentName'] = equipmentName; | |||||
| data['tbSuppliesInWarehouseId'] = tbSuppliesInWarehouseId; | |||||
| data['supplyName'] = supplyName; | |||||
| data['supplyUnit'] = supplyUnit; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class Supply { | class Supply { | ||||
| int id; | |||||
| num quantity; | |||||
| String unit; | |||||
| int tbWarehouseId; | |||||
| String tbWarehouseName; | |||||
| String tbSuppliesName; | |||||
| int tbSuppliesId; | |||||
| bool isSelected; | |||||
| int? id; | |||||
| num? quantity; | |||||
| String? unit; | |||||
| int? tbWarehouseId; | |||||
| String? tbWarehouseName; | |||||
| String? tbSuppliesName; | |||||
| int? tbSuppliesId; | |||||
| bool? isSelected; | |||||
| Supply( | |||||
| {this.id, | |||||
| this.quantity, | |||||
| this.unit, | |||||
| this.tbWarehouseId, | |||||
| this.tbWarehouseName, | |||||
| this.tbSuppliesName, | |||||
| this.tbSuppliesId, | |||||
| this.isSelected}); | |||||
| Supply({this.id, this.quantity, this.unit, this.tbWarehouseId, this.tbWarehouseName, this.tbSuppliesName, this.tbSuppliesId, this.isSelected}); | |||||
| Supply.fromJson(Map<String, dynamic> json) { | Supply.fromJson(Map<String, dynamic> json) { | ||||
| id = json['id']; | id = json['id']; | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['quantity'] = this.quantity; | |||||
| data['unit'] = this.unit; | |||||
| data['tbWarehouseId'] = this.tbWarehouseId; | |||||
| data['tbWarehouseName'] = this.tbWarehouseName; | |||||
| data['tbSuppliesName'] = this.tbSuppliesName; | |||||
| data['tbSuppliesId'] = this.tbSuppliesId; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['quantity'] = quantity; | |||||
| data['unit'] = unit; | |||||
| data['tbWarehouseId'] = tbWarehouseId; | |||||
| data['tbWarehouseName'] = tbWarehouseName; | |||||
| data['tbSuppliesName'] = tbSuppliesName; | |||||
| data['tbSuppliesId'] = tbSuppliesId; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class UpdateNoti { | class UpdateNoti { | ||||
| int id; | |||||
| int isRead; | |||||
| int? id; | |||||
| int? isRead; | |||||
| UpdateNoti({this.id, this.isRead}); | UpdateNoti({this.id, this.isRead}); | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['isRead'] = this.isRead; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['isRead'] = isRead; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class UseWater { | class UseWater { | ||||
| int id; | |||||
| int activityId; | |||||
| int cropId; | |||||
| String executeDate; | |||||
| String media; | |||||
| List<String> mediaDel; | |||||
| String waterType; | |||||
| num amount; | |||||
| String description; | |||||
| String executeBy; | |||||
| int? id; | |||||
| int? activityId; | |||||
| int? cropId; | |||||
| String? executeDate; | |||||
| String? media; | |||||
| List<String>? mediaDel; | |||||
| String? waterType; | |||||
| num? amount; | |||||
| String? description; | |||||
| String? executeBy; | |||||
| UseWater( | UseWater( | ||||
| {this.id, | {this.id, | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['activityId'] = this.activityId; | |||||
| data['cropId'] = this.cropId; | |||||
| data['executeDate'] = this.executeDate; | |||||
| data['media'] = this.media; | |||||
| data['media_del'] = this.mediaDel; | |||||
| data['waterType'] = this.waterType; | |||||
| data['amount'] = this.amount; | |||||
| data['description'] = this.description; | |||||
| data['executeBy'] = this.executeBy; | |||||
| final data = <String, dynamic>{}; | |||||
| data['id'] = id; | |||||
| data['activityId'] = activityId; | |||||
| data['cropId'] = cropId; | |||||
| data['executeDate'] = executeDate; | |||||
| data['media'] = media; | |||||
| data['media_del'] = mediaDel; | |||||
| data['waterType'] = waterType; | |||||
| data['amount'] = amount; | |||||
| data['description'] = description; | |||||
| data['executeBy'] = executeBy; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| class WaterType { | class WaterType { | ||||
| String waterTypeName; | |||||
| String waterTypeDescription; | |||||
| String? waterTypeName; | |||||
| String? waterTypeDescription; | |||||
| WaterType({this.waterTypeName, this.waterTypeDescription}); | WaterType({this.waterTypeName, this.waterTypeDescription}); | ||||
| } | } | ||||
| Map<String, dynamic> toJson() { | Map<String, dynamic> toJson() { | ||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['waterTypeName'] = this.waterTypeName; | |||||
| data['waterTypeDescription'] = this.waterTypeDescription; | |||||
| final data = <String, dynamic>{}; | |||||
| data['waterTypeName'] = waterTypeName; | |||||
| data['waterTypeDescription'] = waterTypeDescription; | |||||
| return data; | return data; | ||||
| } | } | ||||
| } | } |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| part 'account.g.dart'; | |||||
| @JsonSerializable() | |||||
| class Account { | class Account { | ||||
| Account(); | |||||
| num? id; | |||||
| String? login; | |||||
| String? firstName; | |||||
| String? lastName; | |||||
| String? midleName; | |||||
| String? fullName; | |||||
| String? phone; | |||||
| String? address; | |||||
| String? avartar; | |||||
| num? vaiTroId; | |||||
| String? tenVaiTro; | |||||
| num? donViCanhTacId; | |||||
| String? tenDonVi; | |||||
| String? email; | |||||
| String? imageUrl; | |||||
| bool? activated; | |||||
| num? countryId; | |||||
| String? countryName; | |||||
| num? cityId; | |||||
| String? cityName; | |||||
| num? districtId; | |||||
| String? districtName; | |||||
| num? wardId; | |||||
| String? wardName; | |||||
| List<String>? authorities; | |||||
| Account( | |||||
| {this.id, | |||||
| this.login, | |||||
| this.firstName, | |||||
| this.lastName, | |||||
| this.midleName, | |||||
| this.fullName, | |||||
| this.phone, | |||||
| this.address, | |||||
| this.avartar, | |||||
| this.vaiTroId, | |||||
| this.tenVaiTro, | |||||
| this.donViCanhTacId, | |||||
| this.tenDonVi, | |||||
| this.email, | |||||
| this.imageUrl, | |||||
| this.activated, | |||||
| this.countryId, | |||||
| this.countryName, | |||||
| this.cityId, | |||||
| this.cityName, | |||||
| this.districtId, | |||||
| this.districtName, | |||||
| this.wardId, | |||||
| this.wardName, | |||||
| this.authorities}); | |||||
| num id; | |||||
| String login; | |||||
| String firstName; | |||||
| String lastName; | |||||
| String midleName; | |||||
| String fullName; | |||||
| String phone; | |||||
| String address; | |||||
| String avartar; | |||||
| num vaiTroId; | |||||
| String tenVaiTro; | |||||
| num donViCanhTacId; | |||||
| String tenDonVi; | |||||
| String email; | |||||
| String imageUrl; | |||||
| bool activated; | |||||
| int countryId; | |||||
| String countryName; | |||||
| int cityId; | |||||
| String cityName; | |||||
| int districtId; | |||||
| String districtName; | |||||
| int wardId; | |||||
| String wardName; | |||||
| List authorities; | |||||
| Account.fromJson(Map<String, dynamic> json) { | |||||
| id = json['id']; | |||||
| login = json['login']; | |||||
| firstName = json['firstName']; | |||||
| lastName = json['lastName']; | |||||
| midleName = json['midleName']; | |||||
| fullName = json['fullName']; | |||||
| phone = json['phone']; | |||||
| address = json['address']; | |||||
| avartar = json['avartar']; | |||||
| vaiTroId = json['vaiTroId']; | |||||
| tenVaiTro = json['tenVaiTro']; | |||||
| donViCanhTacId = json['donViCanhTacId']; | |||||
| tenDonVi = json['tenDonVi']; | |||||
| email = json['email']; | |||||
| imageUrl = json['imageUrl']; | |||||
| activated = json['activated']; | |||||
| countryId = json['countryId']; | |||||
| countryName = json['countryName']; | |||||
| cityId = json['cityId']; | |||||
| cityName = json['cityName']; | |||||
| districtId = json['districtId']; | |||||
| districtName = json['districtName']; | |||||
| wardId = json['wardId']; | |||||
| wardName = json['wardName']; | |||||
| authorities = json['authorities'].cast<String>(); | |||||
| } | |||||
| factory Account.fromJson(Map<String, dynamic> json) => | |||||
| _$AccountFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$AccountToJson(this); | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['login'] = this.login; | |||||
| data['firstName'] = this.firstName; | |||||
| data['lastName'] = this.lastName; | |||||
| data['midleName'] = this.midleName; | |||||
| data['fullName'] = this.fullName; | |||||
| data['phone'] = this.phone; | |||||
| data['address'] = this.address; | |||||
| data['avartar'] = this.avartar; | |||||
| data['vaiTroId'] = this.vaiTroId; | |||||
| data['tenVaiTro'] = this.tenVaiTro; | |||||
| data['donViCanhTacId'] = this.donViCanhTacId; | |||||
| data['tenDonVi'] = this.tenDonVi; | |||||
| data['email'] = this.email; | |||||
| data['imageUrl'] = this.imageUrl; | |||||
| data['activated'] = this.activated; | |||||
| data['countryId'] = this.countryId; | |||||
| data['countryName'] = this.countryName; | |||||
| data['cityId'] = this.cityId; | |||||
| data['cityName'] = this.cityName; | |||||
| data['districtId'] = this.districtId; | |||||
| data['districtName'] = this.districtName; | |||||
| data['wardId'] = this.wardId; | |||||
| data['wardName'] = this.wardName; | |||||
| data['authorities'] = this.authorities; | |||||
| return data; | |||||
| } | |||||
| } | } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'account.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| Account _$AccountFromJson(Map<String, dynamic> json) { | |||||
| return Account() | |||||
| ..id = json['id'] as num | |||||
| ..login = json['login'] as String | |||||
| ..firstName = json['firstName'] as String | |||||
| ..lastName = json['lastName'] as String | |||||
| ..midleName = json['midleName'] as String | |||||
| ..fullName = json['fullName'] as String | |||||
| ..phone = json['phone'] as String | |||||
| ..address = json['address'] as String | |||||
| ..avartar = json['avartar'] as String | |||||
| ..vaiTroId = json['vaiTroId'] as num | |||||
| ..tenVaiTro = json['tenVaiTro'] as String | |||||
| ..donViCanhTacId = json['donViCanhTacId'] as num | |||||
| ..tenDonVi = json['tenDonVi'] as String | |||||
| ..email = json['email'] as String | |||||
| ..imageUrl = json['imageUrl'] as String | |||||
| ..activated = json['activated'] as bool | |||||
| ..countryId = json['countryId'] as num | |||||
| ..countryName = json['countryName'] as String | |||||
| ..cityId = json['cityId'] as num | |||||
| ..cityName = json['cityName'] as String | |||||
| ..districtId = json['districtId'] as num | |||||
| ..districtName = json['districtName'] as String | |||||
| ..wardId = json['wardId'] as num | |||||
| ..wardName = json['wardName'] as String | |||||
| ..authorities = json['authorities'] as List; | |||||
| } | |||||
| Map<String, dynamic> _$AccountToJson(Account instance) => <String, dynamic>{ | |||||
| 'id': instance.id, | |||||
| 'login': instance.login, | |||||
| 'firstName': instance.firstName, | |||||
| 'lastName': instance.lastName, | |||||
| 'midleName': instance.midleName, | |||||
| 'fullName': instance.fullName, | |||||
| 'phone': instance.phone, | |||||
| 'address': instance.address, | |||||
| 'avartar': instance.avartar, | |||||
| 'vaiTroId': instance.vaiTroId, | |||||
| 'tenVaiTro': instance.tenVaiTro, | |||||
| 'donViCanhTacId': instance.donViCanhTacId, | |||||
| 'tenDonVi': instance.tenDonVi, | |||||
| 'email': instance.email, | |||||
| 'imageUrl': instance.imageUrl, | |||||
| 'activated': instance.activated, | |||||
| 'countryId': instance.countryId, | |||||
| 'countryName': instance.countryName, | |||||
| 'cityId': instance.cityId, | |||||
| 'cityName': instance.cityName, | |||||
| 'districtId': instance.districtId, | |||||
| 'districtName': instance.districtName, | |||||
| 'wardId': instance.wardId, | |||||
| 'wardName': instance.wardName, | |||||
| 'authorities': instance.authorities, | |||||
| }; |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| class Password { | |||||
| String? key; | |||||
| String? currentPassword; | |||||
| String? newPassword; | |||||
| part 'password.g.dart'; | |||||
| Password({this.key, this.currentPassword, this.newPassword}); | |||||
| @JsonSerializable() | |||||
| class Password { | |||||
| Password(); | |||||
| Password.fromJson(Map<String, dynamic> json) { | |||||
| key = json['key']; | |||||
| currentPassword = json['currentPassword']; | |||||
| newPassword = json['newPassword']; | |||||
| } | |||||
| String key; | |||||
| String currentPassword; | |||||
| String newPassword; | |||||
| factory Password.fromJson(Map<String,dynamic> json) => _$PasswordFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$PasswordToJson(this); | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['key'] = this.key; | |||||
| data['currentPassword'] = this.currentPassword; | |||||
| data['newPassword'] = this.newPassword; | |||||
| return data; | |||||
| } | |||||
| } | } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'password.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| Password _$PasswordFromJson(Map<String, dynamic> json) { | |||||
| return Password() | |||||
| ..key = json['key'] as String | |||||
| ..currentPassword = json['currentPassword'] as String | |||||
| ..newPassword = json['newPassword'] as String; | |||||
| } | |||||
| Map<String, dynamic> _$PasswordToJson(Password instance) => <String, dynamic>{ | |||||
| 'key': instance.key, | |||||
| 'currentPassword': instance.currentPassword, | |||||
| 'newPassword': instance.newPassword, | |||||
| }; |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| part 'user.g.dart'; | |||||
| @JsonSerializable() | |||||
| class User { | class User { | ||||
| User(); | |||||
| String? idToken; | |||||
| User({this.idToken}); | |||||
| String idToken; | |||||
| User.fromJson(Map<String, dynamic> json) { | |||||
| idToken = json['idToken']; | |||||
| } | |||||
| factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$UserToJson(this); | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['idToken'] = this.idToken; | |||||
| return data; | |||||
| } | |||||
| } | } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'user.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| User _$UserFromJson(Map<String, dynamic> json) { | |||||
| return User()..idToken = json['id_token'] as String; | |||||
| } | |||||
| Map<String, dynamic> _$UserToJson(User instance) => <String, dynamic>{ | |||||
| 'id_token': instance.idToken, | |||||
| }; |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| part 'user_request.g.dart'; | |||||
| @JsonSerializable() | |||||
| class UserRequest { | class UserRequest { | ||||
| final String username; | |||||
| final String password; | |||||
| String? username; | |||||
| String? password; | |||||
| UserRequest({this.username, this.password}); | UserRequest({this.username, this.password}); | ||||
| factory UserRequest.fromJson(Map<String, dynamic> json) => | |||||
| _$UserRequestFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$UserRequestToJson(this); | |||||
| UserRequest.fromJson(Map<String, dynamic> json) { | |||||
| username = json['username']; | |||||
| password = json['password']; | |||||
| } | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['username'] = this.username; | |||||
| data['password'] = this.password; | |||||
| return data; | |||||
| } | |||||
| } | } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'user_request.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| UserRequest _$UserRequestFromJson(Map<String, dynamic> json) { | |||||
| return UserRequest( | |||||
| username: json['username'] as String, | |||||
| password: json['password'] as String, | |||||
| ); | |||||
| } | |||||
| Map<String, dynamic> _$UserRequestToJson(UserRequest instance) => | |||||
| <String, dynamic>{ | |||||
| 'username': instance.username, | |||||
| 'password': instance.password, | |||||
| }; |
| import 'package:farm_tpf/utils/const_string.dart'; | import 'package:farm_tpf/utils/const_string.dart'; | ||||
| class AppException { | class AppException { | ||||
| static String handleError(dynamic error, {String customMessageError}) { | |||||
| String errorDescription = ""; | |||||
| static String handleError(dynamic error, {String? customMessageError}) { | |||||
| var errorDescription = ""; | |||||
| try { | try { | ||||
| DioError dioError = error as DioError; | |||||
| var dioError = error as DioError; | |||||
| switch (dioError.type) { | switch (dioError.type) { | ||||
| case DioErrorType.CANCEL: | case DioErrorType.CANCEL: | ||||
| errorDescription = exception_dio_cancle; | errorDescription = exception_dio_cancle; | ||||
| if (statusCode == 400) { | if (statusCode == 400) { | ||||
| errorDescription = customMessageError ?? exception_dio_400; | errorDescription = customMessageError ?? exception_dio_400; | ||||
| try { | try { | ||||
| Map errorMap = jsonDecode(dioError.response.data); | |||||
| Map<String, dynamic> errorMap = jsonDecode(dioError.response.data); | |||||
| var errorCode = ErrorCommon.fromJson(errorMap).errorKey; | var errorCode = ErrorCommon.fromJson(errorMap).errorKey; | ||||
| switch (errorCode) { | switch (errorCode) { |
| class _RestClient implements RestClient { | class _RestClient implements RestClient { | ||||
| _RestClient(this._dio, {this.baseUrl}) { | _RestClient(this._dio, {this.baseUrl}) { | ||||
| ArgumentError.checkNotNull(_dio, '_dio'); | ArgumentError.checkNotNull(_dio, '_dio'); | ||||
| this.baseUrl ??= 'https://tpf.aztrace.vn'; | |||||
| baseUrl ??= 'https://smf.presshome.vn/'; | |||||
| } | } | ||||
| final Dio _dio; | final Dio _dio; | ||||
| String baseUrl; | |||||
| String? baseUrl; | |||||
| @override | @override | ||||
| login(userRequest) async { | login(userRequest) async { | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| _data.addAll(userRequest?.toJson() ?? <String, dynamic>{}); | _data.addAll(userRequest?.toJson() ?? <String, dynamic>{}); | ||||
| final Response<Map<String, dynamic>> _result = await _dio.request( | |||||
| '/api/authenticate', | |||||
| final Response<Map<String, dynamic>> _result = await _dio.request('/api/authenticate', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'POST', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'POST', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| final value = User.fromJson(_result.data); | final value = User.fromJson(_result.data); | ||||
| return value; | return value; | ||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final Response<Map<String, dynamic>> _result = await _dio.request( | |||||
| '/api/account', | |||||
| final Response<Map<String, dynamic>> _result = await _dio.request('/api/account', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'GET', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'GET', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| final value = Account.fromJson(_result.data); | final value = Account.fromJson(_result.data); | ||||
| return value; | return value; | ||||
| final _data = email; | final _data = email; | ||||
| await _dio.request<void>('/api/account/reset-password/init', | await _dio.request<void>('/api/account/reset-password/init', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'POST', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'POST', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| return null; | return null; | ||||
| } | } | ||||
| _data.addAll(password?.toJson() ?? <String, dynamic>{}); | _data.addAll(password?.toJson() ?? <String, dynamic>{}); | ||||
| await _dio.request<void>('/api/account/reset-password/finish', | await _dio.request<void>('/api/account/reset-password/finish', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'POST', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'POST', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| return null; | return null; | ||||
| } | } | ||||
| _data.addAll(password?.toJson() ?? <String, dynamic>{}); | _data.addAll(password?.toJson() ?? <String, dynamic>{}); | ||||
| await _dio.request<void>('/api/account/change-password', | await _dio.request<void>('/api/account/change-password', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'POST', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'POST', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| return null; | return null; | ||||
| } | } | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| _data.addAll(account?.toJson() ?? <String, dynamic>{}); | _data.addAll(account?.toJson() ?? <String, dynamic>{}); | ||||
| final Response<Map<String, dynamic>> _result = await _dio.request( | |||||
| '/api/update-my-profile', | |||||
| final Response<Map<String, dynamic>> _result = await _dio.request('/api/update-my-profile', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'PUT', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'PUT', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| final value = Account.fromJson(_result.data); | final value = Account.fromJson(_result.data); | ||||
| return value; | return value; | ||||
| } | } | ||||
| @override | @override | ||||
| getSupplies(type, {options, query = ""}) async { | |||||
| getSupplies(type, {Options? options, query = ""}) async { | |||||
| ArgumentError.checkNotNull(type, 'type'); | ArgumentError.checkNotNull(type, 'type'); | ||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/list-supplies-in-warehouses/$type?q=$query', | |||||
| queryParameters: queryParameters, | |||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | |||||
| data: _data); | |||||
| var value = _result.data | |||||
| .map((dynamic i) => Supply.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/list-supplies-in-warehouses/$type?q=$query', | |||||
| queryParameters: queryParameters, options: newOptions.merge(method: 'GET', baseUrl: baseUrl), data: _data); | |||||
| var value = _result.data.map((dynamic i) => Supply.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| final _data = token; | final _data = token; | ||||
| await _dio.request<void>('/api/update-fcmToken', | await _dio.request<void>('/api/update-fcmToken', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'PUT', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'PUT', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| return null; | return null; | ||||
| } | } | ||||
| final _data = token; | final _data = token; | ||||
| await _dio.request<void>('/api/delete-fcmToken', | await _dio.request<void>('/api/delete-fcmToken', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'PUT', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'PUT', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| return null; | return null; | ||||
| } | } | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/_search/tb-crops?page=$page&size=$size&sort=id,asc&query=$query', | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/_search/tb-crops?page=$page&size=$size&sort=id,asc&query=$query', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'GET', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'GET', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| var value = _result.data | |||||
| .map((dynamic i) => Crop.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| var value = _result.data.map((dynamic i) => Crop.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| @override | @override | ||||
| getActionTypes({options}) async { | |||||
| getActionTypes({Options? options}) async { | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/listActivityTypesOther', | |||||
| queryParameters: queryParameters, | |||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | |||||
| data: _data); | |||||
| var value = _result.data | |||||
| .map((dynamic i) => ActionType.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/listActivityTypesOther', | |||||
| queryParameters: queryParameters, options: newOptions.merge(method: 'GET', baseUrl: baseUrl), data: _data); | |||||
| var value = _result.data.map((dynamic i) => ActionType.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| @override | @override | ||||
| getWaterTypes({options}) async { | |||||
| getWaterTypes({Options? options}) async { | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/water-types', | |||||
| queryParameters: queryParameters, | |||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | |||||
| data: _data); | |||||
| var value = _result.data | |||||
| .map((dynamic i) => WaterType.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/water-types', | |||||
| queryParameters: queryParameters, options: newOptions.merge(method: 'GET', baseUrl: baseUrl), data: _data); | |||||
| var value = _result.data.map((dynamic i) => WaterType.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| @override | @override | ||||
| getHarvests({options}) async { | |||||
| getHarvests({Options? options}) async { | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/tb-harvests', | |||||
| queryParameters: queryParameters, | |||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | |||||
| data: _data); | |||||
| var value = _result.data | |||||
| .map((dynamic i) => Harvest.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/tb-harvests', | |||||
| queryParameters: queryParameters, options: newOptions.merge(method: 'GET', baseUrl: baseUrl), data: _data); | |||||
| var value = _result.data.map((dynamic i) => Harvest.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| @override | @override | ||||
| getDeviceForActivity({options}) async { | |||||
| getDeviceForActivity({Options? options}) async { | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/listDeviceForActivity', | |||||
| queryParameters: queryParameters, | |||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | |||||
| data: _data); | |||||
| var value = _result.data | |||||
| .map((dynamic i) => Device.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/listDeviceForActivity', | |||||
| queryParameters: queryParameters, options: newOptions.merge(method: 'GET', baseUrl: baseUrl), data: _data); | |||||
| var value = _result.data.map((dynamic i) => Device.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| final _data = status; | final _data = status; | ||||
| await _dio.request<void>('/api/notifications/update-all', | await _dio.request<void>('/api/notifications/update-all', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'PUT', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'PUT', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| return null; | return null; | ||||
| } | } | ||||
| _data.addAll(updateNoti?.toJson() ?? <String, dynamic>{}); | _data.addAll(updateNoti?.toJson() ?? <String, dynamic>{}); | ||||
| await _dio.request<void>('/api/notifications/update', | await _dio.request<void>('/api/notifications/update', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'PUT', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'PUT', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| return null; | return null; | ||||
| } | } | ||||
| @override | @override | ||||
| getCountries({page = 0, size = 400, query = '', options}) async { | |||||
| getCountries({page = 0, size = 400, query = '', Options? options}) async { | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/tb-countries?page=$page&size=$size&query=$query&&sort=name,ASC', | |||||
| queryParameters: queryParameters, | |||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | |||||
| data: _data); | |||||
| var value = _result.data | |||||
| .map((dynamic i) => LocationUnit.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/tb-countries?page=$page&size=$size&query=$query&&sort=name,ASC', | |||||
| queryParameters: queryParameters, options: newOptions.merge(method: 'GET', baseUrl: baseUrl), data: _data); | |||||
| var value = _result.data.map((dynamic i) => LocationUnit.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| @override | @override | ||||
| getProvinces(countryId, {page = 0, size = 20, query = '', options}) async { | |||||
| getProvinces(countryId, {page = 0, size = 20, query = '', Options? options}) async { | |||||
| ArgumentError.checkNotNull(countryId, 'countryId'); | ArgumentError.checkNotNull(countryId, 'countryId'); | ||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | ||||
| data: _data); | data: _data); | ||||
| var value = _result.data | |||||
| .map((dynamic i) => LocationUnit.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| var value = _result.data.map((dynamic i) => LocationUnit.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| @override | @override | ||||
| getDistricts(provinceId, {page = 0, size = 20, query = '', options}) async { | |||||
| getDistricts(provinceId, {page = 0, size = 20, query = '', Options? options}) async { | |||||
| ArgumentError.checkNotNull(provinceId, 'provinceId'); | ArgumentError.checkNotNull(provinceId, 'provinceId'); | ||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | ||||
| data: _data); | data: _data); | ||||
| var value = _result.data | |||||
| .map((dynamic i) => LocationUnit.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| var value = _result.data.map((dynamic i) => LocationUnit.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| @override | @override | ||||
| getWards(districtId, {page = 0, size = 20, query = '', options}) async { | |||||
| getWards(districtId, {page = 0, size = 20, query = '', Options? options}) async { | |||||
| ArgumentError.checkNotNull(districtId, 'districtId'); | ArgumentError.checkNotNull(districtId, 'districtId'); | ||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final newOptions = newRequestOptions(options); | |||||
| final newOptions = newRequestOptions(options ?? Options()); | |||||
| newOptions.extra.addAll(_extra); | newOptions.extra.addAll(_extra); | ||||
| newOptions.headers.addAll(<String, dynamic>{}); | newOptions.headers.addAll(<String, dynamic>{}); | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | options: newOptions.merge(method: 'GET', baseUrl: baseUrl), | ||||
| data: _data); | data: _data); | ||||
| var value = _result.data | |||||
| .map((dynamic i) => LocationUnit.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| var value = _result.data.map((dynamic i) => LocationUnit.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| final Response<Map<String, dynamic>> _result = await _dio.request( | final Response<Map<String, dynamic>> _result = await _dio.request( | ||||
| '/api/tb-crops-detail-for-app/$cropId?page=$page&size=$size&sort=executeDate,DESC', | '/api/tb-crops-detail-for-app/$cropId?page=$page&size=$size&sort=executeDate,DESC', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'GET', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'GET', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| final value = CropPlot.fromJson(_result.data); | final value = CropPlot.fromJson(_result.data); | ||||
| return value; | return value; | ||||
| final Response<Map<String, dynamic>> _result = await _dio.request( | final Response<Map<String, dynamic>> _result = await _dio.request( | ||||
| '/api/tb-crops-scan-qrCode/$cropCode?page=$page&size=$size&sort=executeDate,DESC', | '/api/tb-crops-scan-qrCode/$cropCode?page=$page&size=$size&sort=executeDate,DESC', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'GET', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'GET', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| final value = CropPlot.fromJson(_result.data); | final value = CropPlot.fromJson(_result.data); | ||||
| return value; | return value; | ||||
| _data.addAll(crop?.toJson() ?? <String, dynamic>{}); | _data.addAll(crop?.toJson() ?? <String, dynamic>{}); | ||||
| await _dio.request<void>('/api/tb-crops', | await _dio.request<void>('/api/tb-crops', | ||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'PUT', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'PUT', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| return null; | return null; | ||||
| } | } | ||||
| @override | @override | ||||
| getDevices({query}) async { | |||||
| getDevices({String? query}) async { | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/listDeviceOfUserCustomers?query=$query', | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/listDeviceOfUserCustomers?query=$query', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'GET', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'GET', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| var value = _result.data | |||||
| .map((dynamic i) => Device.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| var value = _result.data.map((dynamic i) => Device.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | queryParameters.removeWhere((k, v) => v == null); | ||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final Response<List<dynamic>> _result = await _dio.request( | |||||
| '/api/list-environment-updates-display/$cropId?page=$page&size=$size', | |||||
| final Response<List<dynamic>> _result = await _dio.request('/api/list-environment-updates-display/$cropId?page=$page&size=$size', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | |||||
| method: 'GET', | |||||
| headers: <String, dynamic>{}, | |||||
| extra: _extra, | |||||
| baseUrl: baseUrl), | |||||
| options: RequestOptions(method: 'GET', headers: <String, dynamic>{}, extra: _extra, baseUrl: baseUrl), | |||||
| data: _data); | data: _data); | ||||
| var value = _result.data | |||||
| .map((dynamic i) => | |||||
| EnvironmentParameter.fromJson(i as Map<String, dynamic>)) | |||||
| .toList(); | |||||
| var value = _result.data.map((dynamic i) => EnvironmentParameter.fromJson(i as Map<String, dynamic>)).toList(); | |||||
| return value; | return value; | ||||
| } | } | ||||
| try { | try { | ||||
| var token = await pref.getString(DATA_CONST.TOKEN_KEY); | var token = await pref.getString(DATA_CONST.TOKEN_KEY); | ||||
| var expiredTime = await pref.getString(DATA_CONST.EXPIRED_TIME); | var expiredTime = await pref.getString(DATA_CONST.EXPIRED_TIME); | ||||
| int currentTime = DateTime.now().millisecondsSinceEpoch; | |||||
| bool isNotExpired = | |||||
| (currentTime - int.tryParse(expiredTime)) < ConstCommon.kExpiredTime; | |||||
| var currentTime = DateTime.now().millisecondsSinceEpoch; | |||||
| var isNotExpired = (currentTime - (int.tryParse(expiredTime) ?? 0)) < ConstCommon.kExpiredTime; | |||||
| if (token.isNotEmpty && isNotExpired) { | if (token.isNotEmpty && isNotExpired) { | ||||
| yield AuthenticationStatus.authenticated; | yield AuthenticationStatus.authenticated; | ||||
| Future<User> signInWithCredentials(String username, String password) { | Future<User> signInWithCredentials(String username, String password) { | ||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var result = | |||||
| client.login(UserRequest(username: username, password: password)); | |||||
| var result = client.login(UserRequest(username: username, password: password)); | |||||
| return result; | return result; | ||||
| } | } | ||||
| Future<List<ActionType>> getActionTypes() { | Future<List<ActionType>> getActionTypes() { | ||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var op = buildConfigurableCacheOptions( | |||||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| return client.getActionTypes(options: op); | return client.getActionTypes(options: op); | ||||
| } | } | ||||
| Future<List<Harvest>> getHarvests() { | Future<List<Harvest>> getHarvests() { | ||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var op = buildConfigurableCacheOptions( | |||||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| return client.getHarvests(options: op); | return client.getHarvests(options: op); | ||||
| } | } | ||||
| Future<List<WaterType>> getWaterTypes() { | Future<List<WaterType>> getWaterTypes() { | ||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var op = buildConfigurableCacheOptions( | |||||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| return client.getWaterTypes(options: op); | return client.getWaterTypes(options: op); | ||||
| } | } | ||||
| Future<CropPlot> getPlotDetail(int cropId, {int page, int size}) { | |||||
| Future<CropPlot> getPlotDetail(int cropId, {int page = 0, int size = 20}) { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| return client.getCropDetail(cropId, page: page, size: size); | return client.getCropDetail(cropId, page: page, size: size); | ||||
| } | } | ||||
| Future<CropPlot> getPlotDetailByCode(String cropCode, {int page, int size}) { | |||||
| Future<CropPlot> getPlotDetailByCode(String cropCode, {int page = 0, int size = 20}) { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| return client.getCropDetailByCode(cropCode, page: page, size: size); | return client.getCropDetailByCode(cropCode, page: page, size: size); | ||||
| } | } | ||||
| Future<List<Crop>> getPlots({int page, int size, String searchString}) { | |||||
| Future<List<Crop>> getPlots({int page = 0, int size = 20, String searchString = ''}) { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| return client.getPlots(page: page, size: size, query: searchString); | return client.getPlots(page: page, size: size, query: searchString); | ||||
| } | } | ||||
| return client.login(UserRequest(username: username, password: password)); | return client.login(UserRequest(username: username, password: password)); | ||||
| } | } | ||||
| Future<PagedResult<T>> getInfinityList<T>(String url, | |||||
| {int page = 0, int size = 20}) async { | |||||
| Future<PagedResult<T>> getInfinityList<T>(String url, {int page = 0, int size = 20}) async { | |||||
| var initUrl = "/api/activities/latest-env-by-activity-type/1/2"; | var initUrl = "/api/activities/latest-env-by-activity-type/1/2"; | ||||
| var url = | |||||
| ConstCommon.baseUrl + initUrl + "?page=$page&paged=true&size=$size"; | |||||
| var url = ConstCommon.baseUrl + initUrl + "?page=$page&paged=true&size=$size"; | |||||
| var response = await dio.get(url); | var response = await dio.get(url); | ||||
| final value = PagedResult<T>.fromJson(response.data, getInstanceClass()); | final value = PagedResult<T>.fromJson(response.data, getInstanceClass()); | ||||
| Future<List<Supply>> getSupplies(String type, {String query = ""}) async { | Future<List<Supply>> getSupplies(String type, {String query = ""}) async { | ||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var op = buildConfigurableCacheOptions( | |||||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| return client.getSupplies(type, query: query, options: op); | return client.getSupplies(type, query: query, options: op); | ||||
| } | } | ||||
| Future<List<Device>> getDeviceForActivity() async { | Future<List<Device>> getDeviceForActivity() async { | ||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var op = buildConfigurableCacheOptions( | |||||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| return client.getDeviceForActivity(options: op); | return client.getDeviceForActivity(options: op); | ||||
| } | } | ||||
| return client.updateNoti(updateNoti); | return client.updateNoti(updateNoti); | ||||
| } | } | ||||
| Future<NotificationObjectDTO> getNotifications( | |||||
| {int page = 0, int size = 20}) async { | |||||
| var url = ConstCommon.baseUrl + | |||||
| "/api/notifications-current-user?page=$page&size=$size&sort=sendDate,DESC"; | |||||
| Future<NotificationObjectDTO> getNotifications({int page = 0, int size = 20}) async { | |||||
| var url = ConstCommon.baseUrl + "/api/notifications-current-user?page=$page&size=$size&sort=sendDate,DESC"; | |||||
| var response = await dio.get(url); | var response = await dio.get(url); | ||||
| final value = NotificationObjectDTO.fromJson(response.data); | final value = NotificationObjectDTO.fromJson(response.data); | ||||
| } | } | ||||
| Future<List<LocationUnit>> getLocationUnits( | Future<List<LocationUnit>> getLocationUnits( | ||||
| {@required LocationType locationType, | |||||
| int filterId, | |||||
| int page = 0, | |||||
| int size = 500, | |||||
| String query = ''}) { | |||||
| {required LocationType locationType, required int filterId, int page = 0, int size = 500, String query = ''}) { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| var op = buildConfigurableCacheOptions( | |||||
| forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| var op = buildConfigurableCacheOptions(forceRefresh: true, maxAge: Duration(days: ConstCommon.kMaxAgeCache)); | |||||
| var response; | var response; | ||||
| switch (locationType) { | switch (locationType) { | ||||
| case LocationType.province: | case LocationType.province: | ||||
| response = client.getProvinces(filterId, | |||||
| options: op, page: page, size: size, query: query); | |||||
| response = client.getProvinces(filterId, options: op, page: page, size: size, query: query); | |||||
| break; | break; | ||||
| case LocationType.district: | case LocationType.district: | ||||
| response = client.getDistricts(filterId, | |||||
| options: op, page: page, size: size, query: query); | |||||
| response = client.getDistricts(filterId, options: op, page: page, size: size, query: query); | |||||
| break; | break; | ||||
| case LocationType.ward: | case LocationType.ward: | ||||
| response = client.getWards(filterId, | |||||
| options: op, page: page, size: size, query: query); | |||||
| response = client.getWards(filterId, options: op, page: page, size: size, query: query); | |||||
| break; | break; | ||||
| default: | default: | ||||
| response = client.getCountries(query: query); | response = client.getCountries(query: query); | ||||
| Object getInstanceClass() { | Object getInstanceClass() { | ||||
| var instanceClass; | var instanceClass; | ||||
| if (1 == 1) { | if (1 == 1) { | ||||
| instanceClass = new Crop(); | |||||
| instanceClass = Crop(); | |||||
| } | } | ||||
| return instanceClass; | return instanceClass; | ||||
| } | } | ||||
| //Action | //Action | ||||
| Future<void> createAction( | |||||
| Function(dynamic) onSuccess, Function(dynamic) onError, | |||||
| {String apiAddAction, | |||||
| String paramActivity, | |||||
| String activityAction, | |||||
| List<String> filePaths}) async { | |||||
| Future<void> createAction(Function(dynamic) onSuccess, Function(dynamic) onError, | |||||
| {required String apiAddAction, required String paramActivity, required String activityAction, required List<String> filePaths}) async { | |||||
| var formData = FormData(); | var formData = FormData(); | ||||
| filePaths.forEach((f) { | filePaths.forEach((f) { | ||||
| formData.files.add(MapEntry("images", MultipartFile.fromFileSync(f))); | formData.files.add(MapEntry("images", MultipartFile.fromFileSync(f))); | ||||
| }); | }); | ||||
| formData.fields.add(MapEntry(paramActivity, activityAction)); | formData.fields.add(MapEntry(paramActivity, activityAction)); | ||||
| try { | try { | ||||
| await dio | |||||
| .post("${ConstCommon.baseUrl}/$apiAddAction", data: formData) | |||||
| .then((value) { | |||||
| await dio.post("${ConstCommon.baseUrl}/$apiAddAction", data: formData).then((value) { | |||||
| onSuccess(value.data); | onSuccess(value.data); | ||||
| }); | }); | ||||
| } on DioError catch (e) { | } on DioError catch (e) { | ||||
| } | } | ||||
| } | } | ||||
| Future<void> updateAction( | |||||
| Function(dynamic) onSuccess, Function(dynamic) onError, | |||||
| {String apiUpdateAction, | |||||
| String paramActivity, | |||||
| String activityAction, | |||||
| List<String> filePaths}) async { | |||||
| Future<void> updateAction(Function(dynamic) onSuccess, Function(dynamic) onError, | |||||
| {required String apiUpdateAction, required String paramActivity, required String activityAction, required List<String> filePaths}) async { | |||||
| var formData = FormData(); | var formData = FormData(); | ||||
| filePaths.forEach((f) { | filePaths.forEach((f) { | ||||
| formData.files.add(MapEntry("images", MultipartFile.fromFileSync(f))); | formData.files.add(MapEntry("images", MultipartFile.fromFileSync(f))); | ||||
| }); | }); | ||||
| formData.fields.add(MapEntry(paramActivity, activityAction)); | formData.fields.add(MapEntry(paramActivity, activityAction)); | ||||
| try { | try { | ||||
| await dio | |||||
| .post("${ConstCommon.baseUrl}/$apiUpdateAction", data: formData) | |||||
| .then((value) { | |||||
| await dio.post("${ConstCommon.baseUrl}/$apiUpdateAction", data: formData).then((value) { | |||||
| onSuccess(value.data); | onSuccess(value.data); | ||||
| }); | }); | ||||
| } on DioError catch (e) { | } on DioError catch (e) { | ||||
| } | } | ||||
| //Environment Parameter | //Environment Parameter | ||||
| Future<List<EnvironmentParameter>> getEnvironmentParameters( | |||||
| {@required int cropId, int page, int size}) { | |||||
| Future<List<EnvironmentParameter>> getEnvironmentParameters({required int cropId, int page = 0, int size = 20}) { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| return client.getEnvironmentParameters(cropId, page: page, size: size); | return client.getEnvironmentParameters(cropId, page: page, size: size); | ||||
| } | } |
| runApp(App(authenticationRepository: AuthenticationRepository())); | runApp(App(authenticationRepository: AuthenticationRepository())); | ||||
| } | } | ||||
| Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) { | |||||
| void myBackgroundMessageHandler(Map<String, dynamic> message) { | |||||
| if (message.containsKey('data')) { | if (message.containsKey('data')) { | ||||
| // Handle data message | // Handle data message | ||||
| final dynamic data = message['data']; | final dynamic data = message['data']; | ||||
| } | } | ||||
| } | } | ||||
| _showAlertCheckCropCode( | |||||
| BuildContext context, String cropCode, Repository repository) async { | |||||
| Get.defaultDialog( | |||||
| title: "Kiểm tra thông tin lô ....", | |||||
| middleText: "", | |||||
| content: CircularProgressIndicator()); | |||||
| _showAlertCheckCropCode(BuildContext context, String cropCode, Repository repository) async { | |||||
| Get.defaultDialog(title: "Kiểm tra thông tin lô ....", middleText: "", content: const CircularProgressIndicator()); | |||||
| try { | try { | ||||
| await repository | |||||
| .getPlotDetailByCode(cropCode, page: 1, size: 1) | |||||
| .then((value) { | |||||
| await repository.getPlotDetailByCode(cropCode, page: 1, size: 1).then((value) { | |||||
| print("ok"); | print("ok"); | ||||
| if (Get.isDialogOpen) Get.back(); | if (Get.isDialogOpen) Get.back(); | ||||
| Get.to(PlotDetailScreen( | |||||
| cropId: value.tbCropDTO.id, | |||||
| cropType: value.tbCropDTO.type, | |||||
| initialIndex: 0)); | |||||
| Get.to(PlotDetailScreen(cropId: value.tbCropDTO?.id ?? -1, cropType: value.tbCropDTO?.type ?? -1, initialIndex: 0)); | |||||
| }).catchError((onError) { | }).catchError((onError) { | ||||
| Utils.showDialog( | Utils.showDialog( | ||||
| title: "Không tìm thấy lô", | title: "Không tìm thấy lô", |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| class ActionType { | |||||
| int? id; | |||||
| String? name; | |||||
| String? description; | |||||
| part 'ActionType.g.dart'; | |||||
| ActionType({this.id, this.name, this.description}); | |||||
| @JsonSerializable() | |||||
| class ActionType { | |||||
| ActionType(); | |||||
| ActionType.fromJson(Map<String, dynamic> json) { | |||||
| id = json['id']; | |||||
| name = json['name']; | |||||
| description = json['description']; | |||||
| } | |||||
| num id; | |||||
| String name; | |||||
| String description; | |||||
| factory ActionType.fromJson(Map<String,dynamic> json) => _$ActionTypeFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$ActionTypeToJson(this); | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['name'] = this.name; | |||||
| data['description'] = this.description; | |||||
| return data; | |||||
| } | |||||
| } | } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'ActionType.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| ActionType _$ActionTypeFromJson(Map<String, dynamic> json) { | |||||
| return ActionType() | |||||
| ..id = json['id'] as num | |||||
| ..name = json['name'] as String | |||||
| ..description = json['description'] as String; | |||||
| } | |||||
| Map<String, dynamic> _$ActionTypeToJson(ActionType instance) => | |||||
| <String, dynamic>{ | |||||
| 'id': instance.id, | |||||
| 'name': instance.name, | |||||
| 'description': instance.description, | |||||
| }; |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| class Crop { | |||||
| num? id; | |||||
| String? qrCode; | |||||
| String? code; | |||||
| double? areaM2; | |||||
| num? type; | |||||
| String? startDate; | |||||
| String? endDate; | |||||
| String? status; | |||||
| String? description; | |||||
| num? ageDayStartAt; | |||||
| num? tbSuppliesId; | |||||
| String? suppliesName; | |||||
| num? tbGuidelineId; | |||||
| num? netHouseId; | |||||
| String? netHouseName; | |||||
| num? areaId; | |||||
| String? area; | |||||
| part 'Crop.g.dart'; | |||||
| Crop( | |||||
| {this.id, | |||||
| this.qrCode, | |||||
| this.code, | |||||
| this.areaM2, | |||||
| this.type, | |||||
| this.startDate, | |||||
| this.endDate, | |||||
| this.status, | |||||
| this.description, | |||||
| this.ageDayStartAt, | |||||
| this.tbSuppliesId, | |||||
| this.suppliesName, | |||||
| this.tbGuidelineId, | |||||
| this.netHouseId, | |||||
| this.netHouseName, | |||||
| this.areaId, | |||||
| this.area}); | |||||
| @JsonSerializable() | |||||
| class Crop { | |||||
| Crop(); | |||||
| Crop.fromJson(Map<String, dynamic> json) { | |||||
| id = json['id']; | |||||
| qrCode = json['qrCode']; | |||||
| code = json['code']; | |||||
| areaM2 = json['areaM2']; | |||||
| type = json['type']; | |||||
| startDate = json['startDate']; | |||||
| endDate = json['endDate']; | |||||
| status = json['status']; | |||||
| description = json['description']; | |||||
| ageDayStartAt = json['ageDayStartAt']; | |||||
| tbSuppliesId = json['tbSuppliesId']; | |||||
| suppliesName = json['suppliesName']; | |||||
| tbGuidelineId = json['tbGuidelineId']; | |||||
| netHouseId = json['netHouseId']; | |||||
| netHouseName = json['netHouseName']; | |||||
| areaId = json['areaId']; | |||||
| area = json['area']; | |||||
| } | |||||
| num id; | |||||
| String qrCode; | |||||
| String code; | |||||
| num areaM2; | |||||
| num type; | |||||
| String startDate; | |||||
| String endDate; | |||||
| String status; | |||||
| String description; | |||||
| num ageDayStartAt; | |||||
| num tbSuppliesId; | |||||
| String suppliesName; | |||||
| num tbGuidelineId; | |||||
| num netHouseId; | |||||
| String netHouseName; | |||||
| num areaId; | |||||
| String area; | |||||
| factory Crop.fromJson(Map<String,dynamic> json) => _$CropFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$CropToJson(this); | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['qrCode'] = this.qrCode; | |||||
| data['code'] = this.code; | |||||
| data['areaM2'] = this.areaM2; | |||||
| data['type'] = this.type; | |||||
| data['startDate'] = this.startDate; | |||||
| data['endDate'] = this.endDate; | |||||
| data['status'] = this.status; | |||||
| data['description'] = this.description; | |||||
| data['ageDayStartAt'] = this.ageDayStartAt; | |||||
| data['tbSuppliesId'] = this.tbSuppliesId; | |||||
| data['suppliesName'] = this.suppliesName; | |||||
| data['tbGuidelineId'] = this.tbGuidelineId; | |||||
| data['netHouseId'] = this.netHouseId; | |||||
| data['netHouseName'] = this.netHouseName; | |||||
| data['areaId'] = this.areaId; | |||||
| data['area'] = this.area; | |||||
| return data; | |||||
| } | |||||
| } | } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'Crop.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| Crop _$CropFromJson(Map<String, dynamic> json) { | |||||
| return Crop() | |||||
| ..id = json['id'] as num | |||||
| ..qrCode = json['qrCode'] as String | |||||
| ..code = json['code'] as String | |||||
| ..areaM2 = json['areaM2'] as num | |||||
| ..type = json['type'] as num | |||||
| ..startDate = json['startDate'] as String | |||||
| ..endDate = json['endDate'] as String | |||||
| ..status = json['status'] as String | |||||
| ..description = json['description'] as String | |||||
| ..ageDayStartAt = json['ageDayStartAt'] as num | |||||
| ..tbSuppliesId = json['tbSuppliesId'] as num | |||||
| ..suppliesName = json['suppliesName'] as String | |||||
| ..tbGuidelineId = json['tbGuidelineId'] as num | |||||
| ..netHouseId = json['netHouseId'] as num | |||||
| ..netHouseName = json['netHouseName'] as String | |||||
| ..areaId = json['areaId'] as num | |||||
| ..area = json['area'] as String; | |||||
| } | |||||
| Map<String, dynamic> _$CropToJson(Crop instance) => <String, dynamic>{ | |||||
| 'id': instance.id, | |||||
| 'qrCode': instance.qrCode, | |||||
| 'code': instance.code, | |||||
| 'areaM2': instance.areaM2, | |||||
| 'type': instance.type, | |||||
| 'startDate': instance.startDate, | |||||
| 'endDate': instance.endDate, | |||||
| 'status': instance.status, | |||||
| 'description': instance.description, | |||||
| 'ageDayStartAt': instance.ageDayStartAt, | |||||
| 'tbSuppliesId': instance.tbSuppliesId, | |||||
| 'suppliesName': instance.suppliesName, | |||||
| 'tbGuidelineId': instance.tbGuidelineId, | |||||
| 'netHouseId': instance.netHouseId, | |||||
| 'netHouseName': instance.netHouseName, | |||||
| 'areaId': instance.areaId, | |||||
| 'area': instance.area, | |||||
| }; |
| class PagedResult<T> { | class PagedResult<T> { | ||||
| final int totalElements; | |||||
| final int? totalElements; | |||||
| final List<T> results; | final List<T> results; | ||||
| PagedResult({this.totalElements, this.results}); | |||||
| PagedResult({this.totalElements, required this.results}); | |||||
| factory PagedResult.fromJson(Map<String, dynamic> json, object) { | factory PagedResult.fromJson(Map<String, dynamic> json, object) { | ||||
| final items = json['content'].cast<Map<String, dynamic>>(); | final items = json['content'].cast<Map<String, dynamic>>(); | ||||
| final listItems = | final listItems = | ||||
| new List<T>.from(items.map((itemsJson) => object.fromJson(itemsJson))); | |||||
| List<T>.from(items.map((itemsJson) => object.fromJson(itemsJson))); | |||||
| final total = json['totalElements'] as num; | final total = json['totalElements'] as num; | ||||
| return PagedResult<T>(totalElements: total, results: listItems); | |||||
| return PagedResult<T>(totalElements: total.toInt(), results: listItems); | |||||
| } | } | ||||
| } | } |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| class ResourceHelper { | |||||
| int? id; | |||||
| String? name; | |||||
| String? description; | |||||
| bool? isSelected; | |||||
| part 'ResourceHelper.g.dart'; | |||||
| ResourceHelper({this.id, this.name, this.description, this.isSelected}); | |||||
| @JsonSerializable() | |||||
| class ResourceHelper { | |||||
| ResourceHelper(); | |||||
| ResourceHelper.fromJson(Map<String, dynamic> json) { | |||||
| id = json['id']; | |||||
| name = json['name']; | |||||
| description = json['description']; | |||||
| isSelected = json['isSelected']; | |||||
| } | |||||
| num id; | |||||
| String name; | |||||
| String description; | |||||
| bool isSelected; | |||||
| factory ResourceHelper.fromJson(Map<String,dynamic> json) => _$ResourceHelperFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$ResourceHelperToJson(this); | |||||
| Map<String, dynamic> toJson() { | |||||
| final Map<String, dynamic> data = new Map<String, dynamic>(); | |||||
| data['id'] = this.id; | |||||
| data['name'] = this.name; | |||||
| data['description'] = this.description; | |||||
| data['isSelected'] = this.isSelected; | |||||
| return data; | |||||
| } | |||||
| } | } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'ResourceHelper.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| ResourceHelper _$ResourceHelperFromJson(Map<String, dynamic> json) { | |||||
| return ResourceHelper() | |||||
| ..id = json['id'] as num | |||||
| ..name = json['name'] as String | |||||
| ..description = json['description'] as String | |||||
| ..isSelected = json['isSelected'] as bool; | |||||
| } | |||||
| Map<String, dynamic> _$ResourceHelperToJson(ResourceHelper instance) => | |||||
| <String, dynamic>{ | |||||
| 'id': instance.id, | |||||
| 'name': instance.name, | |||||
| 'description': instance.description, | |||||
| 'isSelected': instance.isSelected, | |||||
| }; |
| class AppBarWidget extends StatelessWidget implements PreferredSizeWidget { | class AppBarWidget extends StatelessWidget implements PreferredSizeWidget { | ||||
| final bool isBack; | final bool isBack; | ||||
| final Widget action; | |||||
| final Widget? action; | |||||
| AppBarWidget({this.isBack = true, this.action}); | AppBarWidget({this.isBack = true, this.action}); | ||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| Text( | Text( | ||||
| 'Quay lại', | 'Quay lại', | ||||
| maxLines: 1, | maxLines: 1, | ||||
| style: TextStyle( | |||||
| color: AppColors.YELLOW, | |||||
| fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: AppColors.YELLOW, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| SizedBox(width: 4), | |||||
| const SizedBox(width: 4), | |||||
| Expanded( | Expanded( | ||||
| child: Align( | child: Align( | ||||
| alignment: Alignment.centerRight, | alignment: Alignment.centerRight, | ||||
| child: action ?? SizedBox(), | |||||
| child: action ?? const SizedBox(), | |||||
| )) | )) | ||||
| ], | ], | ||||
| ), | ), | ||||
| Get.back(); | Get.back(); | ||||
| }, | }, | ||||
| ) | ) | ||||
| : SizedBox(), | |||||
| : const SizedBox(), | |||||
| automaticallyImplyLeading: false, | automaticallyImplyLeading: false, | ||||
| actions: [SizedBox()], | |||||
| actions: [const SizedBox()], | |||||
| ), | ), | ||||
| ); | ); | ||||
| } | } |
| class ChangeListMedia extends MediaHelperEvent { | class ChangeListMedia extends MediaHelperEvent { | ||||
| final List<Media> items; | final List<Media> items; | ||||
| ChangeListMedia({@required this.items}); | |||||
| ChangeListMedia({required this.items}); | |||||
| } | } |
| class MediaHelperFailure extends MediaHelperState { | class MediaHelperFailure extends MediaHelperState { | ||||
| final String errorString; | final String errorString; | ||||
| MediaHelperFailure({@required this.errorString}); | |||||
| MediaHelperFailure({required this.errorString}); | |||||
| } | } | ||||
| class MediaHelperSuccess extends MediaHelperState { | class MediaHelperSuccess extends MediaHelperState { | ||||
| final List<Media> items; | final List<Media> items; | ||||
| const MediaHelperSuccess({@required this.items}); | |||||
| const MediaHelperSuccess({required this.items}); | |||||
| MediaHelperSuccess copyWith({List<Media> items}) { | |||||
| MediaHelperSuccess copyWith({List<Media>? items}) { | |||||
| return MediaHelperSuccess(items: items ?? this.items); | return MediaHelperSuccess(items: items ?? this.items); | ||||
| } | } | ||||
| final Color color; | final Color color; | ||||
| final String name; | final String name; | ||||
| final String value; | final String value; | ||||
| WidgetRowPlotInfo( | |||||
| {@required this.color, @required this.name, @required this.value}); | |||||
| WidgetRowPlotInfo({required this.color, required this.name, required this.value}); | |||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return Container( | return Container( | ||||
| children: [ | children: [ | ||||
| Expanded( | Expanded( | ||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.all(12), | |||||
| padding: const EdgeInsets.all(12), | |||||
| child: Text( | child: Text( | ||||
| name, | name, | ||||
| style: TextStyle(fontSize: 16), | |||||
| style: const TextStyle(fontSize: 16), | |||||
| ), | ), | ||||
| ), | ), | ||||
| ), | ), | ||||
| ), | ), | ||||
| Expanded( | Expanded( | ||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.all(12), | |||||
| child: Text(value ?? '--', | |||||
| textAlign: TextAlign.end, | |||||
| style: TextStyle(fontSize: 16))), | |||||
| padding: const EdgeInsets.all(12), child: Text(value ?? '--', textAlign: TextAlign.end, style: const TextStyle(fontSize: 16))), | |||||
| ), | ), | ||||
| ], | ], | ||||
| ), | ), |
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return Container( | return Container( | ||||
| alignment: Alignment.center, | alignment: Alignment.center, | ||||
| child: Center( | |||||
| child: const Center( | |||||
| child: SizedBox( | child: SizedBox( | ||||
| width: 33, | width: 33, | ||||
| height: 33, | height: 33, |
| class ButtonIconWidget extends StatelessWidget { | class ButtonIconWidget extends StatelessWidget { | ||||
| final String title; | final String title; | ||||
| final TextStyle titleStyle; | |||||
| final String subTitle; | |||||
| final TextStyle? titleStyle; | |||||
| final String? subTitle; | |||||
| final Function onTap; | final Function onTap; | ||||
| final String leadingIcon; | |||||
| final String trailingIcon; | |||||
| final String? leadingIcon; | |||||
| final String? trailingIcon; | |||||
| final bool isTopBorder; | final bool isTopBorder; | ||||
| final bool isBottomBorder; | final bool isBottomBorder; | ||||
| ButtonIconWidget( | ButtonIconWidget( | ||||
| {@required this.title, | |||||
| @required this.onTap, | |||||
| {required this.title, | |||||
| required this.onTap, | |||||
| this.titleStyle, | this.titleStyle, | ||||
| this.subTitle, | this.subTitle, | ||||
| this.leadingIcon, | this.leadingIcon, | ||||
| return SizedBox( | return SizedBox( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: MaterialButton( | child: MaterialButton( | ||||
| padding: EdgeInsets.all(0), | |||||
| onPressed: onTap, | |||||
| padding: const EdgeInsets.all(0), | |||||
| onPressed: () { | |||||
| onTap(); | |||||
| }, | |||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.all(12), | |||||
| padding: const EdgeInsets.all(12), | |||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| border: Border( | border: Border( | ||||
| top: isTopBorder | |||||
| ? BorderSide(color: AppColors.GRAY1, width: 0.35) | |||||
| : BorderSide.none, | |||||
| bottom: isBottomBorder | |||||
| ? BorderSide(color: AppColors.GRAY1, width: 0.35) | |||||
| : BorderSide.none)), | |||||
| top: isTopBorder ? BorderSide(color: AppColors.GRAY1, width: 0.35) : BorderSide.none, | |||||
| bottom: isBottomBorder ? BorderSide(color: AppColors.GRAY1, width: 0.35) : BorderSide.none)), | |||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Row( | child: Row( | ||||
| mainAxisSize: MainAxisSize.max, | mainAxisSize: MainAxisSize.max, | ||||
| children: [ | children: [ | ||||
| leadingIcon == null | |||||
| ? SizedBox() | |||||
| : SizedBox( | |||||
| width: 20, | |||||
| height: 20, | |||||
| child: SvgPicture.asset(leadingIcon)), | |||||
| SizedBox(width: 4), | |||||
| leadingIcon == null ? const SizedBox() : SizedBox(width: 20, height: 20, child: SvgPicture.asset(leadingIcon)), | |||||
| const SizedBox(width: 4), | |||||
| Expanded( | Expanded( | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, | ||||
| children: [ | children: [ | ||||
| Text( | Text( | ||||
| title, | title, | ||||
| style: titleStyle ?? | |||||
| TextStyle(fontSize: 16, fontWeight: FontWeight.w100), | |||||
| style: titleStyle ?? const TextStyle(fontSize: 16, fontWeight: FontWeight.w100), | |||||
| ), | ), | ||||
| subTitle == null | subTitle == null | ||||
| ? SizedBox() | |||||
| ? const SizedBox() | |||||
| : Text( | : Text( | ||||
| subTitle, | |||||
| style: TextStyle(fontSize: 14), | |||||
| subTitle ?? '', | |||||
| style: const TextStyle(fontSize: 14), | |||||
| ) | ) | ||||
| ], | ], | ||||
| ), | ), | ||||
| ), | ), | ||||
| trailingIcon == null ? SizedBox() : SvgPicture.asset(trailingIcon) | |||||
| trailingIcon == null ? const SizedBox() : SvgPicture.asset(trailingIcon) | |||||
| ], | ], | ||||
| ), | ), | ||||
| ), | ), |
| class ButtonWidget extends StatelessWidget { | class ButtonWidget extends StatelessWidget { | ||||
| final Function onPressed; | final Function onPressed; | ||||
| final String title; | final String title; | ||||
| ButtonWidget({@required this.title, @required this.onPressed}); | |||||
| ButtonWidget({required this.title, required this.onPressed}); | |||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return SizedBox( | return SizedBox( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| height: 55, | height: 55, | ||||
| child: FlatButton( | child: FlatButton( | ||||
| onPressed: onPressed, | |||||
| onPressed: () { | |||||
| onPressed(); | |||||
| }, | |||||
| color: AppColors.DEFAULT, | color: AppColors.DEFAULT, | ||||
| shape: RoundedRectangleBorder( | shape: RoundedRectangleBorder( | ||||
| borderRadius: new BorderRadius.circular(7.0), | |||||
| borderRadius: BorderRadius.circular(7.0), | |||||
| ), | ), | ||||
| child: Text(title.toUpperCase(), | |||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.bold, | |||||
| color: AppColors.WHITE, | |||||
| fontSize: 18)), | |||||
| child: Text(title.toUpperCase(), style: TextStyle(fontWeight: FontWeight.bold, color: AppColors.WHITE, fontSize: 18)), | |||||
| ), | ), | ||||
| ); | ); | ||||
| } | } |
| throw ArgumentError('Unknown lens direction'); | throw ArgumentError('Unknown lens direction'); | ||||
| } | } | ||||
| void logError(String code, String message) => | |||||
| print('Error: $code\nError Message: $message'); | |||||
| class _CameraHelperState extends State<CameraHelper> | |||||
| with WidgetsBindingObserver { | |||||
| CameraController controller; | |||||
| String imagePath; | |||||
| String videoPath; | |||||
| VideoPlayerController videoController; | |||||
| VoidCallback videoPlayerListener; | |||||
| void logError(String code, String message) => print('Error: $code\nError Message: $message'); | |||||
| class _CameraHelperState extends State<CameraHelper> with WidgetsBindingObserver { | |||||
| late CameraController controller; | |||||
| String? imagePath; | |||||
| String? videoPath; | |||||
| VideoPlayerController? videoController; | |||||
| VoidCallback? videoPlayerListener; | |||||
| bool enableAudio = true; | bool enableAudio = true; | ||||
| int indexCamera = 0; | int indexCamera = 0; | ||||
| @override | @override | ||||
| void initState() { | void initState() { | ||||
| super.initState(); | super.initState(); | ||||
| controller = | |||||
| CameraController(cameras[indexCamera], ResolutionPreset.medium); | |||||
| controller = CameraController(cameras[indexCamera], ResolutionPreset.medium); | |||||
| controller.initialize().then((_) { | controller.initialize().then((_) { | ||||
| if (!mounted) { | if (!mounted) { | ||||
| return; | return; | ||||
| } | } | ||||
| setState(() {}); | setState(() {}); | ||||
| }); | }); | ||||
| WidgetsBinding.instance.addObserver(this); | |||||
| WidgetsBinding.instance?.addObserver(this); | |||||
| } | } | ||||
| @override | @override | ||||
| void dispose() { | void dispose() { | ||||
| WidgetsBinding.instance.removeObserver(this); | |||||
| WidgetsBinding.instance?.removeObserver(this); | |||||
| super.dispose(); | super.dispose(); | ||||
| } | } | ||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| color: Colors.black, | color: Colors.black, | ||||
| border: Border.all( | border: Border.all( | ||||
| color: | |||||
| controller != null && controller.value.isRecordingVideo | |||||
| ? Colors.redAccent | |||||
| : Colors.grey, | |||||
| width: | |||||
| controller != null && controller.value.isRecordingVideo | |||||
| ? 1.0 | |||||
| : 0.0, | |||||
| color: controller != null && controller.value.isRecordingVideo ? Colors.redAccent : Colors.grey, | |||||
| width: controller != null && controller.value.isRecordingVideo ? 1.0 : 0.0, | |||||
| ), | ), | ||||
| ), | ), | ||||
| ), | ), | ||||
| mainAxisSize: MainAxisSize.max, | mainAxisSize: MainAxisSize.max, | ||||
| children: <Widget>[ | children: <Widget>[ | ||||
| IconButton( | IconButton( | ||||
| icon: Icon(Icons.arrow_back), | |||||
| icon: const Icon(Icons.arrow_back), | |||||
| onPressed: () { | onPressed: () { | ||||
| Get.back(); | Get.back(); | ||||
| }), | }), | ||||
| size: 30, | size: 30, | ||||
| ), | ), | ||||
| color: Colors.blue, | color: Colors.blue, | ||||
| onPressed: controller != null && | |||||
| controller.value.isInitialized && | |||||
| !controller.value.isRecordingVideo | |||||
| ? onTakePictureButtonPressed | |||||
| : null, | |||||
| onPressed: controller != null && controller.value.isInitialized && !controller.value.isRecordingVideo ? onTakePictureButtonPressed : null, | |||||
| ), | ), | ||||
| IconButton( | IconButton( | ||||
| icon: const Icon(Icons.videocam, size: 35), | icon: const Icon(Icons.videocam, size: 35), | ||||
| color: Colors.blue, | color: Colors.blue, | ||||
| onPressed: controller != null && | |||||
| controller.value.isInitialized && | |||||
| !controller.value.isRecordingVideo | |||||
| ? onVideoRecordButtonPressed | |||||
| : null, | |||||
| onPressed: controller != null && controller.value.isInitialized && !controller.value.isRecordingVideo ? onVideoRecordButtonPressed : null, | |||||
| ), | ), | ||||
| IconButton( | IconButton( | ||||
| icon: controller != null && controller.value.isRecordingPaused | |||||
| ? Icon(Icons.play_arrow) | |||||
| : Icon(Icons.pause), | |||||
| icon: controller != null && controller.value.isRecordingPaused ? const Icon(Icons.play_arrow) : const Icon(Icons.pause), | |||||
| color: Colors.blue, | color: Colors.blue, | ||||
| onPressed: controller != null && | |||||
| controller.value.isInitialized && | |||||
| controller.value.isRecordingVideo | |||||
| ? (controller != null && controller.value.isRecordingPaused | |||||
| ? onResumeButtonPressed | |||||
| : onPauseButtonPressed) | |||||
| onPressed: controller != null && controller.value.isInitialized && controller.value.isRecordingVideo | |||||
| ? (controller != null && controller.value.isRecordingPaused ? onResumeButtonPressed : onPauseButtonPressed) | |||||
| : null, | : null, | ||||
| ), | ), | ||||
| IconButton( | IconButton( | ||||
| icon: const Icon(Icons.stop), | icon: const Icon(Icons.stop), | ||||
| color: Colors.red, | color: Colors.red, | ||||
| onPressed: controller != null && | |||||
| controller.value.isInitialized && | |||||
| controller.value.isRecordingVideo | |||||
| ? onStopButtonPressed | |||||
| : null, | |||||
| onPressed: controller != null && controller.value.isInitialized && controller.value.isRecordingVideo ? onStopButtonPressed : null, | |||||
| ) | ) | ||||
| ], | ], | ||||
| ); | ); | ||||
| if (cameras.isEmpty) { | if (cameras.isEmpty) { | ||||
| return const Text('Không có camera'); | return const Text('Không có camera'); | ||||
| } else { | } else { | ||||
| bool disableSwitch = | |||||
| controller != null && controller.value.isRecordingVideo; | |||||
| var disableSwitch = controller != null && controller.value.isRecordingVideo; | |||||
| if (indexCamera == cameras.length - 1) { | if (indexCamera == cameras.length - 1) { | ||||
| indexCamera = 0; | indexCamera = 0; | ||||
| } else { | } else { | ||||
| indexCamera++; | indexCamera++; | ||||
| } | } | ||||
| return IconButton( | return IconButton( | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.switch_camera, | Icons.switch_camera, | ||||
| color: Colors.green, | color: Colors.green, | ||||
| ), | ), | ||||
| setState(() { | setState(() { | ||||
| imagePath = filePath; | imagePath = filePath; | ||||
| videoController?.dispose(); | videoController?.dispose(); | ||||
| videoController = null; | |||||
| // videoController = null; | |||||
| }); | }); | ||||
| if (filePath != null) { | if (filePath != null) { | ||||
| print('Picture saved to $filePath'); | print('Picture saved to $filePath'); | ||||
| Future<String> startVideoRecording() async { | Future<String> startVideoRecording() async { | ||||
| if (!controller.value.isInitialized) { | if (!controller.value.isInitialized) { | ||||
| showInSnackBar('Vui lòng chọn camera'); | showInSnackBar('Vui lòng chọn camera'); | ||||
| return null; | |||||
| // return null; | |||||
| } | } | ||||
| final Directory extDir = await getApplicationDocumentsDirectory(); | final Directory extDir = await getApplicationDocumentsDirectory(); | ||||
| final String dirPath = '${extDir.path}/Movies/tpf'; | |||||
| final dirPath = '${extDir.path}/Movies/tpf'; | |||||
| await Directory(dirPath).create(recursive: true); | await Directory(dirPath).create(recursive: true); | ||||
| final String filePath = '$dirPath/${timestamp()}.mp4'; | |||||
| final filePath = '$dirPath/${timestamp()}.mp4'; | |||||
| if (controller.value.isRecordingVideo) { | if (controller.value.isRecordingVideo) { | ||||
| // A recording is already started, do nothing. | // A recording is already started, do nothing. | ||||
| return null; | |||||
| // return null; | |||||
| } | } | ||||
| try { | try { | ||||
| await controller.startVideoRecording(filePath); | await controller.startVideoRecording(filePath); | ||||
| } on CameraException catch (e) { | } on CameraException catch (e) { | ||||
| _showCameraException(e); | _showCameraException(e); | ||||
| return null; | |||||
| // return null; | |||||
| } | } | ||||
| return filePath; | return filePath; | ||||
| } | } | ||||
| Future<String> takePicture() async { | Future<String> takePicture() async { | ||||
| if (!controller.value.isInitialized) { | if (!controller.value.isInitialized) { | ||||
| showInSnackBar('Vui lòng chọn camera'); | showInSnackBar('Vui lòng chọn camera'); | ||||
| return null; | |||||
| // return null; | |||||
| } | } | ||||
| final Directory extDir = await getApplicationDocumentsDirectory(); | final Directory extDir = await getApplicationDocumentsDirectory(); | ||||
| final String dirPath = '${extDir.path}/Pictures/tpf'; | |||||
| final dirPath = '${extDir.path}/Pictures/tpf'; | |||||
| await Directory(dirPath).create(recursive: true); | await Directory(dirPath).create(recursive: true); | ||||
| final String filePath = '$dirPath/${timestamp()}.jpg'; | |||||
| final filePath = '$dirPath/${timestamp()}.jpg'; | |||||
| if (controller.value.isTakingPicture) { | if (controller.value.isTakingPicture) { | ||||
| // A capture is already pending, do nothing. | // A capture is already pending, do nothing. | ||||
| return null; | |||||
| // return null; | |||||
| } | } | ||||
| try { | try { | ||||
| await controller.takePicture(filePath); | await controller.takePicture(filePath); | ||||
| } on CameraException catch (e) { | } on CameraException catch (e) { | ||||
| _showCameraException(e); | _showCameraException(e); | ||||
| return null; | |||||
| // return null; | |||||
| } | } | ||||
| return filePath; | return filePath; | ||||
| } | } |
| IndexedWidgetBuilder separatorBuilder; | IndexedWidgetBuilder separatorBuilder; | ||||
| WrapContentHozListView({ | WrapContentHozListView({ | ||||
| @required this.list, | |||||
| @required this.itemBuilder, | |||||
| this.separatorBuilder, | |||||
| required this.list, | |||||
| required this.itemBuilder, | |||||
| required this.separatorBuilder, | |||||
| }); | }); | ||||
| @override | @override | ||||
| class _WrapContentHozListViewState extends State<WrapContentHozListView> { | class _WrapContentHozListViewState extends State<WrapContentHozListView> { | ||||
| List<Widget> _generateItemWidgets() { | List<Widget> _generateItemWidgets() { | ||||
| List<Widget> items = []; | |||||
| for (int i = 0; i < widget.list.length; i++) { | |||||
| var items = <Widget>[]; | |||||
| for (var i = 0; i < widget.list.length; i++) { | |||||
| items.add(widget.itemBuilder(context, i)); | items.add(widget.itemBuilder(context, i)); | ||||
| if (widget.separatorBuilder != null) { | if (widget.separatorBuilder != null) { | ||||
| items.add(widget.separatorBuilder(context, i)); | items.add(widget.separatorBuilder(context, i)); | ||||
| return SingleChildScrollView( | return SingleChildScrollView( | ||||
| reverse: false, | reverse: false, | ||||
| scrollDirection: Axis.horizontal, | scrollDirection: Axis.horizontal, | ||||
| physics: BouncingScrollPhysics(), | |||||
| physics: const BouncingScrollPhysics(), | |||||
| child: Row( | child: Row( | ||||
| mainAxisAlignment: MainAxisAlignment.start, | mainAxisAlignment: MainAxisAlignment.start, | ||||
| crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, |
| class ShimmerImage extends StatelessWidget { | class ShimmerImage extends StatelessWidget { | ||||
| String url; | String url; | ||||
| BoxFit fit; | |||||
| double width; | |||||
| double height; | |||||
| double aspectRatio; | |||||
| double iconHolderSize = 40; | |||||
| BoxFit? fit; | |||||
| double? width; | |||||
| double? height; | |||||
| double? aspectRatio; | |||||
| double? iconHolderSize = 40; | |||||
| ShimmerImage( | ShimmerImage( | ||||
| this.url, { | this.url, { | ||||
| Shimmer.fromColors( | Shimmer.fromColors( | ||||
| baseColor: Colors.grey[200], | baseColor: Colors.grey[200], | ||||
| highlightColor: Colors.grey[100], | highlightColor: Colors.grey[100], | ||||
| child: this.aspectRatio != null | |||||
| child: aspectRatio != null | |||||
| ? AspectRatio( | ? AspectRatio( | ||||
| aspectRatio: aspectRatio, | |||||
| aspectRatio: aspectRatio ?? 1, | |||||
| child: Container( | child: Container( | ||||
| child: _buildIcon(), | child: _buildIcon(), | ||||
| ), | ), | ||||
| ) | ) | ||||
| : Container( | : Container( | ||||
| width: this.width, | |||||
| height: this.height, | |||||
| width: width, | |||||
| height: height, | |||||
| child: _buildIcon(), | child: _buildIcon(), | ||||
| ), | ), | ||||
| ), | ), | ||||
| this.aspectRatio != null | |||||
| aspectRatio != null | |||||
| ? AspectRatio( | ? AspectRatio( | ||||
| aspectRatio: aspectRatio, | |||||
| aspectRatio: aspectRatio ?? 1, | |||||
| child: Image.network( | child: Image.network( | ||||
| url, | url, | ||||
| fit: fit ?? BoxFit.contain, | fit: fit ?? BoxFit.contain, | ||||
| ) | ) | ||||
| : Image.network( | : Image.network( | ||||
| url, | url, | ||||
| width: this.width, | |||||
| height: this.height, | |||||
| width: width, | |||||
| height: height, | |||||
| fit: fit ?? BoxFit.contain, | fit: fit ?? BoxFit.contain, | ||||
| ), | ), | ||||
| ], | ], |
| class WidgetFieldDateTimePicker extends StatefulWidget { | class WidgetFieldDateTimePicker extends StatefulWidget { | ||||
| final DateTime initDateTime; | final DateTime initDateTime; | ||||
| final Function(DateTime selectedDateTimeLocal) onUpdateDateTime; | final Function(DateTime selectedDateTimeLocal) onUpdateDateTime; | ||||
| WidgetFieldDateTimePicker( | |||||
| {@required this.initDateTime, @required this.onUpdateDateTime}); | |||||
| WidgetFieldDateTimePicker({required this.initDateTime, required this.onUpdateDateTime}); | |||||
| @override | @override | ||||
| _WidgetFieldDateTimePickerState createState() => | |||||
| _WidgetFieldDateTimePickerState(); | |||||
| _WidgetFieldDateTimePickerState createState() => _WidgetFieldDateTimePickerState(); | |||||
| } | } | ||||
| class _WidgetFieldDateTimePickerState extends State<WidgetFieldDateTimePicker> { | class _WidgetFieldDateTimePickerState extends State<WidgetFieldDateTimePicker> { | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return GetBuilder<ChangeDateTimePicker>(builder: (value) { | return GetBuilder<ChangeDateTimePicker>(builder: (value) { | ||||
| return FlatButton( | return FlatButton( | ||||
| padding: | |||||
| EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| onPressed: () { | onPressed: () { | ||||
| DatePicker.showDateTimePicker(context, | |||||
| showTitleActions: true, | |||||
| onChanged: (date) {}, onConfirm: (date) { | |||||
| DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {}, onConfirm: (date) { | |||||
| changeDate.change(date); | changeDate.change(date); | ||||
| widget.onUpdateDateTime(date); | widget.onUpdateDateTime(date); | ||||
| }, currentTime: value.selectedDateTime, locale: LocaleType.vi); | }, currentTime: value.selectedDateTime, locale: LocaleType.vi); | ||||
| }, | }, | ||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.only( | |||||
| top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: BoxDecoration( | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: const BoxDecoration( | |||||
| border: kBorderTextField, | border: kBorderTextField, | ||||
| ), | ), | ||||
| child: Row( | child: Row( | ||||
| Expanded( | Expanded( | ||||
| child: Text( | child: Text( | ||||
| value.selectedDateTime.displayDateTime_DDMMYYYY_HHmm(), | value.selectedDateTime.displayDateTime_DDMMYYYY_HHmm(), | ||||
| style: TextStyle(fontSize: 14.0, color: Colors.black87), | |||||
| style: const TextStyle(fontSize: 14.0, color: Colors.black87), | |||||
| )), | )), | ||||
| Icon( | |||||
| const Icon( | |||||
| Icons.date_range, | Icons.date_range, | ||||
| color: Colors.grey, | color: Colors.grey, | ||||
| ), | ), | ||||
| } | } | ||||
| class ChangeDateTimePicker extends GetxController { | class ChangeDateTimePicker extends GetxController { | ||||
| DateTime selectedDateTime; | |||||
| initValue({DateTime selectedDate}) { | |||||
| DateTime selectedDateTime = DateTime.now(); | |||||
| initValue({DateTime? selectedDate}) { | |||||
| selectedDateTime = selectedDate ?? DateTime.now(); | selectedDateTime = selectedDate ?? DateTime.now(); | ||||
| update(); | update(); | ||||
| } | } |
| Align( | Align( | ||||
| alignment: Alignment.center, | alignment: Alignment.center, | ||||
| child: Container( | child: Container( | ||||
| decoration: new BoxDecoration( | |||||
| decoration: BoxDecoration( | |||||
| color: Colors.white, | color: Colors.white, | ||||
| borderRadius: | borderRadius: | ||||
| new BorderRadius.all(Radius.circular(16.0))), | |||||
| const BorderRadius.all(Radius.circular(16.0))), | |||||
| width: 80.0, | width: 80.0, | ||||
| height: 80.0), | height: 80.0), | ||||
| ), | ), | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| alignment: Alignment.center, | alignment: Alignment.center, | ||||
| child: SizedBox( | |||||
| child: const SizedBox( | |||||
| child: CircularProgressIndicator( | child: CircularProgressIndicator( | ||||
| strokeWidth: 2.0, | strokeWidth: 2.0, | ||||
| ), | ), |
| import 'hoz_list_view.dart'; | import 'hoz_list_view.dart'; | ||||
| class WidgetMediaPicker extends StatefulWidget { | class WidgetMediaPicker extends StatefulWidget { | ||||
| final List<Media> currentItems; | |||||
| final Function(List<String> addNewFilePaths, List<String> deleteFilePaths) | |||||
| onChangeFiles; | |||||
| WidgetMediaPicker({this.currentItems, @required this.onChangeFiles}); | |||||
| final List<Media>? currentItems; | |||||
| final Function(List<String> addNewFilePaths, List<String> deleteFilePaths) onChangeFiles; | |||||
| WidgetMediaPicker({this.currentItems, required this.onChangeFiles}); | |||||
| @override | @override | ||||
| _WidgetMediaPickerState createState() => _WidgetMediaPickerState(); | _WidgetMediaPickerState createState() => _WidgetMediaPickerState(); | ||||
| } | } | ||||
| class _WidgetMediaPickerState extends State<WidgetMediaPicker> { | class _WidgetMediaPickerState extends State<WidgetMediaPicker> { | ||||
| List<Media> currentItems = []; | List<Media> currentItems = []; | ||||
| List<String> addNewFilePaths = new List<String>(); | |||||
| List<String> deleteFilePaths = new List<String>(); | |||||
| List<String> addNewFilePaths = <String>[]; | |||||
| List<String> deleteFilePaths = <String>[]; | |||||
| @override | @override | ||||
| void initState() { | void initState() { | ||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return BlocProvider<MediaHelperBloc>( | return BlocProvider<MediaHelperBloc>( | ||||
| create: (BuildContext contextA) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: currentItems)), | |||||
| child: BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (contextB, state) { | |||||
| create: (BuildContext contextA) => MediaHelperBloc()..add(ChangeListMedia(items: currentItems)), | |||||
| child: BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (contextB, state) { | |||||
| if (state is MediaHelperFailure) { | if (state is MediaHelperFailure) { | ||||
| return Container(); | return Container(); | ||||
| } else if (state is MediaHelperSuccess) { | } else if (state is MediaHelperSuccess) { | ||||
| currentItems = widget.currentItems ?? []; | currentItems = widget.currentItems ?? []; | ||||
| return Container( | return Container( | ||||
| padding: EdgeInsets.all(8), | |||||
| padding: const EdgeInsets.all(8), | |||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, | ||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text('Hình ảnh/ Video', | |||||
| style: TextStyle(color: Colors.black54, fontSize: 16)), | |||||
| SizedBox( | |||||
| const Text('Hình ảnh/ Video', style: TextStyle(color: Colors.black54, fontSize: 16)), | |||||
| const SizedBox( | |||||
| height: 8, | height: 8, | ||||
| ), | ), | ||||
| Row( | Row( | ||||
| )); | )); | ||||
| }, | }, | ||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| width: 8.0, | width: 8.0, | ||||
| ), | ), | ||||
| Expanded( | Expanded( | ||||
| Widget multipleChoice(BuildContext context) { | Widget multipleChoice(BuildContext context) { | ||||
| return CupertinoAlertDialog( | return CupertinoAlertDialog( | ||||
| title: Text(label_title_select_media), | |||||
| title: const Text(label_title_select_media), | |||||
| actions: <Widget>[ | actions: <Widget>[ | ||||
| CupertinoDialogAction( | CupertinoDialogAction( | ||||
| child: const Text(label_take_photo_or_video), | child: const Text(label_take_photo_or_video), | ||||
| onPressed: () { | onPressed: () { | ||||
| Navigator.pop(context, 'Discard'); | Navigator.pop(context, 'Discard'); | ||||
| Navigator.of(context) | |||||
| .push(MaterialPageRoute(builder: (context) => CameraHelper())) | |||||
| .then((value) { | |||||
| Navigator.of(context).push(MaterialPageRoute(builder: (context) => CameraHelper())).then((value) { | |||||
| if (value != null) { | if (value != null) { | ||||
| print("ok"); | print("ok"); | ||||
| print(value); | print(value); | ||||
| String filePath = value[0]; | String filePath = value[0]; | ||||
| File f = File(filePath); | |||||
| var f = File(filePath); | |||||
| f.length().then((lengthFileInBytes) { | f.length().then((lengthFileInBytes) { | ||||
| if (lengthFileInBytes > ConstCommon.kFileSize) { | if (lengthFileInBytes > ConstCommon.kFileSize) { | ||||
| Utils.showSnackBarWarning(message: label_file_to_large); | Utils.showSnackBarWarning(message: label_file_to_large); | ||||
| } else { | } else { | ||||
| bool isVideo = value[1]; | bool isVideo = value[1]; | ||||
| Media newMedia = Media() | |||||
| var newMedia = Media() | |||||
| ..isVideo = isVideo | ..isVideo = isVideo | ||||
| ..isServerFile = false | ..isServerFile = false | ||||
| ..pathFile = filePath; | ..pathFile = filePath; | ||||
| currentItems.add(newMedia); | currentItems.add(newMedia); | ||||
| addNewFilePaths.add(filePath); | addNewFilePaths.add(filePath); | ||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| ..add(ChangeListMedia(items: currentItems)); | |||||
| BlocProvider.of<MediaHelperBloc>(context)..add(ChangeListMedia(items: currentItems)); | |||||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | ||||
| } | } | ||||
| }); | }); | ||||
| child: const Text(label_select_image_from_library), | child: const Text(label_select_image_from_library), | ||||
| onPressed: () async { | onPressed: () async { | ||||
| Navigator.pop(context, 'Discard'); | Navigator.pop(context, 'Discard'); | ||||
| FilePickerResult result = await FilePicker.platform | |||||
| .pickFiles(type: FileType.image, allowMultiple: true); | |||||
| FilePickerResult result = await FilePicker.platform.pickFiles(type: FileType.image, allowMultiple: true); | |||||
| if (result != null) { | if (result != null) { | ||||
| var listFuture = List<Future<File>>(); | |||||
| var listFuture = <Future<File>>[]; | |||||
| result.files.forEach((element) { | result.files.forEach((element) { | ||||
| listFuture.add(UtilAction.compressImage(File(element.path))); | listFuture.add(UtilAction.compressImage(File(element.path))); | ||||
| }); | }); | ||||
| Future.wait(listFuture).then((values) { | Future.wait(listFuture).then((values) { | ||||
| bool isExistedFileTooLarge = false; | |||||
| var isExistedFileTooLarge = false; | |||||
| values.forEach((compressFile) { | values.forEach((compressFile) { | ||||
| if (compressFile.lengthSync() > ConstCommon.kFileSize) { | if (compressFile.lengthSync() > ConstCommon.kFileSize) { | ||||
| isExistedFileTooLarge = true; | isExistedFileTooLarge = true; | ||||
| } else { | } else { | ||||
| Media newMedia = Media() | |||||
| var newMedia = Media() | |||||
| ..isVideo = false | ..isVideo = false | ||||
| ..isServerFile = false | ..isServerFile = false | ||||
| ..pathFile = compressFile.path; | ..pathFile = compressFile.path; | ||||
| } | } | ||||
| }); | }); | ||||
| if (isExistedFileTooLarge) { | if (isExistedFileTooLarge) { | ||||
| Utils.showSnackBarWarning( | |||||
| message: "Tập tin có kích thước lớn đã được loại bỏ."); | |||||
| Utils.showSnackBarWarning(message: "Tập tin có kích thước lớn đã được loại bỏ."); | |||||
| } | } | ||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| ..add(ChangeListMedia(items: currentItems)); | |||||
| BlocProvider.of<MediaHelperBloc>(context)..add(ChangeListMedia(items: currentItems)); | |||||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | ||||
| }); | }); | ||||
| } | } | ||||
| child: const Text(label_select_video_from_library), | child: const Text(label_select_video_from_library), | ||||
| onPressed: () async { | onPressed: () async { | ||||
| Navigator.pop(context, 'Discard'); | Navigator.pop(context, 'Discard'); | ||||
| FilePickerResult result = await FilePicker.platform | |||||
| .pickFiles(type: FileType.video, allowMultiple: true); | |||||
| FilePickerResult result = await FilePicker.platform.pickFiles(type: FileType.video, allowMultiple: true); | |||||
| if (result != null) { | if (result != null) { | ||||
| bool isExistedFileTooLarge = false; | |||||
| var isExistedFileTooLarge = false; | |||||
| result.files?.forEach((videoFile) { | result.files?.forEach((videoFile) { | ||||
| if (videoFile.size * 1000 > ConstCommon.kFileSize) { | if (videoFile.size * 1000 > ConstCommon.kFileSize) { | ||||
| isExistedFileTooLarge = true; | isExistedFileTooLarge = true; | ||||
| } else { | } else { | ||||
| Media newMedia = Media() | |||||
| var newMedia = Media() | |||||
| ..isVideo = true | ..isVideo = true | ||||
| ..isServerFile = false | ..isServerFile = false | ||||
| ..pathFile = videoFile.path; | ..pathFile = videoFile.path; | ||||
| } | } | ||||
| }); | }); | ||||
| if (isExistedFileTooLarge) { | if (isExistedFileTooLarge) { | ||||
| Utils.showSnackBarWarning( | |||||
| message: "Tập tin có kích thước lớn đã được loại bỏ."); | |||||
| Utils.showSnackBarWarning(message: "Tập tin có kích thước lớn đã được loại bỏ."); | |||||
| } | } | ||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| ..add(ChangeListMedia(items: currentItems)); | |||||
| BlocProvider.of<MediaHelperBloc>(context)..add(ChangeListMedia(items: currentItems)); | |||||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | ||||
| } | } | ||||
| }), | }), | ||||
| CupertinoDialogAction( | CupertinoDialogAction( | ||||
| child: const Text(label_cancel), | child: const Text(label_cancel), | ||||
| textStyle: TextStyle(fontWeight: FontWeight.bold), | |||||
| textStyle: const TextStyle(fontWeight: FontWeight.bold), | |||||
| isDefaultAction: true, | isDefaultAction: true, | ||||
| onPressed: () { | onPressed: () { | ||||
| Navigator.pop(context, 'Cancel'); | Navigator.pop(context, 'Cancel'); | ||||
| } | } | ||||
| _buildListPoster() { | _buildListPoster() { | ||||
| return BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| return BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| return WrapContentHozListView( | return WrapContentHozListView( | ||||
| list: currentItems, | |||||
| itemBuilder: (context, index) { | |||||
| var item = currentItems[index]; | |||||
| return Container( | |||||
| width: 120, | |||||
| height: 120, | |||||
| child: _WidgetItemMedia( | |||||
| item: item, | |||||
| deleteImage: (item) { | |||||
| if (item.isServerFile) { | |||||
| var url = item.pathFile | |||||
| .replaceAll(ConstCommon.baseImageUrl, ''); | |||||
| deleteFilePaths.add(url); | |||||
| } | |||||
| addNewFilePaths.remove(item.pathFile); | |||||
| currentItems.remove(item); | |||||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | |||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| .add(ChangeListMedia(items: currentItems)); | |||||
| }), | |||||
| ); | |||||
| }); | |||||
| list: currentItems, | |||||
| itemBuilder: (context, index) { | |||||
| var item = currentItems[index]; | |||||
| return Container( | |||||
| width: 120, | |||||
| height: 120, | |||||
| child: _WidgetItemMedia( | |||||
| item: item, | |||||
| deleteImage: (item) { | |||||
| if (item.isServerFile ?? false) { | |||||
| var url = item.pathFile?.replaceAll(ConstCommon.baseImageUrl, ''); | |||||
| deleteFilePaths.add(url ?? ''); | |||||
| } | |||||
| addNewFilePaths.remove(item.pathFile); | |||||
| currentItems.remove(item); | |||||
| widget.onChangeFiles(addNewFilePaths, deleteFilePaths); | |||||
| BlocProvider.of<MediaHelperBloc>(context).add(ChangeListMedia(items: currentItems)); | |||||
| }), | |||||
| ); | |||||
| }, | |||||
| separatorBuilder: (BuildContext context, int index) { | |||||
| return const SizedBox.shrink(); | |||||
| }, | |||||
| ); | |||||
| } | } | ||||
| return Container(); | return Container(); | ||||
| }); | }); | ||||
| ItemMediaCallback deleteImage; | ItemMediaCallback deleteImage; | ||||
| final Media item; | final Media item; | ||||
| _WidgetItemMedia({@required this.item, @required this.deleteImage}); | |||||
| _WidgetItemMedia({required this.item, required this.deleteImage}); | |||||
| BuildContext _context; | |||||
| double positionIconDelete = -(120.0 - 36); | double positionIconDelete = -(120.0 - 36); | ||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| _context = context; | |||||
| return GestureDetector( | return GestureDetector( | ||||
| onTap: () { | onTap: () { | ||||
| print("Show preview image or video"); | print("Show preview image or video"); | ||||
| }, | }, | ||||
| child: Stack( | child: Stack( | ||||
| alignment: Alignment.topRight, | alignment: Alignment.topRight, | ||||
| overflow: Overflow.visible, | |||||
| // overflow: Overflow.visible, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Positioned.fill( | Positioned.fill( | ||||
| child: item.isVideo | |||||
| child: (item.isVideo ?? false) | |||||
| ? VideoWidget( | ? VideoWidget( | ||||
| pathFile: item.pathFile, | |||||
| isServerFile: item.isServerFile, | |||||
| pathFile: item.pathFile ?? '', | |||||
| isServerFile: item.isServerFile ?? false, | |||||
| play: false, | play: false, | ||||
| ) | ) | ||||
| : Container( | : Container( | ||||
| margin: EdgeInsets.all(4.0), | |||||
| margin: const EdgeInsets.all(4.0), | |||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| color: Colors.white, | |||||
| border: Border.all(color: Colors.grey), | |||||
| borderRadius: | |||||
| BorderRadius.all(Radius.circular(8.0))), | |||||
| child: item.isServerFile | |||||
| ? CachedNetworkImage( | |||||
| placeholder: (context, url) => | |||||
| Icon(Icons.crop_original), | |||||
| imageUrl: item.pathFile) | |||||
| : Image.file(File(item.pathFile)), | |||||
| color: Colors.white, border: Border.all(color: Colors.grey), borderRadius: const BorderRadius.all(Radius.circular(8.0))), | |||||
| child: (item.isServerFile ?? false) | |||||
| ? CachedNetworkImage(placeholder: (context, url) => const Icon(Icons.crop_original), imageUrl: item.pathFile) | |||||
| : Image.file(File(item.pathFile ?? '')), | |||||
| )), | )), | ||||
| Positioned.fill( | Positioned.fill( | ||||
| top: positionIconDelete, | top: positionIconDelete, | ||||
| right: positionIconDelete, | right: positionIconDelete, | ||||
| child: IconButton( | child: IconButton( | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.delete, | Icons.delete, | ||||
| color: Colors.redAccent, | color: Colors.redAccent, | ||||
| size: 24, | size: 24, |
| final BoxPainter _painter; | final BoxPainter _painter; | ||||
| RoundedRectIndicator({ | RoundedRectIndicator({ | ||||
| @required Color color, | |||||
| @required double radius, | |||||
| required Color color, | |||||
| required double radius, | |||||
| double padding = 0.0, | double padding = 0.0, | ||||
| double weight = 3.0, | double weight = 3.0, | ||||
| }) : _painter = _RectPainter(color, radius, padding, weight); | }) : _painter = _RectPainter(color, radius, padding, weight); | ||||
| @override | @override | ||||
| BoxPainter createBoxPainter([onChanged]) { | |||||
| BoxPainter createBoxPainter([VoidCallback? onChanged]) { | |||||
| return _painter; | return _painter; | ||||
| } | } | ||||
| } | } | ||||
| @override | @override | ||||
| void paint(Canvas canvas, Offset offset, ImageConfiguration cfg) { | void paint(Canvas canvas, Offset offset, ImageConfiguration cfg) { | ||||
| var width = cfg.size.width; | |||||
| var height = cfg.size.height; | |||||
| var width = cfg.size?.width ?? 0.0; | |||||
| var height = cfg.size?.height ?? 0.0; | |||||
| var left = 0.0; | var left = 0.0; | ||||
| var top = height - indicatorPaddingBottom; | var top = height - indicatorPaddingBottom; |
| class SearchWidget extends StatefulWidget { | class SearchWidget extends StatefulWidget { | ||||
| final Function(String) searchPressed; | final Function(String) searchPressed; | ||||
| SearchWidget({@required this.searchPressed}); | |||||
| SearchWidget({required this.searchPressed}); | |||||
| @override | @override | ||||
| _SearchWidgetState createState() => _SearchWidgetState(); | _SearchWidgetState createState() => _SearchWidgetState(); | ||||
| } | } | ||||
| class _SearchWidgetState extends State<SearchWidget> { | class _SearchWidgetState extends State<SearchWidget> { | ||||
| BuildContext _blocContext; | |||||
| TextEditingController _searchController = TextEditingController(); | TextEditingController _searchController = TextEditingController(); | ||||
| @override | @override | ||||
| padding: const EdgeInsets.only(right: 8, top: 0, bottom: 0), | padding: const EdgeInsets.only(right: 8, top: 0, bottom: 0), | ||||
| child: Container( | child: Container( | ||||
| child: Padding( | child: Padding( | ||||
| padding: const EdgeInsets.only( | |||||
| left: 16, right: 16, top: 4, bottom: 4), | |||||
| padding: const EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 4), | |||||
| child: TextField( | child: TextField( | ||||
| textInputAction: TextInputAction.done, | textInputAction: TextInputAction.done, | ||||
| controller: _searchController, | controller: _searchController, | ||||
| cursorColor: AppColors.GRAY1, | cursorColor: AppColors.GRAY1, | ||||
| decoration: InputDecoration( | decoration: InputDecoration( | ||||
| suffixIcon: IconButton( | suffixIcon: IconButton( | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.search, | Icons.search, | ||||
| size: 30, | size: 30, | ||||
| ), | ), | ||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| _blocContext = context; | |||||
| return Container(child: getSearchBarUI()); | return Container(child: getSearchBarUI()); | ||||
| } | } | ||||
| final bool isServerFile; | final bool isServerFile; | ||||
| final String pathFile; | final String pathFile; | ||||
| const VideoWidget( | |||||
| {Key key, | |||||
| @required this.pathFile, | |||||
| @required this.play, | |||||
| @required this.isServerFile}) | |||||
| : super(key: key); | |||||
| const VideoWidget({Key? key, required this.pathFile, required this.play, required this.isServerFile}) : super(key: key); | |||||
| @override | @override | ||||
| _VideoWidgetState createState() => _VideoWidgetState(); | _VideoWidgetState createState() => _VideoWidgetState(); | ||||
| } | } | ||||
| class _VideoWidgetState extends State<VideoWidget> { | class _VideoWidgetState extends State<VideoWidget> { | ||||
| VideoPlayerController videoPlayerController; | |||||
| Future<void> _initializeVideoPlayerFuture; | |||||
| late VideoPlayerController videoPlayerController; | |||||
| late Future<void> _initializeVideoPlayerFuture; | |||||
| @override | @override | ||||
| void initState() { | void initState() { | ||||
| // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. | // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. | ||||
| videoPlayerController.play(); | videoPlayerController.play(); | ||||
| videoPlayerController.setVolume(0.0); | videoPlayerController.setVolume(0.0); | ||||
| Timer.periodic(Duration(seconds: 1), (_) { | |||||
| Timer.periodic(const Duration(seconds: 1), (_) { | |||||
| videoPlayerController.pause(); | videoPlayerController.pause(); | ||||
| }); | }); | ||||
| setState(() {}); | setState(() {}); | ||||
| future: _initializeVideoPlayerFuture, | future: _initializeVideoPlayerFuture, | ||||
| builder: (context, snapshot) { | builder: (context, snapshot) { | ||||
| if (snapshot.connectionState == ConnectionState.done) { | if (snapshot.connectionState == ConnectionState.done) { | ||||
| return new Container( | |||||
| return Container( | |||||
| child: Container( | child: Container( | ||||
| key: new PageStorageKey(widget.pathFile), | |||||
| key: PageStorageKey(widget.pathFile), | |||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.all(1), | |||||
| padding: const EdgeInsets.all(1), | |||||
| width: 100, | width: 100, | ||||
| height: 100, | height: 100, | ||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| color: Colors.white, | |||||
| border: Border.all(color: Colors.red), | |||||
| borderRadius: BorderRadius.all(Radius.circular(8.0))), | |||||
| color: Colors.white, border: Border.all(color: Colors.red), borderRadius: const BorderRadius.all(Radius.circular(8.0))), | |||||
| child: VideoPlayer(videoPlayerController), | child: VideoPlayer(videoPlayerController), | ||||
| ), | ), | ||||
| ), | ), | ||||
| ); | ); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| return const Center( | |||||
| child: CircularProgressIndicator(), | child: CircularProgressIndicator(), | ||||
| ); | ); | ||||
| } | } |
| class TextFieldDescriptionWidget extends StatelessWidget { | class TextFieldDescriptionWidget extends StatelessWidget { | ||||
| final TextEditingController controller; | final TextEditingController controller; | ||||
| final Function onSaved; | final Function onSaved; | ||||
| TextFieldDescriptionWidget( | |||||
| {@required this.onSaved, @required this.controller}); | |||||
| TextFieldDescriptionWidget({required this.onSaved, required this.controller}); | |||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return Container( | return Container( | ||||
| padding: EdgeInsets.all(8), | |||||
| decoration: BoxDecoration( | |||||
| color: AppColors.YELLOW.withOpacity(0.1), | |||||
| borderRadius: BorderRadius.circular(8)), | |||||
| padding: const EdgeInsets.all(8), | |||||
| decoration: BoxDecoration(color: AppColors.YELLOW.withOpacity(0.1), borderRadius: BorderRadius.circular(8)), | |||||
| child: TextFormField( | child: TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| controller: controller, | controller: controller, | ||||
| decoration: InputDecoration( | |||||
| labelText: "Ghi chú", | |||||
| hintText: 'Ghi chú', | |||||
| border: InputBorder.none), | |||||
| onSaved: onSaved, | |||||
| decoration: const InputDecoration(labelText: "Ghi chú", hintText: 'Ghi chú', border: InputBorder.none), | |||||
| onSaved: (v) { | |||||
| onSaved(); | |||||
| }, | |||||
| ), | ), | ||||
| ); | ); | ||||
| } | } |
| class WidgetTextFormFieldNumber extends StatelessWidget { | class WidgetTextFormFieldNumber extends StatelessWidget { | ||||
| final TextEditingController textController; | final TextEditingController textController; | ||||
| final void Function(String) onSaved; | |||||
| final void Function(String) validator; | |||||
| final void Function(String?) onSaved; | |||||
| final void Function(String?) validator; | |||||
| final void Function(String) onChanged; | final void Function(String) onChanged; | ||||
| final String hintValue; | final String hintValue; | ||||
| WidgetTextFormFieldNumber( | WidgetTextFormFieldNumber( | ||||
| {@required this.textController, | |||||
| this.onSaved, | |||||
| @required this.hintValue, | |||||
| this.validator, | |||||
| this.onChanged}); | |||||
| {required this.textController, required this.onSaved, required this.hintValue, required this.validator, required this.onChanged}); | |||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.numberWithOptions(decimal: true), | |||||
| keyboardType: const TextInputType.numberWithOptions(decimal: true), | |||||
| inputFormatters: [ | inputFormatters: [ | ||||
| FilteringTextInputFormatter.allow(ConstCommon.regExpDecimal), | FilteringTextInputFormatter.allow(ConstCommon.regExpDecimal), | ||||
| ThousandsFormatter(allowFraction: true), | ThousandsFormatter(allowFraction: true), | ||||
| decoration: InputDecoration( | decoration: InputDecoration( | ||||
| labelText: hintValue, | labelText: hintValue, | ||||
| ), | ), | ||||
| validator: validator ?? | |||||
| (String value) { | |||||
| return Validators.validNumberOrEmpty(value, label_invalid_number); | |||||
| }, | |||||
| validator: (v) { | |||||
| validator(v); | |||||
| }, | |||||
| controller: textController, | controller: textController, | ||||
| onSaved: onSaved, | |||||
| onSaved: (v) { | |||||
| onSaved(v); | |||||
| }, | |||||
| onChanged: onChanged, | onChanged: onChanged, | ||||
| ); | ); | ||||
| } | } |
| class WidgetToast extends StatelessWidget { | class WidgetToast extends StatelessWidget { | ||||
| String message; | String message; | ||||
| Color color = Colors.green; | |||||
| WidgetToast({@required this.message, this.color}); | |||||
| Color? color = Colors.green; | |||||
| WidgetToast({required this.message, this.color}); | |||||
| @override | @override | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| child: Row( | child: Row( | ||||
| mainAxisSize: MainAxisSize.min, | mainAxisSize: MainAxisSize.min, | ||||
| children: [ | children: [ | ||||
| Icon(Icons.check), | |||||
| SizedBox( | |||||
| const Icon(Icons.check), | |||||
| const SizedBox( | |||||
| width: 12.0, | width: 12.0, | ||||
| ), | ), | ||||
| Text(message), | Text(message), |
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class Utils { | class Utils { | ||||
| static void showSnackBarSuccess({String message}) { | |||||
| static void showSnackBarSuccess({required String message}) { | |||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| Get.snackbar(null, message, | Get.snackbar(null, message, | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.done, | Icons.done, | ||||
| color: Colors.white, | color: Colors.white, | ||||
| ), | ), | ||||
| backgroundColor: Colors.green); | backgroundColor: Colors.green); | ||||
| } | } | ||||
| static void showSnackBarError({String message}) { | |||||
| static void showSnackBarError({required String message}) { | |||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| Get.snackbar(null, message, | Get.snackbar(null, message, | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.error, | Icons.error, | ||||
| color: Colors.white, | color: Colors.white, | ||||
| ), | ), | ||||
| backgroundColor: Colors.red); | backgroundColor: Colors.red); | ||||
| } | } | ||||
| static void showSnackBarWarning({String message}) { | |||||
| static void showSnackBarWarning({required String message}) { | |||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| Get.snackbar(null, message, | Get.snackbar(null, message, | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.warning, | Icons.warning, | ||||
| color: Colors.yellow, | color: Colors.yellow, | ||||
| ), | ), | ||||
| } | } | ||||
| static void showDialog( | static void showDialog( | ||||
| {@required String title, | |||||
| @required String message, | |||||
| @required String textConfirm, | |||||
| @required String textCancel, | |||||
| @required Function() onConfirm}) { | |||||
| {required String title, required String message, required String textConfirm, required String textCancel, required Function() onConfirm}) { | |||||
| if (Get.isDialogOpen) Get.back(); | if (Get.isDialogOpen) Get.back(); | ||||
| Get.defaultDialog( | Get.defaultDialog( | ||||
| title: title, | title: title, | ||||
| ); | ); | ||||
| } | } | ||||
| static void showDialogConfirmSupply({@required Function() onConfirm}) { | |||||
| static void showDialogConfirmSupply({required Function() onConfirm}) { | |||||
| if (Get.isDialogOpen) Get.back(); | if (Get.isDialogOpen) Get.back(); | ||||
| Get.defaultDialog( | Get.defaultDialog( | ||||
| title: "Vật tư chưa được thêm", | title: "Vật tư chưa được thêm", |
| _clickSignOut() async { | _clickSignOut() async { | ||||
| context.bloc<AuthenticationBloc>().add(AuthenticationLogoutRequested()); | context.bloc<AuthenticationBloc>().add(AuthenticationLogoutRequested()); | ||||
| try { | try { | ||||
| String pushKey = await pref.getString(DATA_CONST.PUSH_KEY); | |||||
| var pushKey = await pref.getString(DATA_CONST.PUSH_KEY); | |||||
| if (pushKey.isNotEmpty) { | if (pushKey.isNotEmpty) { | ||||
| _userRepository | _userRepository | ||||
| .deleteFcmToken(pushKey) | .deleteFcmToken(pushKey) | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, | ||||
| children: <Widget>[ | children: <Widget>[ | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8, | height: 8, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| padding: EdgeInsets.all(8), | |||||
| padding: const EdgeInsets.all(8), | |||||
| color: Colors.white, | color: Colors.white, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Cá nhân', | 'Cá nhân', | ||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | ||||
| )), | )), | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| padding: | padding: | ||||
| EdgeInsets.only(left: 12, right: 8, top: 14, bottom: 14), | |||||
| const EdgeInsets.only(left: 12, right: 8, top: 14, bottom: 14), | |||||
| child: Row( | child: Row( | ||||
| children: [ | children: [ | ||||
| Expanded( | |||||
| const Expanded( | |||||
| child: Text( | child: Text( | ||||
| 'Phiên bản', | 'Phiên bản', | ||||
| style: | style: | ||||
| ), | ), | ||||
| ButtonIconWidget( | ButtonIconWidget( | ||||
| title: 'Đăng xuất', | title: 'Đăng xuất', | ||||
| titleStyle: TextStyle( | |||||
| titleStyle: const TextStyle( | |||||
| fontSize: 16, | fontSize: 16, | ||||
| fontWeight: FontWeight.w100, | fontWeight: FontWeight.w100, | ||||
| color: Colors.red), | color: Colors.red), |
| class ActionDetailBloc extends Bloc<ActionDetailEvent, ActionDetailState> { | class ActionDetailBloc extends Bloc<ActionDetailEvent, ActionDetailState> { | ||||
| final Repository repository; | final Repository repository; | ||||
| ActionDetailBloc({@required this.repository}) : super(ActionDetailInitial()); | |||||
| ActionDetailBloc({required this.repository}) : super(ActionDetailInitial()); | |||||
| final dio = DioProvider.instance(); | final dio = DioProvider.instance(); | ||||
| @override | @override | ||||
| } else { | } else { | ||||
| try { | try { | ||||
| yield ActionDetailLoading(); | yield ActionDetailLoading(); | ||||
| Response<String> response = await dio.get( | |||||
| "${ConstCommon.baseUrl}/${event.apiActivity}/${event.activityId}"); | |||||
| Response<String> response = await dio.get("${ConstCommon.baseUrl}/${event.apiActivity}/${event.activityId}"); | |||||
| final jsonData = json.decode(response.data); | final jsonData = json.decode(response.data); | ||||
| yield ActionDetailSuccess(item: jsonData); | yield ActionDetailSuccess(item: jsonData); | ||||
| } catch (error) { | } catch (error) { | ||||
| yield ActionDetailFailure( | |||||
| errorString: AppException.handleError(error)); | |||||
| yield ActionDetailFailure(errorString: AppException.handleError(error)); | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| final bool isNeedFetchData; | final bool isNeedFetchData; | ||||
| final String apiActivity; | final String apiActivity; | ||||
| final int activityId; | final int activityId; | ||||
| FetchData( | |||||
| {@required this.isNeedFetchData, | |||||
| @required this.apiActivity, | |||||
| @required this.activityId}); | |||||
| FetchData({required this.isNeedFetchData, required this.apiActivity, required this.activityId}); | |||||
| } | } |
| class ActionDetailFailure extends ActionDetailState { | class ActionDetailFailure extends ActionDetailState { | ||||
| final String errorString; | final String errorString; | ||||
| ActionDetailFailure({@required this.errorString}); | |||||
| ActionDetailFailure({required this.errorString}); | |||||
| } | } | ||||
| class ActionDetailSuccess<T> extends ActionDetailState { | class ActionDetailSuccess<T> extends ActionDetailState { | ||||
| final T item; | final T item; | ||||
| ActionDetailSuccess({this.item}); | |||||
| ActionDetailSuccess({required this.item}); | |||||
| @override | |||||
| List<Object> get props => [item]; | |||||
| // @override | |||||
| // List<Object> get props => [item]; | |||||
| } | } |
| Stream<dynamic> get actions => _getHarvestFetcher.stream; | Stream<dynamic> get actions => _getHarvestFetcher.stream; | ||||
| void getHarvests( | |||||
| Function(dynamic) onSuccess, Function(String) onError) async { | |||||
| void getHarvests(Function(dynamic) onSuccess, Function(String) onError) async { | |||||
| try { | try { | ||||
| _repository.getHarvests().then((value) { | _repository.getHarvests().then((value) { | ||||
| onSuccess(value); | onSuccess(value); | ||||
| }); | }); | ||||
| } catch (e) { | } catch (e) { | ||||
| _getHarvestFetcher.addError(e); | _getHarvestFetcher.addError(e); | ||||
| onError(e); | |||||
| onError(e.toString()); | |||||
| } | } | ||||
| } | } | ||||
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class ChangeDevice extends GetxController { | class ChangeDevice extends GetxController { | ||||
| Device currentDevice; | |||||
| int selectedDeviceId; | |||||
| String selectedDeviceName; | |||||
| Device currentDevice = Device(); | |||||
| int selectedDeviceId = -1; | |||||
| String selectedDeviceName = ''; | |||||
| void initValue() { | void initValue() { | ||||
| currentDevice = Device(); | currentDevice = Device(); | ||||
| void change(Device device) { | void change(Device device) { | ||||
| currentDevice = device; | currentDevice = device; | ||||
| selectedDeviceId = device.id; | |||||
| selectedDeviceName = device.name; | |||||
| selectedDeviceId = device.id ?? -1; | |||||
| selectedDeviceName = device.name ?? ''; | |||||
| update(); | update(); | ||||
| } | } | ||||
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class ChangeFieldFormSupply extends GetxController { | class ChangeFieldFormSupply extends GetxController { | ||||
| bool isChanged; | |||||
| bool isChanged = false; | |||||
| void init() { | void init() { | ||||
| isChanged = false; | isChanged = false; | ||||
| update(); | update(); |
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class ChangeButtonInForm extends GetxController { | class ChangeButtonInForm extends GetxController { | ||||
| bool isEdit; | |||||
| bool isEdit = false; | |||||
| void resetValue() { | void resetValue() { | ||||
| isEdit = false; | isEdit = false; | ||||
| update(); | update(); |
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class ChangeSupplyUsing extends GetxController { | class ChangeSupplyUsing extends GetxController { | ||||
| List<SuppliesUsing> currentItems; | |||||
| SuppliesUsing currentSupplyUsing; | |||||
| int currentIndex; | |||||
| List<SuppliesUsing> currentItems = <SuppliesUsing>[]; | |||||
| SuppliesUsing currentSupplyUsing = SuppliesUsing(); | |||||
| int currentIndex = -1; | |||||
| void init(List<SuppliesUsing> initItems) { | void init(List<SuppliesUsing> initItems) { | ||||
| currentItems = initItems; | currentItems = initItems; | ||||
| currentSupplyUsing = SuppliesUsing(); | currentSupplyUsing = SuppliesUsing(); |
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class ChangeUnit extends GetxController { | class ChangeUnit extends GetxController { | ||||
| List<String> currentUnits; | |||||
| String selectedUnit; | |||||
| List<String> currentUnits = []; | |||||
| String selectedUnit = ''; | |||||
| initValue() { | initValue() { | ||||
| currentUnits = []; | currentUnits = []; |
| class EditActionCropStatusScreen extends StatefulWidget { | class EditActionCropStatusScreen extends StatefulWidget { | ||||
| final int cropId; | final int cropId; | ||||
| final bool isEdit; | final bool isEdit; | ||||
| final int activityId; | |||||
| EditActionCropStatusScreen( | |||||
| {@required this.cropId, this.isEdit = false, this.activityId}); | |||||
| final int? activityId; | |||||
| EditActionCropStatusScreen({required this.cropId, this.isEdit = false, this.activityId}); | |||||
| @override | @override | ||||
| _EditActionCropStatusScreenState createState() => | |||||
| _EditActionCropStatusScreenState(); | |||||
| _EditActionCropStatusScreenState createState() => _EditActionCropStatusScreenState(); | |||||
| } | } | ||||
| class _EditActionCropStatusScreenState | |||||
| extends State<EditActionCropStatusScreen> { | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| class _EditActionCropStatusScreenState extends State<EditActionCropStatusScreen> { | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |||||
| final _repository = Repository(); | final _repository = Repository(); | ||||
| GlobalKey<FormState> _formKey = GlobalKey(); | GlobalKey<FormState> _formKey = GlobalKey(); | ||||
| bool _autoValidate = false; | bool _autoValidate = false; | ||||
| final _executeByController = TextEditingController(); | final _executeByController = TextEditingController(); | ||||
| DateTime executeTime = DateTime.now(); | DateTime executeTime = DateTime.now(); | ||||
| List<String> filePaths = List<String>(); | |||||
| List<String> filePaths = <String>[]; | |||||
| var changeFileController = Get.put(ChangeFileController()); | var changeFileController = Get.put(ChangeFileController()); | ||||
| Future<Null> getSharedPrefs() async { | Future<Null> getSharedPrefs() async { | ||||
| } | } | ||||
| _validateInputs() async { | _validateInputs() async { | ||||
| if (_formKey.currentState.validate()) { | |||||
| _formKey.currentState.save(); | |||||
| if (_formKey.currentState!.validate()) { | |||||
| _formKey.currentState!.save(); | |||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| filePaths = Get.find<ChangeFileController>().newFiles; | filePaths = Get.find<ChangeFileController>().newFiles; | ||||
| //Create request general model | //Create request general model | ||||
| try { | try { | ||||
| RequestGeneralModel generalModel = RequestGeneralModel() | |||||
| var generalModel = RequestGeneralModel() | |||||
| ..cropId = _cropStatus.cropId | ..cropId = _cropStatus.cropId | ||||
| ..activityId = _cropStatus.activityId | ..activityId = _cropStatus.activityId | ||||
| ..description = _cropStatus.description | ..description = _cropStatus.description | ||||
| ..executeDate = _cropStatus.executeDate; | ..executeDate = _cropStatus.executeDate; | ||||
| var generalDetail = List<ObjectUpdateDetail>(); | |||||
| var generalDetail = <ObjectUpdateDetail>[]; | |||||
| generalDetail.add(ObjectUpdateDetail() | generalDetail.add(ObjectUpdateDetail() | ||||
| ..name = "TY_LE_CAY_TRONG" | ..name = "TY_LE_CAY_TRONG" | ||||
| ..index = _cropStatus.cropRate); | ..index = _cropStatus.cropRate); | ||||
| return WidgetFieldDateTimePicker( | return WidgetFieldDateTimePicker( | ||||
| initDateTime: executeTime, | initDateTime: executeTime, | ||||
| onUpdateDateTime: (selectedDate) { | onUpdateDateTime: (selectedDate) { | ||||
| _cropStatus.executeDate = | |||||
| selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _cropStatus.executeDate = selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| }); | }); | ||||
| } | } | ||||
| hintValue: "Tỉ lệ lên cây", | hintValue: "Tỉ lệ lên cây", | ||||
| textController: _cropRateController, | textController: _cropRateController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _cropStatus.cropRate = newValue; | |||||
| _cropStatus.cropRate = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lượng lên cây", | hintValue: "Số lượng lên cây", | ||||
| textController: _numTreeController, | textController: _numTreeController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _cropStatus.numberOfTreeToGrow = newValue; | |||||
| _cropStatus.numberOfTreeToGrow = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Chiều cao cây", | hintValue: "Chiều cao cây", | ||||
| textController: _heightOfTreeController, | textController: _heightOfTreeController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _cropStatus.heightOfTree = newValue; | |||||
| _cropStatus.heightOfTree = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lá", | hintValue: "Số lá", | ||||
| textController: _numberOfLeafController, | textController: _numberOfLeafController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _cropStatus.numberOfLeaf = newValue; | |||||
| _cropStatus.numberOfLeaf = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Kích thước lá", | hintValue: "Kích thước lá", | ||||
| textController: _leafSizeController, | textController: _leafSizeController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _cropStatus.leafSize = newValue; | |||||
| _cropStatus.leafSize = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _leafColorField() { | Widget _leafColorField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Màu lá"), | |||||
| decoration: const InputDecoration(labelText: "Màu lá"), | |||||
| controller: _leafColorController, | controller: _leafColorController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _cropStatus.leafColor = newValue; | |||||
| _cropStatus.leafColor = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Dài đốt thân", | hintValue: "Dài đốt thân", | ||||
| textController: _internodeLengthController, | textController: _internodeLengthController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _cropStatus.internodeLength = newValue; | |||||
| _cropStatus.internodeLength = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _abilityProduceBudsField() { | Widget _abilityProduceBudsField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Khả năng sinh chồi"), | |||||
| decoration: const InputDecoration(labelText: "Khả năng sinh chồi"), | |||||
| controller: _abilityProduceBudsController, | controller: _abilityProduceBudsController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _cropStatus.abilityProduceBuds = newValue; | |||||
| _cropStatus.abilityProduceBuds = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Người thực hiện"), | |||||
| decoration: const InputDecoration(labelText: "Người thực hiện"), | |||||
| enabled: false, | enabled: false, | ||||
| controller: _executeByController, | controller: _executeByController, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| appBar: AppBarWidget( | appBar: AppBarWidget( | ||||
| isBack: true, | isBack: true, | ||||
| action: InkWell( | action: InkWell( | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Huỷ', | 'Huỷ', | ||||
| style: TextStyle( | |||||
| color: Colors.red, fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: Colors.red, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| onTap: () { | onTap: () { | ||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| child: MultiBlocProvider( | child: MultiBlocProvider( | ||||
| providers: [ | providers: [ | ||||
| BlocProvider<ActionDetailBloc>( | BlocProvider<ActionDetailBloc>( | ||||
| create: (context) => | |||||
| ActionDetailBloc(repository: Repository()) | |||||
| ..add(FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailCropStatus, | |||||
| activityId: widget.activityId))), | |||||
| create: (context) => ActionDetailBloc(repository: Repository()) | |||||
| ..add( | |||||
| FetchData(isNeedFetchData: widget.isEdit, apiActivity: ConstCommon.apiDetailCropStatus, activityId: widget.activityId ?? -1), | |||||
| ), | |||||
| ), | |||||
| BlocProvider<MediaHelperBloc>( | BlocProvider<MediaHelperBloc>( | ||||
| create: (context) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| ) | ) | ||||
| ], | ], | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | |||||
| // autovalidate: _autoValidate, | |||||
| child: SafeArea( | child: SafeArea( | ||||
| child: SingleChildScrollView( | child: SingleChildScrollView( | ||||
| child: | |||||
| BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | listener: (context, state) async { | ||||
| if (state is ActionDetailFailure) { | if (state is ActionDetailFailure) { | ||||
| print("fail"); | print("fail"); | ||||
| print("success"); | print("success"); | ||||
| print(state.item); | print(state.item); | ||||
| _cropStatus = CropStatus.fromJson(state.item); | _cropStatus = CropStatus.fromJson(state.item); | ||||
| _cropStatus.activityId = widget.activityId; | |||||
| _cropRateController.text = _cropStatus.cropRate | |||||
| .formatStringToStringDecimal(); | |||||
| _numTreeController.text = _cropStatus | |||||
| .numberOfTreeToGrow | |||||
| .formatStringToStringDecimal(); | |||||
| _heightOfTreeController.text = _cropStatus | |||||
| .heightOfTree | |||||
| .formatStringToStringDecimal(); | |||||
| _numberOfLeafController.text = _cropStatus | |||||
| .numberOfLeaf | |||||
| .formatStringToStringDecimal(); | |||||
| _leafSizeController.text = _cropStatus.leafSize | |||||
| .formatStringToStringDecimal(); | |||||
| _leafColorController.text = | |||||
| _cropStatus.leafColor ?? ""; | |||||
| _abilityProduceBudsController.text = | |||||
| _cropStatus.abilityProduceBuds ?? ""; | |||||
| _internodeLengthController.text = _cropStatus | |||||
| .internodeLength | |||||
| .formatStringToStringDecimal(); | |||||
| _descriptionController.text = | |||||
| _cropStatus.description ?? ""; | |||||
| _executeByController.text = | |||||
| _cropStatus.executeBy ?? ""; | |||||
| _cropStatus.activityId = widget.activityId ?? -1; | |||||
| _cropRateController.text = _cropStatus.cropRate?.formatStringToStringDecimal() ?? ''; | |||||
| _numTreeController.text = _cropStatus.numberOfTreeToGrow?.formatStringToStringDecimal() ?? ''; | |||||
| _heightOfTreeController.text = _cropStatus.heightOfTree?.formatStringToStringDecimal() ?? ''; | |||||
| _numberOfLeafController.text = _cropStatus.numberOfLeaf?.formatStringToStringDecimal() ?? ''; | |||||
| _leafSizeController.text = _cropStatus.leafSize?.formatStringToStringDecimal() ?? ''; | |||||
| _leafColorController.text = _cropStatus.leafColor ?? ""; | |||||
| _abilityProduceBudsController.text = _cropStatus.abilityProduceBuds ?? ""; | |||||
| _internodeLengthController.text = _cropStatus.internodeLength?.formatStringToStringDecimal() ?? ''; | |||||
| _descriptionController.text = _cropStatus.description ?? ""; | |||||
| _executeByController.text = _cropStatus.executeBy ?? ""; | |||||
| Get.find<ChangeDateTimePicker>().change(_cropStatus | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| Get.find<ChangeDateTimePicker>().change( | |||||
| _cropStatus.executeDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now(), | |||||
| ); | |||||
| //Show media | //Show media | ||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _cropStatus.media)) { | |||||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||||
| ChangeListMedia( | |||||
| items: | |||||
| UtilAction.convertFilePathToMedia( | |||||
| _cropStatus.media))); | |||||
| if (Validators.stringNotNullOrEmpty(_cropStatus.media ?? '')) { | |||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| .add(ChangeListMedia(items: UtilAction.convertFilePathToMedia(_cropStatus.media ?? ''))); | |||||
| } | } | ||||
| } else if (state is ActionDetailInitial) { | } else if (state is ActionDetailInitial) { | ||||
| print("init"); | print("init"); | ||||
| Padding( | Padding( | ||||
| padding: const EdgeInsets.all(8.0), | padding: const EdgeInsets.all(8.0), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: | |||||
| CrossAxisAlignment.start, | |||||
| crossAxisAlignment: CrossAxisAlignment.start, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text( | |||||
| const Text( | |||||
| plot_action_crop_status, | plot_action_crop_status, | ||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.w500, | |||||
| fontSize: 22), | |||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | |||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Ngày thực hiện *", | "Ngày thực hiện *", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnExecuteTimePicker(), | _btnExecuteTimePicker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _cropRateField(), | _cropRateField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _numTreeField(), | _numTreeField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _hightOfTreeField(), | _hightOfTreeField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _numberOfLeafField(), | _numberOfLeafField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _leafSizeField(), | _leafSizeField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _leafColorField(), | _leafColorField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _internodeLengthField(), | _internodeLengthField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _abilityProduceBudsField(), | _abilityProduceBudsField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _desciptionField(), | _desciptionField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _executeByField(), | _executeByField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| print("length: " + | |||||
| state.items.length.toString()); | |||||
| print("length: " + state.items.length.toString()); | |||||
| return WidgetMediaPicker( | return WidgetMediaPicker( | ||||
| currentItems: state.items, | currentItems: state.items, | ||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>() | |||||
| .change(newPathFiles, | |||||
| deletePathFiles); | |||||
| onChangeFiles: (newPathFiles, deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change(newPathFiles, deletePathFiles); | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| child: CircularProgressIndicator()); | |||||
| return const Center(child: CircularProgressIndicator()); | |||||
| } | } | ||||
| }), | }), | ||||
| Padding( | Padding( | ||||
| child: ButtonWidget( | child: ButtonWidget( | ||||
| title: 'CẬP NHẬT', | title: 'CẬP NHẬT', | ||||
| onPressed: () { | onPressed: () { | ||||
| FocusScopeNode currentFocus = | |||||
| FocusScope.of(context); | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | if (!currentFocus.hasPrimaryFocus) { | ||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } |
| class EditActionDiseaseScreen extends StatefulWidget { | class EditActionDiseaseScreen extends StatefulWidget { | ||||
| final int cropId; | final int cropId; | ||||
| final bool isEdit; | final bool isEdit; | ||||
| final int activityId; | |||||
| EditActionDiseaseScreen( | |||||
| {@required this.cropId, this.isEdit = false, this.activityId}); | |||||
| final int? activityId; | |||||
| EditActionDiseaseScreen({required this.cropId, this.isEdit = false, this.activityId}); | |||||
| @override | @override | ||||
| _EditActionDiseaseScreenState createState() => | |||||
| _EditActionDiseaseScreenState(); | |||||
| _EditActionDiseaseScreenState createState() => _EditActionDiseaseScreenState(); | |||||
| } | } | ||||
| class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { | class _EditActionDiseaseScreenState extends State<EditActionDiseaseScreen> { | ||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |||||
| final _repository = Repository(); | final _repository = Repository(); | ||||
| GlobalKey<FormState> _formKey = GlobalKey(); | GlobalKey<FormState> _formKey = GlobalKey(); | ||||
| bool _autoValidate = false; | bool _autoValidate = false; | ||||
| final _executeByController = TextEditingController(); | final _executeByController = TextEditingController(); | ||||
| DateTime executeTime = DateTime.now(); | DateTime executeTime = DateTime.now(); | ||||
| List<String> filePaths = List<String>(); | |||||
| List<String> filePaths = <String>[]; | |||||
| var changeFileController = Get.put(ChangeFileController()); | var changeFileController = Get.put(ChangeFileController()); | ||||
| Future<Null> getSharedPrefs() async { | Future<Null> getSharedPrefs() async { | ||||
| } | } | ||||
| _validateInputs() async { | _validateInputs() async { | ||||
| if (_formKey.currentState.validate()) { | |||||
| _formKey.currentState.save(); | |||||
| if (_formKey.currentState!.validate()) { | |||||
| _formKey.currentState!.save(); | |||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| filePaths = Get.find<ChangeFileController>().newFiles; | filePaths = Get.find<ChangeFileController>().newFiles; | ||||
| //Create request general model | //Create request general model | ||||
| try { | try { | ||||
| RequestDisease requestDisease = RequestDisease() | |||||
| var requestDisease = RequestDisease() | |||||
| ..cropId = _disease.cropId | ..cropId = _disease.cropId | ||||
| ..activityId = _disease.activityId | ..activityId = _disease.activityId | ||||
| ..description = _disease.description | ..description = _disease.description | ||||
| ..executeDate = _disease.executeDate; | ..executeDate = _disease.executeDate; | ||||
| var generalDetail = List<ObjectUpdateDetail>(); | |||||
| var generalDetail = <ObjectUpdateDetail>[]; | |||||
| generalDetail.add(ObjectUpdateDetail() | generalDetail.add(ObjectUpdateDetail() | ||||
| ..name = "LOAI_DICH_HAI" | ..name = "LOAI_DICH_HAI" | ||||
| ..index = _disease.typesOfPest); | ..index = _disease.typesOfPest); | ||||
| return WidgetFieldDateTimePicker( | return WidgetFieldDateTimePicker( | ||||
| initDateTime: executeTime, | initDateTime: executeTime, | ||||
| onUpdateDateTime: (selectedDate) { | onUpdateDateTime: (selectedDate) { | ||||
| _disease.executeDate = | |||||
| selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _disease.executeDate = selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| }); | }); | ||||
| } | } | ||||
| Widget _typeOfPestField() { | Widget _typeOfPestField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Loại dịch hại *"), | |||||
| decoration: const InputDecoration(labelText: "Loại dịch hại *"), | |||||
| controller: _typesOfPestController, | controller: _typesOfPestController, | ||||
| validator: (String value) { | |||||
| return Validators.validateNotNullOrEmpty( | |||||
| value, label_validate_input_empty); | |||||
| validator: (value) { | |||||
| return Validators.validateNotNullOrEmpty(value!, label_validate_input_empty); | |||||
| }, | }, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _disease.typesOfPest = newValue; | |||||
| _disease.typesOfPest = newValue!; | |||||
| }, | }, | ||||
| ); | ); | ||||
| } | } | ||||
| Widget _harmLevelField() { | Widget _harmLevelField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Mức độ gây hại"), | |||||
| decoration: const InputDecoration(labelText: "Mức độ gây hại"), | |||||
| controller: _harmLevelController, | controller: _harmLevelController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _disease.harmLevel = newValue; | |||||
| _disease.harmLevel = newValue!; | |||||
| }, | }, | ||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "% cây", | hintValue: "% cây", | ||||
| textController: _treePercentController, | textController: _treePercentController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _disease.treePercent = newValue; | |||||
| _disease.treePercent = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _locationField() { | Widget _locationField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Vị trí"), | |||||
| decoration: const InputDecoration(labelText: "Vị trí"), | |||||
| controller: _locationController, | controller: _locationController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _disease.location = newValue; | |||||
| _disease.location = newValue!; | |||||
| }, | }, | ||||
| ); | ); | ||||
| } | } | ||||
| Widget _naturalEnemyField() { | Widget _naturalEnemyField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Thiên địch"), | |||||
| decoration: const InputDecoration(labelText: "Thiên địch"), | |||||
| controller: _naturalEnemyController, | controller: _naturalEnemyController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _disease.naturalEnemy = newValue; | |||||
| _disease.naturalEnemy = newValue!; | |||||
| }, | }, | ||||
| ); | ); | ||||
| } | } | ||||
| Widget _treatmentMeasuresField() { | Widget _treatmentMeasuresField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Biện pháp xử lý"), | |||||
| decoration: const InputDecoration(labelText: "Biện pháp xử lý"), | |||||
| controller: _treatmentMeasuresController, | controller: _treatmentMeasuresController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _disease.treatmentMeasures = newValue; | |||||
| _disease.treatmentMeasures = newValue!; | |||||
| }, | }, | ||||
| ); | ); | ||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Người thực hiện"), | |||||
| decoration: const InputDecoration(labelText: "Người thực hiện"), | |||||
| enabled: false, | enabled: false, | ||||
| controller: _executeByController, | controller: _executeByController, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| appBar: AppBarWidget( | appBar: AppBarWidget( | ||||
| isBack: true, | isBack: true, | ||||
| action: InkWell( | action: InkWell( | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Huỷ', | 'Huỷ', | ||||
| style: TextStyle( | |||||
| color: Colors.red, fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: Colors.red, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| onTap: () { | onTap: () { | ||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| child: MultiBlocProvider( | child: MultiBlocProvider( | ||||
| providers: [ | providers: [ | ||||
| BlocProvider<ActionDetailBloc>( | BlocProvider<ActionDetailBloc>( | ||||
| create: (context) => | |||||
| ActionDetailBloc(repository: Repository()) | |||||
| ..add(FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailDisease, | |||||
| activityId: widget.activityId))), | |||||
| create: (context) => ActionDetailBloc(repository: Repository()) | |||||
| ..add( | |||||
| FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailDisease, | |||||
| activityId: widget.activityId ?? 0, | |||||
| ), | |||||
| ), | |||||
| ), | |||||
| BlocProvider<MediaHelperBloc>( | BlocProvider<MediaHelperBloc>( | ||||
| create: (context) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| ) | ) | ||||
| ], | ], | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | |||||
| // autovalidate: _autoValidate, | |||||
| child: SafeArea( | child: SafeArea( | ||||
| child: SingleChildScrollView( | child: SingleChildScrollView( | ||||
| child: | |||||
| BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | listener: (context, state) async { | ||||
| if (state is ActionDetailFailure) { | if (state is ActionDetailFailure) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| print(state.item); | print(state.item); | ||||
| _disease = Disease.fromJson(state.item); | _disease = Disease.fromJson(state.item); | ||||
| _disease.activityId = widget.activityId; | |||||
| _typesOfPestController.text = | |||||
| _disease.typesOfPest ?? ""; | |||||
| _harmLevelController.text = | |||||
| _disease.harmLevel ?? ""; | |||||
| _treePercentController.text = _disease.treePercent | |||||
| .formatStringToStringDecimal(); | |||||
| _locationController.text = | |||||
| _disease.location ?? ""; | |||||
| _naturalEnemyController.text = | |||||
| _disease.naturalEnemy ?? ""; | |||||
| _treatmentMeasuresController.text = | |||||
| _disease.treatmentMeasures ?? ""; | |||||
| _descriptionController.text = | |||||
| _disease.description ?? ""; | |||||
| _executeByController.text = _disease.executeBy; | |||||
| _disease.activityId = widget.activityId ?? 0; | |||||
| _typesOfPestController.text = _disease.typesOfPest ?? ""; | |||||
| _harmLevelController.text = _disease.harmLevel ?? ""; | |||||
| _treePercentController.text = _disease.treePercent?.formatStringToStringDecimal() ?? ''; | |||||
| _locationController.text = _disease.location ?? ""; | |||||
| _naturalEnemyController.text = _disease.naturalEnemy ?? ""; | |||||
| _treatmentMeasuresController.text = _disease.treatmentMeasures ?? ""; | |||||
| _descriptionController.text = _disease.description ?? ""; | |||||
| _executeByController.text = _disease.executeBy ?? ''; | |||||
| Get.find<ChangeDateTimePicker>().change(_disease | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| Get.find<ChangeDateTimePicker>().change( | |||||
| _disease.executeDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now(), | |||||
| ); | |||||
| //Show media | //Show media | ||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _disease.media)) { | |||||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||||
| ChangeListMedia( | |||||
| items: | |||||
| UtilAction.convertFilePathToMedia( | |||||
| _disease.media))); | |||||
| if (Validators.stringNotNullOrEmpty(_disease.media ?? '')) { | |||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| .add(ChangeListMedia(items: UtilAction.convertFilePathToMedia(_disease.media ?? ''))); | |||||
| } | } | ||||
| } else if (state is ActionDetailInitial) { | } else if (state is ActionDetailInitial) { | ||||
| } else if (state is ActionDetailLoading) { | } else if (state is ActionDetailLoading) { | ||||
| Padding( | Padding( | ||||
| padding: const EdgeInsets.all(8.0), | padding: const EdgeInsets.all(8.0), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: | |||||
| CrossAxisAlignment.start, | |||||
| crossAxisAlignment: CrossAxisAlignment.start, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text( | |||||
| const Text( | |||||
| plot_action_disease, | plot_action_disease, | ||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.w500, | |||||
| fontSize: 22), | |||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | |||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Ngày thực hiện *", | "Ngày thực hiện *", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnExecuteTimePicker(), | _btnExecuteTimePicker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _typeOfPestField(), | _typeOfPestField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _harmLevelField(), | _harmLevelField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _treePercentField(), | _treePercentField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _locationField(), | _locationField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _naturalEnemyField(), | _naturalEnemyField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _treatmentMeasuresField(), | _treatmentMeasuresField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _descriptionField(), | _descriptionField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _executeByField(), | _executeByField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| return WidgetMediaPicker( | return WidgetMediaPicker( | ||||
| currentItems: state.items, | currentItems: state.items, | ||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>() | |||||
| .change(newPathFiles, | |||||
| deletePathFiles); | |||||
| onChangeFiles: (newPathFiles, deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change(newPathFiles, deletePathFiles); | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| child: CircularProgressIndicator()); | |||||
| return const Center(child: CircularProgressIndicator()); | |||||
| } | } | ||||
| }), | }), | ||||
| Padding( | Padding( | ||||
| child: ButtonWidget( | child: ButtonWidget( | ||||
| title: 'CẬP NHẬT', | title: 'CẬP NHẬT', | ||||
| onPressed: () { | onPressed: () { | ||||
| FocusScopeNode currentFocus = | |||||
| FocusScope.of(context); | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | if (!currentFocus.hasPrimaryFocus) { | ||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } |
| class EditActionDungScreen extends StatefulWidget { | class EditActionDungScreen extends StatefulWidget { | ||||
| final int cropId; | final int cropId; | ||||
| final bool isEdit; | final bool isEdit; | ||||
| final int activityId; | |||||
| EditActionDungScreen( | |||||
| {@required this.cropId, this.isEdit = false, this.activityId}); | |||||
| final int? activityId; | |||||
| EditActionDungScreen({required this.cropId, this.isEdit = false, this.activityId}); | |||||
| @override | @override | ||||
| _EditActionDungScreenState createState() => _EditActionDungScreenState(); | _EditActionDungScreenState createState() => _EditActionDungScreenState(); | ||||
| } | } | ||||
| class _EditActionDungScreenState extends State<EditActionDungScreen> { | class _EditActionDungScreenState extends State<EditActionDungScreen> { | ||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |||||
| final _repository = Repository(); | final _repository = Repository(); | ||||
| GlobalKey<FormState> _formKey = GlobalKey(); | GlobalKey<FormState> _formKey = GlobalKey(); | ||||
| bool _autoValidate = false; | bool _autoValidate = false; | ||||
| final _weatherController = TextEditingController(); | final _weatherController = TextEditingController(); | ||||
| final _executeByController = TextEditingController(); | final _executeByController = TextEditingController(); | ||||
| final _quarantinePeriodController = TextEditingController(); | final _quarantinePeriodController = TextEditingController(); | ||||
| List<SuppliesUsing> suppliesUsing = new List<SuppliesUsing>(); | |||||
| List<SuppliesUsing> suppliesUsing = <SuppliesUsing>[]; | |||||
| DateTime executeTime = DateTime.now(); | DateTime executeTime = DateTime.now(); | ||||
| List<String> filePaths = List<String>(); | |||||
| List<String> filePaths = <String>[]; | |||||
| var changeFileController = Get.put(ChangeFileController()); | var changeFileController = Get.put(ChangeFileController()); | ||||
| Future<Null> getSharedPrefs() async { | Future<Null> getSharedPrefs() async { | ||||
| super.initState(); | super.initState(); | ||||
| getSharedPrefs(); | getSharedPrefs(); | ||||
| changeFileController.initValue(); | changeFileController.initValue(); | ||||
| _dung.suppliesUsing = new List<SuppliesUsing>(); | |||||
| _dung.suppliesUsing = <SuppliesUsing>[]; | |||||
| _dung.cropId = widget.cropId; | _dung.cropId = widget.cropId; | ||||
| } | } | ||||
| _validateInputs() async { | _validateInputs() async { | ||||
| if (_formKey.currentState.validate()) { | |||||
| _formKey.currentState.save(); | |||||
| if (_formKey.currentState!.validate()) { | |||||
| _formKey.currentState!.save(); | |||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| filePaths = Get.find<ChangeFileController>().newFiles; | filePaths = Get.find<ChangeFileController>().newFiles; | ||||
| List<SuppliesUsing> newSups = []; | |||||
| var newSups = <SuppliesUsing>[]; | |||||
| suppliesUsing.forEach((sup) { | suppliesUsing.forEach((sup) { | ||||
| var newSup = sup; | var newSup = sup; | ||||
| newSup.suppliesInWarehouseId = sup.tbSuppliesInWarehouseId; | newSup.suppliesInWarehouseId = sup.tbSuppliesInWarehouseId; | ||||
| }, (error) { | }, (error) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| Utils.showSnackBarError(message: AppException.handleError(error)); | Utils.showSnackBarError(message: AppException.handleError(error)); | ||||
| }, | |||||
| apiAddAction: ConstCommon.apiAddDung, | |||||
| paramActivity: ConstCommon.paramsActionDung, | |||||
| activityAction: activityDung, | |||||
| filePaths: filePaths); | |||||
| }, apiAddAction: ConstCommon.apiAddDung, paramActivity: ConstCommon.paramsActionDung, activityAction: activityDung, filePaths: filePaths); | |||||
| } else { | } else { | ||||
| //UPDATE | //UPDATE | ||||
| _repository.updateAction((value) { | _repository.updateAction((value) { | ||||
| return WidgetFieldDateTimePicker( | return WidgetFieldDateTimePicker( | ||||
| initDateTime: executeTime, | initDateTime: executeTime, | ||||
| onUpdateDateTime: (selectedDate) { | onUpdateDateTime: (selectedDate) { | ||||
| _dung.executeDate = | |||||
| selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _dung.executeDate = selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| }); | }); | ||||
| } | } | ||||
| Widget _purposeField() { | Widget _purposeField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Lý do sử dụng"), | |||||
| decoration: const InputDecoration(labelText: "Lý do sử dụng"), | |||||
| controller: _purposeController, | controller: _purposeController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _dung.purpose = newValue; | |||||
| _dung.purpose = newValue ?? ''; | |||||
| }, | }, | ||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Thời gian cách ly", | hintValue: "Thời gian cách ly", | ||||
| textController: _quarantinePeriodController, | textController: _quarantinePeriodController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _dung.quarantinePeriod = newValue.parseDoubleThousand(); | |||||
| _dung.quarantinePeriod = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _weatherField() { | Widget _weatherField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Thời tiết"), | |||||
| decoration: const InputDecoration(labelText: "Thời tiết"), | |||||
| controller: _weatherController, | controller: _weatherController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _dung.weatherConditions = newValue; | |||||
| _dung.weatherConditions = newValue ?? ''; | |||||
| }, | }, | ||||
| ); | ); | ||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Người thực hiện"), | |||||
| decoration: const InputDecoration(labelText: "Người thực hiện"), | |||||
| enabled: false, | enabled: false, | ||||
| controller: _executeByController, | controller: _executeByController, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| appBar: AppBarWidget( | appBar: AppBarWidget( | ||||
| isBack: true, | isBack: true, | ||||
| action: InkWell( | action: InkWell( | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Huỷ', | 'Huỷ', | ||||
| style: TextStyle( | |||||
| color: Colors.red, fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: Colors.red, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| onTap: () { | onTap: () { | ||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| child: MultiBlocProvider( | child: MultiBlocProvider( | ||||
| providers: [ | providers: [ | ||||
| BlocProvider<ActionDetailBloc>( | BlocProvider<ActionDetailBloc>( | ||||
| create: (context) => | |||||
| ActionDetailBloc(repository: Repository()) | |||||
| ..add(FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailDung, | |||||
| activityId: widget.activityId))), | |||||
| create: (context) => ActionDetailBloc(repository: Repository()) | |||||
| ..add( | |||||
| FetchData(isNeedFetchData: widget.isEdit, apiActivity: ConstCommon.apiDetailDung, activityId: widget.activityId ?? -1), | |||||
| ), | |||||
| ), | |||||
| BlocProvider<MediaHelperBloc>( | BlocProvider<MediaHelperBloc>( | ||||
| create: (context) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| ) | ) | ||||
| ], | ], | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | |||||
| // autovalidate: _autoValidate, | |||||
| child: SafeArea( | child: SafeArea( | ||||
| child: SingleChildScrollView( | child: SingleChildScrollView( | ||||
| child: BlocConsumer<ActionDetailBloc, | |||||
| ActionDetailState>( | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | listener: (context, state) async { | ||||
| if (state is ActionDetailFailure) { | if (state is ActionDetailFailure) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| } else if (state is ActionDetailSuccess) { | } else if (state is ActionDetailSuccess) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| _dung = Dung.fromJson(state.item); | _dung = Dung.fromJson(state.item); | ||||
| _dung.activityId = widget.activityId; | |||||
| _purposeController.text = | |||||
| _dung.purpose ?? ""; | |||||
| _quarantinePeriodController.text = _dung | |||||
| .quarantinePeriod | |||||
| .formatNumtoStringDecimal(); | |||||
| _weatherController.text = | |||||
| _dung.weatherConditions ?? ""; | |||||
| _descriptionController.text = | |||||
| _dung.description; | |||||
| _executeByController.text = _dung.executeBy; | |||||
| Get.find<ChangeDateTimePicker>().change(_dung | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| _dung.activityId = widget.activityId ?? -1; | |||||
| _purposeController.text = _dung.purpose ?? ""; | |||||
| _quarantinePeriodController.text = _dung.quarantinePeriod?.formatNumtoStringDecimal() ?? ''; | |||||
| _weatherController.text = _dung.weatherConditions ?? ""; | |||||
| _descriptionController.text = _dung.description ?? ''; | |||||
| _executeByController.text = _dung.executeBy ?? ''; | |||||
| Get.find<ChangeDateTimePicker>().change( | |||||
| _dung.executeDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now(), | |||||
| ); | |||||
| //Show media | //Show media | ||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _dung.media)) { | |||||
| if (Validators.stringNotNullOrEmpty(_dung.media ?? '')) { | |||||
| BlocProvider.of<MediaHelperBloc>(context) | BlocProvider.of<MediaHelperBloc>(context) | ||||
| .add(ChangeListMedia( | |||||
| items: UtilAction | |||||
| .convertFilePathToMedia( | |||||
| _dung.media))); | |||||
| .add(ChangeListMedia(items: UtilAction.convertFilePathToMedia(_dung.media ?? ''))); | |||||
| } | } | ||||
| //list supply | //list supply | ||||
| suppliesUsing = _dung.suppliesUsing; | |||||
| Get.find<ChangeSupplyUsing>() | |||||
| .changeInitList(suppliesUsing); | |||||
| suppliesUsing = _dung.suppliesUsing ?? <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) { | ||||
| Padding( | Padding( | ||||
| padding: const EdgeInsets.all(8.0), | padding: const EdgeInsets.all(8.0), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: | |||||
| CrossAxisAlignment.start, | |||||
| crossAxisAlignment: CrossAxisAlignment.start, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text( | |||||
| const Text( | |||||
| plot_action_dung, | plot_action_dung, | ||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.w500, | |||||
| fontSize: 22), | |||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | |||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Ngày thực hiện *", | "Ngày thực hiện *", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnExecuteTimePicker(), | _btnExecuteTimePicker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _purposeField(), | _purposeField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _quarantinePeriodField(), | _quarantinePeriodField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _weatherField(), | _weatherField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _desciptionField(), | _desciptionField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _executeByField(), | _executeByField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| BlocBuilder<MediaHelperBloc, | |||||
| MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| return WidgetMediaPicker( | return WidgetMediaPicker( | ||||
| currentItems: state.items, | currentItems: state.items, | ||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>() | |||||
| .change(newPathFiles, | |||||
| deletePathFiles); | |||||
| onChangeFiles: (newPathFiles, deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change(newPathFiles, deletePathFiles); | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| child: | |||||
| CircularProgressIndicator()); | |||||
| return const Center(child: CircularProgressIndicator()); | |||||
| } | } | ||||
| }), | }), | ||||
| Padding( | Padding( | ||||
| child: ButtonWidget( | child: ButtonWidget( | ||||
| title: 'CẬP NHẬT', | title: 'CẬP NHẬT', | ||||
| onPressed: () { | onPressed: () { | ||||
| FocusScopeNode currentFocus = | |||||
| FocusScope.of(context); | |||||
| if (!currentFocus | |||||
| .hasPrimaryFocus) { | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | |||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } | ||||
| if (Get.find< | |||||
| ChangeFieldFormSupply>() | |||||
| .isChanged) { | |||||
| Utils.showDialogConfirmSupply( | |||||
| onConfirm: () { | |||||
| if (Get.find<ChangeFieldFormSupply>().isChanged) { | |||||
| Utils.showDialogConfirmSupply(onConfirm: () { | |||||
| Get.back(); | Get.back(); | ||||
| _validateInputs(); | _validateInputs(); | ||||
| }); | }); |
| class WidgetDungSupply extends StatefulWidget { | class WidgetDungSupply extends StatefulWidget { | ||||
| final List<SuppliesUsing> currentItems; | final List<SuppliesUsing> currentItems; | ||||
| final Function(List<SuppliesUsing> supplyChanges) onChangeSupplies; | final Function(List<SuppliesUsing> supplyChanges) onChangeSupplies; | ||||
| WidgetDungSupply({this.currentItems, @required this.onChangeSupplies}); | |||||
| WidgetDungSupply({required this.currentItems, required this.onChangeSupplies}); | |||||
| @override | @override | ||||
| _WidgetDungSupplyState createState() => _WidgetDungSupplyState(); | _WidgetDungSupplyState createState() => _WidgetDungSupplyState(); | ||||
| } | } | ||||
| return Container( | return Container( | ||||
| height: 120, | height: 120, | ||||
| child: ListView.builder( | child: ListView.builder( | ||||
| physics: ClampingScrollPhysics(), | |||||
| physics: const ClampingScrollPhysics(), | |||||
| scrollDirection: Axis.horizontal, | scrollDirection: Axis.horizontal, | ||||
| shrinkWrap: true, | shrinkWrap: true, | ||||
| itemCount: value.currentItems.length, | itemCount: value.currentItems.length, | ||||
| ..name = editedSupplyUsing.equipmentName; | ..name = editedSupplyUsing.equipmentName; | ||||
| changeSelectedDevice.change(editedDevice); | changeSelectedDevice.change(editedDevice); | ||||
| changeUnit | |||||
| .updateListByUnitName(editedSupplyUsing.supplyUnit); | |||||
| changeUnit.updateSelected(editedSupplyUsing.supplyUnit); | |||||
| _dosageController.text = editedSupplyUsing.dosage; | |||||
| _howToUseController.text = editedSupplyUsing.howToUse; | |||||
| _quantityController.text = editedSupplyUsing.quantity | |||||
| .formatNumtoStringDecimal(); | |||||
| changeUnit.updateListByUnitName(editedSupplyUsing.supplyUnit ?? ''); | |||||
| changeUnit.updateSelected(editedSupplyUsing.supplyUnit ?? ''); | |||||
| _dosageController.text = editedSupplyUsing.dosage ?? ''; | |||||
| _howToUseController.text = editedSupplyUsing.howToUse ?? ''; | |||||
| _quantityController.text = editedSupplyUsing.quantity?.formatNumtoStringDecimal() ?? ''; | |||||
| }, | }, | ||||
| child: Card( | child: Card( | ||||
| child: Stack( | child: Stack( | ||||
| alignment: Alignment.bottomCenter, | alignment: Alignment.bottomCenter, | ||||
| overflow: Overflow.visible, | |||||
| // overflow: Overflow.visible, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Positioned( | Positioned( | ||||
| child: ClipRRect( | child: ClipRRect( | ||||
| borderRadius: BorderRadius.circular(8), | borderRadius: BorderRadius.circular(8), | ||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.all(4), | |||||
| padding: const EdgeInsets.all(4), | |||||
| width: 150, | width: 150, | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: CrossAxisAlignment.center, | crossAxisAlignment: CrossAxisAlignment.center, | ||||
| mainAxisAlignment: MainAxisAlignment.center, | mainAxisAlignment: MainAxisAlignment.center, | ||||
| children: [ | children: [ | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 12.0, | height: 12.0, | ||||
| ), | ), | ||||
| Flexible( | Flexible( | ||||
| child: Text( | |||||
| value.currentItems[index].supplyName ?? | |||||
| "", | |||||
| overflow: TextOverflow.ellipsis, | |||||
| maxLines: 1), | |||||
| child: Text(value.currentItems[index].supplyName ?? "", overflow: TextOverflow.ellipsis, maxLines: 1), | |||||
| ), | ), | ||||
| Validators.stringNotNullOrEmpty( | |||||
| value.currentItems[index].dosage) | |||||
| Validators.stringNotNullOrEmpty(value.currentItems[index].dosage ?? '') | |||||
| ? Flexible(child: Text("${value.currentItems[index].dosage ?? ""}")) | |||||
| : const SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value.currentItems[index].quantity?.formatNumtoStringDecimal() ?? '') | |||||
| ? Flexible( | ? Flexible( | ||||
| child: Text( | child: Text( | ||||
| "${value.currentItems[index].dosage ?? ""}")) | |||||
| : SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value | |||||
| .currentItems[index].quantity | |||||
| .formatNumtoStringDecimal()) | |||||
| ? Flexible( | |||||
| child: Text( | |||||
| "${value.currentItems[index].quantity.formatNumtoStringDecimal() ?? ""} ${value.currentItems[index].supplyUnit ?? ""}")) | |||||
| : SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value | |||||
| .currentItems[index].equipmentName) | |||||
| ? Flexible( | |||||
| child: Text( | |||||
| "${value.currentItems[index].equipmentName ?? ""}")) | |||||
| : SizedBox(), | |||||
| Validators.stringNotNullOrEmpty( | |||||
| value.currentItems[index].howToUse) | |||||
| ? Flexible( | |||||
| child: Text( | |||||
| "${value.currentItems[index].howToUse ?? ""}")) | |||||
| : SizedBox(), | |||||
| "${value.currentItems[index].quantity?.formatNumtoStringDecimal() ?? ""} ${value.currentItems[index].supplyUnit ?? ""}")) | |||||
| : const SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value.currentItems[index].equipmentName ?? '') | |||||
| ? Flexible(child: Text("${value.currentItems[index].equipmentName ?? ""}")) | |||||
| : const SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value.currentItems[index].howToUse ?? '') | |||||
| ? Flexible(child: Text("${value.currentItems[index].howToUse ?? ""}")) | |||||
| : const SizedBox(), | |||||
| ], | ], | ||||
| ), | ), | ||||
| ), | ), | ||||
| top: -10, | top: -10, | ||||
| right: -10, | right: -10, | ||||
| child: IconButton( | child: IconButton( | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.cancel, | Icons.cancel, | ||||
| color: Colors.redAccent, | color: Colors.redAccent, | ||||
| ), | ), | ||||
| Widget _btnSelectSubstrates() { | Widget _btnSelectSubstrates() { | ||||
| return GetBuilder<ChangeSupply>(builder: (data) { | return GetBuilder<ChangeSupply>(builder: (data) { | ||||
| return FlatButton( | return FlatButton( | ||||
| padding: | |||||
| EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| onPressed: () { | onPressed: () { | ||||
| var currentIndexEdit = changeSupplyUsing.currentIndex; | var currentIndexEdit = changeSupplyUsing.currentIndex; | ||||
| Navigator.of(context) | Navigator.of(context) | ||||
| type: ConstCommon.supplyTypeDung, | type: ConstCommon.supplyTypeDung, | ||||
| selectedId: changeSelectedSupply.selectedSupplyId, | selectedId: changeSelectedSupply.selectedSupplyId, | ||||
| currentItems: changeSupplyUsing.currentItems, | currentItems: changeSupplyUsing.currentItems, | ||||
| currentEditId: (currentIndexEdit >= 0) | |||||
| ? changeSupplyUsing.currentItems[currentIndexEdit] | |||||
| .tbSuppliesInWarehouseId | |||||
| : -1, | |||||
| currentEditId: | |||||
| (currentIndexEdit >= 0) ? changeSupplyUsing.currentItems[currentIndexEdit].tbSuppliesInWarehouseId ?? -1 : -1, | |||||
| ), | ), | ||||
| fullscreenDialog: false)) | fullscreenDialog: false)) | ||||
| .then((value) { | .then((value) { | ||||
| if (value != null) { | if (value != null) { | ||||
| var result = value as Supply; | var result = value as Supply; | ||||
| changeSelectedSupply.change(result); | changeSelectedSupply.change(result); | ||||
| changeUnit.updateListByUnitName(result.unit); | |||||
| changeUnit.updateListByUnitName(result.unit ?? ''); | |||||
| changeFormField.change(true); | changeFormField.change(true); | ||||
| } | } | ||||
| }); | }); | ||||
| crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, | ||||
| children: [ | children: [ | ||||
| Container( | Container( | ||||
| padding: EdgeInsets.only( | |||||
| top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| border: Border( | border: Border( | ||||
| bottom: BorderSide( | |||||
| width: 1, | |||||
| color: isValid ? Colors.grey : Colors.red[900])), | |||||
| bottom: BorderSide( | |||||
| width: 1, | |||||
| color: isValid ? Colors.grey : Colors.red, | |||||
| ), | |||||
| ), | |||||
| ), | ), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, | ||||
| children: [ | children: [ | ||||
| Text( | Text( | ||||
| 'Tên thương mại *', | 'Tên thương mại *', | ||||
| style: TextStyle( | |||||
| fontSize: 13, | |||||
| fontWeight: FontWeight.normal, | |||||
| color: | |||||
| isValid ? Colors.black54 : Colors.red[600]), | |||||
| style: TextStyle(fontSize: 13, fontWeight: FontWeight.normal, color: isValid ? Colors.black54 : Colors.red[600]), | |||||
| ), | ), | ||||
| Row( | Row( | ||||
| children: [ | children: [ | ||||
| Expanded( | Expanded( | ||||
| child: Text( | |||||
| changeSelectedSupply.selectedSupplyName ?? | |||||
| "Tên thương mại", | |||||
| style: TextStyle( | |||||
| fontSize: 14.0, | |||||
| color: Colors.black87))), | |||||
| Icon( | |||||
| child: Text(changeSelectedSupply.selectedSupplyName ?? "Tên thương mại", | |||||
| style: const TextStyle(fontSize: 14.0, color: Colors.black87))), | |||||
| const Icon( | |||||
| Icons.arrow_drop_down, | Icons.arrow_drop_down, | ||||
| color: Colors.grey, | color: Colors.grey, | ||||
| ), | ), | ||||
| ) | ) | ||||
| ], | ], | ||||
| )), | )), | ||||
| isValid ? SizedBox() : WidgetErrorTextField() | |||||
| isValid ? const SizedBox() : WidgetErrorTextField() | |||||
| ], | ], | ||||
| ); | ); | ||||
| })); | })); | ||||
| Widget _btnSelectDevice() { | Widget _btnSelectDevice() { | ||||
| return GetBuilder<ChangeDevice>(builder: (data) { | return GetBuilder<ChangeDevice>(builder: (data) { | ||||
| return FlatButton( | return FlatButton( | ||||
| padding: | |||||
| EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| onPressed: () { | onPressed: () { | ||||
| Navigator.of(context) | Navigator.of(context) | ||||
| .push(MaterialPageRoute( | |||||
| builder: (_) => ListDeviceActivity( | |||||
| selectedId: changeSelectedDevice.selectedDeviceId), | |||||
| fullscreenDialog: false)) | |||||
| .push( | |||||
| MaterialPageRoute(builder: (_) => ListDeviceActivity(selectedId: changeSelectedDevice.selectedDeviceId), fullscreenDialog: false)) | |||||
| .then((value) { | .then((value) { | ||||
| if (value != null) { | if (value != null) { | ||||
| var result = value as Device; | var result = value as Device; | ||||
| }); | }); | ||||
| }, | }, | ||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.only( | |||||
| top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: BoxDecoration( | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: const BoxDecoration( | |||||
| border: kBorderTextField, | border: kBorderTextField, | ||||
| ), | ), | ||||
| child: Row( | child: Row( | ||||
| children: [ | children: [ | ||||
| GetBuilder<ChangeSupply>( | GetBuilder<ChangeSupply>( | ||||
| builder: (_) => Expanded( | builder: (_) => Expanded( | ||||
| child: Text( | |||||
| changeSelectedDevice.selectedDeviceName ?? | |||||
| "Thiết bị", | |||||
| style: TextStyle( | |||||
| fontSize: 14.0, color: Colors.black87)))), | |||||
| Icon( | |||||
| child: Text(changeSelectedDevice.selectedDeviceName ?? "Thiết bị", | |||||
| style: const TextStyle(fontSize: 14.0, color: Colors.black87)))), | |||||
| const Icon( | |||||
| Icons.arrow_drop_down, | Icons.arrow_drop_down, | ||||
| color: Colors.grey, | color: Colors.grey, | ||||
| ), | ), | ||||
| var oldSelected = data.selectedUnit; | var oldSelected = data.selectedUnit; | ||||
| if (oldSelected == value) { | if (oldSelected == value) { | ||||
| } else { | } else { | ||||
| assignValue = UtilAction.convertUnit( | |||||
| inputValue: assignValue, | |||||
| oldUnit: oldSelected, | |||||
| newUnit: value); | |||||
| assignValue = UtilAction.convertUnit(inputValue: assignValue, oldUnit: oldSelected, newUnit: value ?? ''); | |||||
| } | } | ||||
| _quantityController.text = assignValue.formatNumtoStringDecimal(); | _quantityController.text = assignValue.formatNumtoStringDecimal(); | ||||
| } | } | ||||
| changeUnit.updateSelected(value); | |||||
| changeUnit.updateSelected(value ?? ''); | |||||
| }, | }, | ||||
| ); | ); | ||||
| }); | }); | ||||
| return WidgetTextFormFieldNumber( | return WidgetTextFormFieldNumber( | ||||
| hintValue: "Tổng lượng sử dụng *", | hintValue: "Tổng lượng sử dụng *", | ||||
| textController: _quantityController, | textController: _quantityController, | ||||
| validator: (String value) { | |||||
| return Validators.validateNotNullOrEmpty( | |||||
| value, label_validate_input_empty); | |||||
| validator: (String? value) { | |||||
| // return Validators.validateNotNullOrEmpty(value, label_validate_input_empty); | |||||
| }, | }, | ||||
| onChanged: (value) { | onChanged: (value) { | ||||
| if (!Validators.stringNotNullOrEmpty(value) && | if (!Validators.stringNotNullOrEmpty(value) && | ||||
| changeFormField.change(true); | changeFormField.change(true); | ||||
| } | } | ||||
| }, | }, | ||||
| onSaved: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||||
| children: [ | children: [ | ||||
| _.isEdit | _.isEdit | ||||
| ? OutlineButton( | |||||
| shape: RoundedRectangleBorder( | |||||
| borderRadius: new BorderRadius.circular(8.0)), | |||||
| child: Text("Huỷ"), | |||||
| onPressed: () { | |||||
| ? InkWell( | |||||
| // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), | |||||
| child: const Text("Huỷ"), | |||||
| onTap: () { | |||||
| changeButton.resetValue(); | changeButton.resetValue(); | ||||
| _resetForm(); | _resetForm(); | ||||
| _hidenKeyboard(context); | _hidenKeyboard(context); | ||||
| }) | }) | ||||
| : SizedBox(), | |||||
| : const SizedBox(), | |||||
| _.isEdit | _.isEdit | ||||
| ? Expanded( | ? Expanded( | ||||
| child: FlatButton( | child: FlatButton( | ||||
| onPressed: () { | onPressed: () { | ||||
| if (_formSupplyKey.currentState.validate()) { | |||||
| _formSupplyKey.currentState.save(); | |||||
| if (_formSupplyKey.currentState!.validate()) { | |||||
| _formSupplyKey.currentState!.save(); | |||||
| if (changeSelectedSupply.selectedSupplyId <= 0) { | if (changeSelectedSupply.selectedSupplyId <= 0) { | ||||
| changeSelectedSupply.changeValid(false); | changeSelectedSupply.changeValid(false); | ||||
| } else { | } else { | ||||
| changeSelectedSupply.changeValid(true); | changeSelectedSupply.changeValid(true); | ||||
| } | } | ||||
| var currentSupply = | |||||
| changeSelectedSupply.currentSupply; | |||||
| var currentDevice = | |||||
| changeSelectedDevice.currentDevice; | |||||
| var currentQuantity = | |||||
| _quantityController.text.parseDoubleThousand(); | |||||
| if (currentSupply.id != null && | |||||
| (currentQuantity ?? 0) > 0) { | |||||
| var quantityWithCurrentSupplyUnit = | |||||
| UtilAction.convertUnit( | |||||
| inputValue: currentQuantity, | |||||
| oldUnit: changeUnit.selectedUnit, | |||||
| newUnit: changeSelectedSupply | |||||
| .currentSupply.unit); | |||||
| SuppliesUsing newSup = SuppliesUsing() | |||||
| var currentSupply = changeSelectedSupply.currentSupply; | |||||
| var currentDevice = changeSelectedDevice.currentDevice; | |||||
| var currentQuantity = _quantityController.text.parseDoubleThousand(); | |||||
| if (currentSupply.id != null && (currentQuantity ?? 0) > 0) { | |||||
| var quantityWithCurrentSupplyUnit = UtilAction.convertUnit( | |||||
| inputValue: currentQuantity, | |||||
| oldUnit: changeUnit.selectedUnit, | |||||
| newUnit: changeSelectedSupply.currentSupply.unit ?? '', | |||||
| ); | |||||
| var newSup = SuppliesUsing() | |||||
| ..dosage = _dosageController.text | ..dosage = _dosageController.text | ||||
| ..howToUse = _howToUseController.text | ..howToUse = _howToUseController.text | ||||
| ..quantity = quantityWithCurrentSupplyUnit | ..quantity = quantityWithCurrentSupplyUnit | ||||
| ..equipmentName = currentDevice.name | ..equipmentName = currentDevice.name | ||||
| ..supplyUnit = currentSupply.unit | ..supplyUnit = currentSupply.unit | ||||
| ..unit = currentSupply.unit; | ..unit = currentSupply.unit; | ||||
| changeSupplyUsing.editSupply( | |||||
| changeSupplyUsing.currentIndex, newSup); | |||||
| changeSupplyUsing.editSupply(changeSupplyUsing.currentIndex, newSup); | |||||
| _resetForm(); | _resetForm(); | ||||
| _hidenKeyboard(context); | _hidenKeyboard(context); | ||||
| } else if (currentSupply.id == null || | |||||
| ((currentQuantity ?? 0) <= 0)) { | |||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập vật tư và số lượng"); | |||||
| } else if (currentSupply.id == null || ((currentQuantity ?? 0) <= 0)) { | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập vật tư và số lượng"); | |||||
| } | } | ||||
| } else { | } else { | ||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập vật tư và số lượng"); | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập vật tư và số lượng"); | |||||
| if (changeSelectedSupply.selectedSupplyId <= 0) { | if (changeSelectedSupply.selectedSupplyId <= 0) { | ||||
| changeSelectedSupply.changeValid(false); | changeSelectedSupply.changeValid(false); | ||||
| } else { | } else { | ||||
| } | } | ||||
| } | } | ||||
| }, | }, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Sửa phân bón", | "Sửa phân bón", | ||||
| style: TextStyle(color: Colors.blue), | style: TextStyle(color: Colors.blue), | ||||
| )), | )), | ||||
| : Expanded( | : Expanded( | ||||
| child: FlatButton( | child: FlatButton( | ||||
| onPressed: () { | onPressed: () { | ||||
| if (_formSupplyKey.currentState.validate()) { | |||||
| _formSupplyKey.currentState.save(); | |||||
| if (_formSupplyKey.currentState!.validate()) { | |||||
| _formSupplyKey.currentState!.save(); | |||||
| if (changeSelectedSupply.selectedSupplyId <= 0) { | if (changeSelectedSupply.selectedSupplyId <= 0) { | ||||
| changeSelectedSupply.changeValid(false); | changeSelectedSupply.changeValid(false); | ||||
| } else { | } else { | ||||
| changeSelectedSupply.changeValid(true); | changeSelectedSupply.changeValid(true); | ||||
| } | } | ||||
| var currentSupply = | |||||
| changeSelectedSupply.currentSupply; | |||||
| var currentDevice = | |||||
| changeSelectedDevice.currentDevice; | |||||
| var currentQuantity = | |||||
| _quantityController.text.parseDoubleThousand(); | |||||
| if (currentSupply.id != null && | |||||
| (currentQuantity ?? 0) > 0) { | |||||
| var quantityWithCurrentSupplyUnit = | |||||
| UtilAction.convertUnit( | |||||
| inputValue: currentQuantity, | |||||
| oldUnit: changeUnit.selectedUnit, | |||||
| newUnit: changeSelectedSupply | |||||
| .currentSupply.unit); | |||||
| SuppliesUsing newSup = SuppliesUsing() | |||||
| var currentSupply = changeSelectedSupply.currentSupply; | |||||
| var currentDevice = changeSelectedDevice.currentDevice; | |||||
| var currentQuantity = _quantityController.text.parseDoubleThousand(); | |||||
| if (currentSupply.id != null && (currentQuantity ?? 0) > 0) { | |||||
| var quantityWithCurrentSupplyUnit = UtilAction.convertUnit( | |||||
| inputValue: currentQuantity, | |||||
| oldUnit: changeUnit.selectedUnit, | |||||
| newUnit: changeSelectedSupply.currentSupply.unit ?? '', | |||||
| ); | |||||
| var newSup = SuppliesUsing() | |||||
| ..dosage = _dosageController.text | ..dosage = _dosageController.text | ||||
| ..howToUse = _howToUseController.text | ..howToUse = _howToUseController.text | ||||
| ..quantity = quantityWithCurrentSupplyUnit | ..quantity = quantityWithCurrentSupplyUnit | ||||
| changeSupplyUsing.addSupply(newSup); | changeSupplyUsing.addSupply(newSup); | ||||
| _resetForm(); | _resetForm(); | ||||
| _hidenKeyboard(context); | _hidenKeyboard(context); | ||||
| } else if (currentSupply.id == null || | |||||
| ((currentQuantity ?? 0) <= 0)) { | |||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập vật tư và số lượng"); | |||||
| } else if (currentSupply.id == null || ((currentQuantity ?? 0) <= 0)) { | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập vật tư và số lượng"); | |||||
| } | } | ||||
| } else { | } else { | ||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập vật tư và số lượng"); | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập vật tư và số lượng"); | |||||
| if (changeSelectedSupply.selectedSupplyId <= 0) { | if (changeSelectedSupply.selectedSupplyId <= 0) { | ||||
| changeSelectedSupply.changeValid(false); | changeSelectedSupply.changeValid(false); | ||||
| } else { | } else { | ||||
| // | // | ||||
| } | } | ||||
| }, | }, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "+ Thêm phân bón", | "+ Thêm phân bón", | ||||
| style: TextStyle(color: Colors.blue), | style: TextStyle(color: Colors.blue), | ||||
| )), | )), | ||||
| child: Column( | child: Column( | ||||
| children: [ | children: [ | ||||
| Container( | Container( | ||||
| padding: EdgeInsets.all(8.0), | |||||
| margin: EdgeInsets.all(8.0), | |||||
| padding: const EdgeInsets.all(8.0), | |||||
| margin: const EdgeInsets.all(8.0), | |||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| shape: BoxShape.rectangle, | |||||
| borderRadius: BorderRadius.circular(10), | |||||
| color: Colors.white, | |||||
| border: Border.all(color: Colors.grey[300])), | |||||
| shape: BoxShape.rectangle, | |||||
| borderRadius: BorderRadius.circular(10), | |||||
| color: Colors.white, | |||||
| border: Border.all( | |||||
| color: Colors.grey, | |||||
| ), | |||||
| ), | |||||
| child: Column( | child: Column( | ||||
| children: [ | children: [ | ||||
| _btnSelectSubstrates(), | _btnSelectSubstrates(), | ||||
| TextFormField( | TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| controller: _dosageController, | controller: _dosageController, | ||||
| decoration: InputDecoration(labelText: "Liều lượng sử dụng"), | |||||
| decoration: const InputDecoration(labelText: "Liều lượng sử dụng"), | |||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| onChanged: (value) { | onChanged: (value) { | ||||
| if (!Validators.stringNotNullOrEmpty( | |||||
| _quantityController.text) && | |||||
| !Validators.stringNotNullOrEmpty( | |||||
| _howToUseController.text) && | |||||
| if (!Validators.stringNotNullOrEmpty(_quantityController.text) && | |||||
| !Validators.stringNotNullOrEmpty(_howToUseController.text) && | |||||
| !Validators.stringNotNullOrEmpty(value) && | !Validators.stringNotNullOrEmpty(value) && | ||||
| Get.find<ChangeSupply>().selectedSupplyId <= 0 && | Get.find<ChangeSupply>().selectedSupplyId <= 0 && | ||||
| changeSelectedDevice.selectedDeviceId <= 0) { | changeSelectedDevice.selectedDeviceId <= 0) { | ||||
| child: _quantityField(), | child: _quantityField(), | ||||
| ), | ), | ||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| width: 16.0, | width: 16.0, | ||||
| ), | ), | ||||
| Expanded( | Expanded( | ||||
| ]), | ]), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Thiết bị", | "Thiết bị", | ||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | style: TextStyle(color: Colors.black54, fontSize: 13.0), | ||||
| ), | ), | ||||
| TextFormField( | TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| controller: _howToUseController, | controller: _howToUseController, | ||||
| decoration: InputDecoration(labelText: "Phương pháp sử dụng"), | |||||
| decoration: const InputDecoration(labelText: "Phương pháp sử dụng"), | |||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| onChanged: (value) { | onChanged: (value) { | ||||
| if (!Validators.stringNotNullOrEmpty( | |||||
| _quantityController.text) && | |||||
| if (!Validators.stringNotNullOrEmpty(_quantityController.text) && | |||||
| !Validators.stringNotNullOrEmpty(value) && | !Validators.stringNotNullOrEmpty(value) && | ||||
| !Validators.stringNotNullOrEmpty( | |||||
| _dosageController.text) && | |||||
| !Validators.stringNotNullOrEmpty(_dosageController.text) && | |||||
| Get.find<ChangeSupply>().selectedSupplyId <= 0 && | Get.find<ChangeSupply>().selectedSupplyId <= 0 && | ||||
| changeSelectedDevice.selectedDeviceId <= 0) { | changeSelectedDevice.selectedDeviceId <= 0) { | ||||
| changeFormField.change(false); | changeFormField.change(false); | ||||
| } | } | ||||
| _hidenKeyboard(BuildContext context) { | _hidenKeyboard(BuildContext context) { | ||||
| FocusScopeNode currentFocus = FocusScope.of(context); | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | if (!currentFocus.hasPrimaryFocus) { | ||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return Column( | return Column( | ||||
| children: [ | children: [ | ||||
| Padding( | |||||
| padding: const EdgeInsets.all(8.0), | |||||
| const Padding( | |||||
| padding: EdgeInsets.all(8.0), | |||||
| child: Align( | child: Align( | ||||
| alignment: Alignment.centerLeft, | alignment: Alignment.centerLeft, | ||||
| child: Text( | child: Text( | ||||
| ), | ), | ||||
| ), | ), | ||||
| _buildListSupply(), | _buildListSupply(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _formEdit(), | _formEdit(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], |
| class EditActionEndScreen extends StatefulWidget { | class EditActionEndScreen extends StatefulWidget { | ||||
| final int cropId; | final int cropId; | ||||
| final bool isEdit; | final bool isEdit; | ||||
| final int activityId; | |||||
| EditActionEndScreen( | |||||
| {@required this.cropId, this.isEdit = false, this.activityId}); | |||||
| final int? activityId; | |||||
| EditActionEndScreen({required this.cropId, this.isEdit = false, this.activityId}); | |||||
| @override | @override | ||||
| _EditActionEndScreenState createState() => _EditActionEndScreenState(); | _EditActionEndScreenState createState() => _EditActionEndScreenState(); | ||||
| } | } | ||||
| class _EditActionEndScreenState extends State<EditActionEndScreen> { | class _EditActionEndScreenState extends State<EditActionEndScreen> { | ||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |||||
| final _repository = Repository(); | final _repository = Repository(); | ||||
| GlobalKey<FormState> _formKey = GlobalKey(); | GlobalKey<FormState> _formKey = GlobalKey(); | ||||
| bool _autoValidate = false; | bool _autoValidate = false; | ||||
| var pref = LocalPref(); | var pref = LocalPref(); | ||||
| DateTime executeTime = DateTime.now(); | DateTime executeTime = DateTime.now(); | ||||
| List<String> filePaths = List<String>(); | |||||
| List<String> filePaths = <String>[]; | |||||
| var changeFileController = Get.put(ChangeFileController()); | var changeFileController = Get.put(ChangeFileController()); | ||||
| Future<Null> getSharedPrefs() async { | Future<Null> getSharedPrefs() async { | ||||
| } | } | ||||
| _validateInputs() async { | _validateInputs() async { | ||||
| if (_formKey.currentState.validate()) { | |||||
| _formKey.currentState.save(); | |||||
| if (_formKey.currentState!.validate()) { | |||||
| _formKey.currentState!.save(); | |||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| filePaths = Get.find<ChangeFileController>().newFiles; | filePaths = Get.find<ChangeFileController>().newFiles; | ||||
| try { | try { | ||||
| }, (error) { | }, (error) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| Utils.showSnackBarError(message: AppException.handleError(error)); | Utils.showSnackBarError(message: AppException.handleError(error)); | ||||
| }, | |||||
| apiAddAction: ConstCommon.apiAddEnd, | |||||
| paramActivity: ConstCommon.paramsActionEnd, | |||||
| activityAction: activityEnd, | |||||
| filePaths: filePaths); | |||||
| }, apiAddAction: ConstCommon.apiAddEnd, paramActivity: ConstCommon.paramsActionEnd, activityAction: activityEnd, filePaths: filePaths); | |||||
| } else { | } else { | ||||
| //UPDATE | //UPDATE | ||||
| _repository.updateAction((value) { | _repository.updateAction((value) { | ||||
| return WidgetFieldDateTimePicker( | return WidgetFieldDateTimePicker( | ||||
| initDateTime: executeTime, | initDateTime: executeTime, | ||||
| onUpdateDateTime: (selectedDate) { | onUpdateDateTime: (selectedDate) { | ||||
| _end.executeDate = | |||||
| selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _end.executeDate = selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| }); | }); | ||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Người thực hiện"), | |||||
| decoration: const InputDecoration(labelText: "Người thực hiện"), | |||||
| enabled: false, | enabled: false, | ||||
| controller: _executeByController, | controller: _executeByController, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| appBar: AppBarWidget( | appBar: AppBarWidget( | ||||
| isBack: true, | isBack: true, | ||||
| action: InkWell( | action: InkWell( | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Huỷ', | 'Huỷ', | ||||
| style: TextStyle( | |||||
| color: Colors.red, fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: Colors.red, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| onTap: () { | onTap: () { | ||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| child: MultiBlocProvider( | child: MultiBlocProvider( | ||||
| providers: [ | providers: [ | ||||
| BlocProvider<ActionDetailBloc>( | BlocProvider<ActionDetailBloc>( | ||||
| create: (context) => | |||||
| ActionDetailBloc(repository: Repository()) | |||||
| ..add(FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailEnd, | |||||
| activityId: widget.activityId))), | |||||
| create: (context) => ActionDetailBloc(repository: Repository()) | |||||
| ..add( | |||||
| FetchData(isNeedFetchData: widget.isEdit, apiActivity: ConstCommon.apiDetailEnd, activityId: widget.activityId ?? -1), | |||||
| ), | |||||
| ), | |||||
| BlocProvider<MediaHelperBloc>( | BlocProvider<MediaHelperBloc>( | ||||
| create: (context) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| ) | ) | ||||
| ], | ], | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | |||||
| // autovalidate: _autoValidate, | |||||
| child: SafeArea( | child: SafeArea( | ||||
| child: SingleChildScrollView( | child: SingleChildScrollView( | ||||
| child: | |||||
| BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | listener: (context, state) async { | ||||
| if (state is ActionDetailFailure) { | if (state is ActionDetailFailure) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| } else if (state is ActionDetailSuccess) { | } else if (state is ActionDetailSuccess) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| _end = End.fromJson(state.item); | _end = End.fromJson(state.item); | ||||
| _end.activityId = widget.activityId; | |||||
| _descriptionController.text = | |||||
| _end.description ?? ""; | |||||
| _executeByController.text = _end.createdByName; | |||||
| _end.activityId = widget.activityId ?? -1; | |||||
| _descriptionController.text = _end.description ?? ""; | |||||
| _executeByController.text = _end.createdByName ?? ''; | |||||
| Get.find<ChangeDateTimePicker>().change(_end | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| Get.find<ChangeDateTimePicker>().change( | |||||
| _end.executeDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now(), | |||||
| ); | |||||
| //Show media | //Show media | ||||
| if (Validators.stringNotNullOrEmpty(_end.media)) { | |||||
| if (Validators.stringNotNullOrEmpty(_end.media ?? '')) { | |||||
| BlocProvider.of<MediaHelperBloc>(context).add( | BlocProvider.of<MediaHelperBloc>(context).add( | ||||
| ChangeListMedia( | |||||
| items: | |||||
| UtilAction.convertFilePathToMedia( | |||||
| _end.media))); | |||||
| ChangeListMedia( | |||||
| items: UtilAction.convertFilePathToMedia(_end.media ?? ''), | |||||
| ), | |||||
| ); | |||||
| } | } | ||||
| } else if (state is ActionDetailInitial) { | } else if (state is ActionDetailInitial) { | ||||
| } else if (state is ActionDetailLoading) { | } else if (state is ActionDetailLoading) { | ||||
| Padding( | Padding( | ||||
| padding: const EdgeInsets.all(8.0), | padding: const EdgeInsets.all(8.0), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: | |||||
| CrossAxisAlignment.start, | |||||
| crossAxisAlignment: CrossAxisAlignment.start, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text( | |||||
| const Text( | |||||
| plot_action_finish, | plot_action_finish, | ||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.w500, | |||||
| fontSize: 22), | |||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | |||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Ngày thực hiện *", | "Ngày thực hiện *", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnExecuteTimePicker(), | _btnExecuteTimePicker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _descriptionField(), | _descriptionField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _executeByField(), | _executeByField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| return WidgetMediaPicker( | return WidgetMediaPicker( | ||||
| currentItems: state.items, | currentItems: state.items, | ||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>() | |||||
| .change(newPathFiles, | |||||
| deletePathFiles); | |||||
| onChangeFiles: (newPathFiles, deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change(newPathFiles, deletePathFiles); | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| child: CircularProgressIndicator()); | |||||
| return const Center(child: CircularProgressIndicator()); | |||||
| } | } | ||||
| }), | }), | ||||
| Padding( | Padding( | ||||
| child: ButtonWidget( | child: ButtonWidget( | ||||
| title: 'CẬP NHẬT', | title: 'CẬP NHẬT', | ||||
| onPressed: () { | onPressed: () { | ||||
| FocusScopeNode currentFocus = | |||||
| FocusScope.of(context); | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | if (!currentFocus.hasPrimaryFocus) { | ||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } |
| class EditActionEnvironmentUpdate extends StatefulWidget { | class EditActionEnvironmentUpdate extends StatefulWidget { | ||||
| final int cropId; | final int cropId; | ||||
| final bool isEdit; | final bool isEdit; | ||||
| final int activityId; | |||||
| EditActionEnvironmentUpdate( | |||||
| {@required this.cropId, this.isEdit = false, this.activityId}); | |||||
| final int? activityId; | |||||
| EditActionEnvironmentUpdate({required this.cropId, this.isEdit = false, this.activityId}); | |||||
| @override | @override | ||||
| _EditActionEnvironmentUpdateState createState() => | |||||
| _EditActionEnvironmentUpdateState(); | |||||
| _EditActionEnvironmentUpdateState createState() => _EditActionEnvironmentUpdateState(); | |||||
| } | } | ||||
| class _EditActionEnvironmentUpdateState | |||||
| extends State<EditActionEnvironmentUpdate> { | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| class _EditActionEnvironmentUpdateState extends State<EditActionEnvironmentUpdate> { | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |||||
| final _repository = Repository(); | final _repository = Repository(); | ||||
| GlobalKey<FormState> _formKey = GlobalKey(); | GlobalKey<FormState> _formKey = GlobalKey(); | ||||
| bool _autoValidate = false; | bool _autoValidate = false; | ||||
| final _executeByController = TextEditingController(); | final _executeByController = TextEditingController(); | ||||
| DateTime executeTime = DateTime.now(); | DateTime executeTime = DateTime.now(); | ||||
| List<String> filePaths = List<String>(); | |||||
| List<String> filePaths = <String>[]; | |||||
| var changeFileController = Get.put(ChangeFileController()); | var changeFileController = Get.put(ChangeFileController()); | ||||
| Future<Null> getSharedPrefs() async { | Future<Null> getSharedPrefs() async { | ||||
| } | } | ||||
| _validateInputs() async { | _validateInputs() async { | ||||
| if (_formKey.currentState.validate()) { | |||||
| _formKey.currentState.save(); | |||||
| if (_formKey.currentState!.validate()) { | |||||
| _formKey.currentState!.save(); | |||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| filePaths = Get.find<ChangeFileController>().newFiles; | filePaths = Get.find<ChangeFileController>().newFiles; | ||||
| //Create request general model | //Create request general model | ||||
| try { | try { | ||||
| RequestEnvironment requestEnvironment = RequestEnvironment() | |||||
| var requestEnvironment = RequestEnvironment() | |||||
| ..cropId = _environment.cropId | ..cropId = _environment.cropId | ||||
| ..activityId = _environment.activityId | ..activityId = _environment.activityId | ||||
| ..executeDate = _environment.executeDate; | ..executeDate = _environment.executeDate; | ||||
| var envDetail = List<EnvDetail>(); | |||||
| var envDetail = <EnvDetail>[]; | |||||
| envDetail.add(EnvDetail() | envDetail.add(EnvDetail() | ||||
| ..name = "EC" | ..name = "EC" | ||||
| ..index = _environment.ec); | ..index = _environment.ec); | ||||
| ..name = "LLN" | ..name = "LLN" | ||||
| ..index = _environment.lln); | ..index = _environment.lln); | ||||
| requestEnvironment.envDetail = envDetail; | requestEnvironment.envDetail = envDetail; | ||||
| requestEnvironment.mediaDel = | |||||
| Get.find<ChangeFileController>().deleteFiles; | |||||
| var activityEnvironmentUpdate = | |||||
| jsonEncode(requestEnvironment.toJson()).toString(); | |||||
| requestEnvironment.mediaDel = Get.find<ChangeFileController>().deleteFiles; | |||||
| var activityEnvironmentUpdate = jsonEncode(requestEnvironment.toJson()).toString(); | |||||
| //ADD NEW | //ADD NEW | ||||
| if (_environment.activityId == null) { | if (_environment.activityId == null) { | ||||
| _repository.createAction((value) { | _repository.createAction((value) { | ||||
| return WidgetFieldDateTimePicker( | return WidgetFieldDateTimePicker( | ||||
| initDateTime: executeTime, | initDateTime: executeTime, | ||||
| onUpdateDateTime: (selectedDate) { | onUpdateDateTime: (selectedDate) { | ||||
| _environment.executeDate = | |||||
| selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _environment.executeDate = selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| }); | }); | ||||
| } | } | ||||
| hintValue: "EC", | hintValue: "EC", | ||||
| textController: _ecController, | textController: _ecController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _environment.ec = newValue; | |||||
| _environment.ec = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "pH", | hintValue: "pH", | ||||
| textController: _phController, | textController: _phController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _environment.pH = newValue; | |||||
| _environment.pH = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Nhiệt độ dung dịch", | hintValue: "Nhiệt độ dung dịch", | ||||
| textController: _ocddController, | textController: _ocddController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _environment.ocdd = newValue; | |||||
| _environment.ocdd = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Nhiệt độ môi trường", | hintValue: "Nhiệt độ môi trường", | ||||
| textController: _temperatureController, | textController: _temperatureController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _environment.temperature = newValue; | |||||
| _environment.temperature = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Độ ẩm", | hintValue: "Độ ẩm", | ||||
| textController: _doController, | textController: _doController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _environment.dodo = newValue; | |||||
| _environment.dodo = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Lưu lượng nước", | hintValue: "Lưu lượng nước", | ||||
| textController: _llnController, | textController: _llnController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _environment.lln = newValue; | |||||
| _environment.lln = newValue ?? ''; | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Người thực hiện"), | |||||
| decoration: const InputDecoration(labelText: "Người thực hiện"), | |||||
| enabled: false, | enabled: false, | ||||
| controller: _executeByController, | controller: _executeByController, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| appBar: AppBarWidget( | appBar: AppBarWidget( | ||||
| isBack: true, | isBack: true, | ||||
| action: InkWell( | action: InkWell( | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Huỷ', | 'Huỷ', | ||||
| style: TextStyle( | |||||
| color: Colors.red, fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: Colors.red, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| onTap: () { | onTap: () { | ||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| child: MultiBlocProvider( | child: MultiBlocProvider( | ||||
| providers: [ | providers: [ | ||||
| BlocProvider<ActionDetailBloc>( | BlocProvider<ActionDetailBloc>( | ||||
| create: (context) => | |||||
| ActionDetailBloc(repository: Repository()) | |||||
| ..add(FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailEnvUpdate, | |||||
| activityId: widget.activityId))), | |||||
| create: (context) => ActionDetailBloc(repository: Repository()) | |||||
| ..add( | |||||
| FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailEnvUpdate, | |||||
| activityId: widget.activityId ?? -1, | |||||
| ), | |||||
| ), | |||||
| ), | |||||
| BlocProvider<MediaHelperBloc>( | BlocProvider<MediaHelperBloc>( | ||||
| create: (context) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| ) | ) | ||||
| ], | ], | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | |||||
| // autovalidate: _autoValidate, | |||||
| child: SafeArea( | child: SafeArea( | ||||
| child: SingleChildScrollView( | child: SingleChildScrollView( | ||||
| child: | |||||
| BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | listener: (context, state) async { | ||||
| if (state is ActionDetailFailure) { | if (state is ActionDetailFailure) { | ||||
| print("fail"); | print("fail"); | ||||
| print(state.item); | print(state.item); | ||||
| _environment = Environment.fromJson(state.item); | _environment = Environment.fromJson(state.item); | ||||
| //Parse theo API :') | //Parse theo API :') | ||||
| _environment.environmentUpdates | |||||
| .forEach((envDetail) { | |||||
| _environment.environmentUpdates?.forEach((envDetail) { | |||||
| switch (envDetail.tbEnvironmentalName) { | switch (envDetail.tbEnvironmentalName) { | ||||
| case "EC": | case "EC": | ||||
| _environment.ec = | |||||
| envDetail.index.toString(); | |||||
| _environment.ec = envDetail.index.toString(); | |||||
| break; | break; | ||||
| case "pH": | case "pH": | ||||
| _environment.pH = | |||||
| envDetail.index.toString(); | |||||
| _environment.pH = envDetail.index.toString(); | |||||
| break; | break; | ||||
| case "OCDD": | case "OCDD": | ||||
| _environment.ocdd = | |||||
| envDetail.index.toString(); | |||||
| _environment.ocdd = envDetail.index.toString(); | |||||
| break; | break; | ||||
| case "TEMPERATURE": | case "TEMPERATURE": | ||||
| _environment.temperature = | |||||
| envDetail.index.toString(); | |||||
| _environment.temperature = envDetail.index.toString(); | |||||
| break; | break; | ||||
| case "DO": | case "DO": | ||||
| _environment.dodo = | |||||
| envDetail.index.toString(); | |||||
| _environment.dodo = envDetail.index.toString(); | |||||
| break; | break; | ||||
| case "LLN": | case "LLN": | ||||
| _environment.lln = | |||||
| envDetail.index.toString(); | |||||
| _environment.lln = envDetail.index.toString(); | |||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| }); | }); | ||||
| _environment.activityId = widget.activityId; | |||||
| _ecController.text = | |||||
| _environment.ec.formatStringToStringDecimal(); | |||||
| _phController.text = | |||||
| _environment.pH.formatStringToStringDecimal(); | |||||
| _ocddController.text = _environment.ocdd | |||||
| .formatStringToStringDecimal(); | |||||
| _temperatureController.text = _environment | |||||
| .temperature | |||||
| .formatStringToStringDecimal(); | |||||
| _doController.text = _environment.dodo | |||||
| .formatStringToStringDecimal(); | |||||
| _llnController.text = _environment.lln | |||||
| .formatStringToStringDecimal(); | |||||
| _executeByController.text = | |||||
| _environment.executeBy; | |||||
| _environment.activityId = widget.activityId ?? -1; | |||||
| _ecController.text = _environment.ec?.formatStringToStringDecimal() ?? ''; | |||||
| _phController.text = _environment.pH?.formatStringToStringDecimal() ?? ''; | |||||
| _ocddController.text = _environment.ocdd?.formatStringToStringDecimal() ?? ''; | |||||
| _temperatureController.text = _environment.temperature?.formatStringToStringDecimal() ?? ''; | |||||
| _doController.text = _environment.dodo?.formatStringToStringDecimal() ?? ''; | |||||
| _llnController.text = _environment.lln?.formatStringToStringDecimal() ?? ''; | |||||
| _executeByController.text = _environment.executeBy ?? ''; | |||||
| Get.find<ChangeDateTimePicker>().change(_environment | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| Get.find<ChangeDateTimePicker>().change( | |||||
| _environment.executeDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now(), | |||||
| ); | |||||
| //Show media | //Show media | ||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _environment.media)) { | |||||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||||
| ChangeListMedia( | |||||
| items: | |||||
| UtilAction.convertFilePathToMedia( | |||||
| _environment.media))); | |||||
| if (Validators.stringNotNullOrEmpty(_environment.media ?? '')) { | |||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| .add(ChangeListMedia(items: UtilAction.convertFilePathToMedia(_environment.media ?? ''))); | |||||
| } | } | ||||
| } else if (state is ActionDetailInitial) { | } else if (state is ActionDetailInitial) { | ||||
| print("init"); | print("init"); | ||||
| Padding( | Padding( | ||||
| padding: const EdgeInsets.all(8.0), | padding: const EdgeInsets.all(8.0), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: | |||||
| CrossAxisAlignment.start, | |||||
| crossAxisAlignment: CrossAxisAlignment.start, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text( | |||||
| const Text( | |||||
| plot_action_environment_update, | plot_action_environment_update, | ||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.w500, | |||||
| fontSize: 22), | |||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | |||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Ngày thực hiện *", | "Ngày thực hiện *", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnExecuteTimePicker(), | _btnExecuteTimePicker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _ecField(), | _ecField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _phField(), | _phField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _ocddField(), | _ocddField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _temperatureField(), | _temperatureField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _doField(), | _doField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _llnField(), | _llnField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _executeByField(), | _executeByField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| return WidgetMediaPicker( | return WidgetMediaPicker( | ||||
| currentItems: state.items, | currentItems: state.items, | ||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>() | |||||
| .change(newPathFiles, | |||||
| deletePathFiles); | |||||
| onChangeFiles: (newPathFiles, deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change(newPathFiles, deletePathFiles); | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| child: CircularProgressIndicator()); | |||||
| return const Center(child: CircularProgressIndicator()); | |||||
| } | } | ||||
| }), | }), | ||||
| Padding( | Padding( | ||||
| child: ButtonWidget( | child: ButtonWidget( | ||||
| title: 'CẬP NHẬT', | title: 'CẬP NHẬT', | ||||
| onPressed: () { | onPressed: () { | ||||
| FocusScopeNode currentFocus = | |||||
| FocusScope.of(context); | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | if (!currentFocus.hasPrimaryFocus) { | ||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } |
| class EditActionHarvestScreen extends StatefulWidget { | class EditActionHarvestScreen extends StatefulWidget { | ||||
| final int cropId; | final int cropId; | ||||
| final bool isEdit; | final bool isEdit; | ||||
| final int activityId; | |||||
| EditActionHarvestScreen( | |||||
| {@required this.cropId, this.isEdit = false, this.activityId}); | |||||
| final int? activityId; | |||||
| EditActionHarvestScreen({required this.cropId, this.isEdit = false, this.activityId}); | |||||
| @override | @override | ||||
| _EditActionHarvestScreenState createState() => | |||||
| _EditActionHarvestScreenState(); | |||||
| _EditActionHarvestScreenState createState() => _EditActionHarvestScreenState(); | |||||
| } | } | ||||
| class _EditActionHarvestScreenState extends State<EditActionHarvestScreen> { | class _EditActionHarvestScreenState extends State<EditActionHarvestScreen> { | ||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |||||
| final _repository = Repository(); | final _repository = Repository(); | ||||
| GlobalKey<FormState> _formKey = GlobalKey(); | GlobalKey<FormState> _formKey = GlobalKey(); | ||||
| bool _autoValidate = false; | bool _autoValidate = false; | ||||
| var pref = LocalPref(); | var pref = LocalPref(); | ||||
| DateTime executeTime = DateTime.now(); | DateTime executeTime = DateTime.now(); | ||||
| List<String> filePaths = List<String>(); | |||||
| List<String> filePaths = <String>[]; | |||||
| var changeFileController = Get.put(ChangeFileController()); | var changeFileController = Get.put(ChangeFileController()); | ||||
| Future<Null> getSharedPrefs() async { | Future<Null> getSharedPrefs() async { | ||||
| } | } | ||||
| _validateInputs() async { | _validateInputs() async { | ||||
| if (_formKey.currentState.validate()) { | |||||
| _formKey.currentState.save(); | |||||
| if (_formKey.currentState!.validate()) { | |||||
| _formKey.currentState!.save(); | |||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| filePaths = Get.find<ChangeFileController>().newFiles; | filePaths = Get.find<ChangeFileController>().newFiles; | ||||
| try { | try { | ||||
| return WidgetFieldDateTimePicker( | return WidgetFieldDateTimePicker( | ||||
| initDateTime: executeTime, | initDateTime: executeTime, | ||||
| onUpdateDateTime: (selectedDate) { | onUpdateDateTime: (selectedDate) { | ||||
| _harvest.executeDate = | |||||
| selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _harvest.executeDate = selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| }); | }); | ||||
| } | } | ||||
| hintValue: "Số lượng/khối lượng loại 1", | hintValue: "Số lượng/khối lượng loại 1", | ||||
| textController: _l1Controller, | textController: _l1Controller, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _harvest.collectedQuantityLv1 = newValue.parseDoubleThousand(); | |||||
| _harvest.collectedQuantityLv1 = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lượng/khối lượng loại 2", | hintValue: "Số lượng/khối lượng loại 2", | ||||
| textController: _l2Controller, | textController: _l2Controller, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _harvest.collectedQuantityLv2 = newValue.parseDoubleThousand(); | |||||
| _harvest.collectedQuantityLv2 = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lượng/khối lượng loại 3", | hintValue: "Số lượng/khối lượng loại 3", | ||||
| textController: _l3Controller, | textController: _l3Controller, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _harvest.collectedQuantityLv3 = newValue.parseDoubleThousand(); | |||||
| _harvest.collectedQuantityLv3 = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lượng/khối lượng loại bỏ", | hintValue: "Số lượng/khối lượng loại bỏ", | ||||
| textController: _removedQuantityController, | textController: _removedQuantityController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _harvest.removedQuantity = newValue.parseDoubleThousand(); | |||||
| _harvest.removedQuantity = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Người thực hiện"), | |||||
| decoration: const InputDecoration(labelText: "Người thực hiện"), | |||||
| enabled: false, | enabled: false, | ||||
| controller: _executeByController, | controller: _executeByController, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| appBar: AppBarWidget( | appBar: AppBarWidget( | ||||
| isBack: true, | isBack: true, | ||||
| action: InkWell( | action: InkWell( | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Huỷ', | 'Huỷ', | ||||
| style: TextStyle( | |||||
| color: Colors.red, fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: Colors.red, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| onTap: () { | onTap: () { | ||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| child: MultiBlocProvider( | child: MultiBlocProvider( | ||||
| providers: [ | providers: [ | ||||
| BlocProvider<ActionDetailBloc>( | BlocProvider<ActionDetailBloc>( | ||||
| create: (context) => | |||||
| ActionDetailBloc(repository: Repository()) | |||||
| ..add(FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailHarvest, | |||||
| activityId: widget.activityId))), | |||||
| create: (context) => ActionDetailBloc(repository: Repository()) | |||||
| ..add( | |||||
| FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailHarvest, | |||||
| activityId: widget.activityId ?? -1, | |||||
| ), | |||||
| ), | |||||
| ), | |||||
| BlocProvider<MediaHelperBloc>( | BlocProvider<MediaHelperBloc>( | ||||
| create: (context) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| ) | ) | ||||
| ], | ], | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | |||||
| // autovalidate: _autoValidate, | |||||
| child: SafeArea( | child: SafeArea( | ||||
| child: SingleChildScrollView( | child: SingleChildScrollView( | ||||
| child: | |||||
| BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | listener: (context, state) async { | ||||
| if (state is ActionDetailFailure) { | if (state is ActionDetailFailure) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| print(state.item); | print(state.item); | ||||
| _harvest = Harvest.fromJson(state.item); | _harvest = Harvest.fromJson(state.item); | ||||
| _harvest.activityId = widget.activityId; | |||||
| _l1Controller.text = _harvest.collectedQuantityLv1 | |||||
| .formatNumtoStringDecimal(); | |||||
| _l2Controller.text = _harvest.collectedQuantityLv2 | |||||
| .formatNumtoStringDecimal(); | |||||
| _l3Controller.text = _harvest.collectedQuantityLv3 | |||||
| .formatNumtoStringDecimal(); | |||||
| _removedQuantityController.text = _harvest | |||||
| .removedQuantity | |||||
| .formatNumtoStringDecimal(); | |||||
| _descriptionController.text = | |||||
| _harvest.description ?? ""; | |||||
| _executeByController.text = _harvest.executeBy; | |||||
| _harvest.activityId = widget.activityId ?? -1; | |||||
| _l1Controller.text = _harvest.collectedQuantityLv1?.formatNumtoStringDecimal() ?? ''; | |||||
| _l2Controller.text = _harvest.collectedQuantityLv2?.formatNumtoStringDecimal() ?? ''; | |||||
| _l3Controller.text = _harvest.collectedQuantityLv3?.formatNumtoStringDecimal() ?? ''; | |||||
| _removedQuantityController.text = _harvest.removedQuantity?.formatNumtoStringDecimal() ?? ''; | |||||
| _descriptionController.text = _harvest.description ?? ""; | |||||
| _executeByController.text = _harvest.executeBy ?? ''; | |||||
| Get.find<ChangeDateTimePicker>().change(_harvest | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| Get.find<ChangeDateTimePicker>() | |||||
| .change(_harvest.executeDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now()); | |||||
| //Show media | //Show media | ||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _harvest.media)) { | |||||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||||
| ChangeListMedia( | |||||
| items: | |||||
| UtilAction.convertFilePathToMedia( | |||||
| _harvest.media))); | |||||
| if (Validators.stringNotNullOrEmpty(_harvest.media ?? '')) { | |||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| .add(ChangeListMedia(items: UtilAction.convertFilePathToMedia(_harvest.media ?? ''))); | |||||
| } | } | ||||
| } else if (state is ActionDetailInitial) { | } else if (state is ActionDetailInitial) { | ||||
| } else if (state is ActionDetailLoading) { | } else if (state is ActionDetailLoading) { | ||||
| Padding( | Padding( | ||||
| padding: const EdgeInsets.all(8.0), | padding: const EdgeInsets.all(8.0), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: | |||||
| CrossAxisAlignment.start, | |||||
| crossAxisAlignment: CrossAxisAlignment.start, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text( | |||||
| const Text( | |||||
| plot_action_harvest, | plot_action_harvest, | ||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.w500, | |||||
| fontSize: 22), | |||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | |||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Ngày thực hiện *", | "Ngày thực hiện *", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnExecuteTimePicker(), | _btnExecuteTimePicker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _l1Field(), | _l1Field(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _l2Field(), | _l2Field(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _l3Field(), | _l3Field(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _removedQuantityField(), | _removedQuantityField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _descriptionField(), | _descriptionField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _executeByField(), | _executeByField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| return WidgetMediaPicker( | return WidgetMediaPicker( | ||||
| currentItems: state.items, | currentItems: state.items, | ||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>() | |||||
| .change(newPathFiles, | |||||
| deletePathFiles); | |||||
| onChangeFiles: (newPathFiles, deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change(newPathFiles, deletePathFiles); | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| child: CircularProgressIndicator()); | |||||
| return const Center(child: CircularProgressIndicator()); | |||||
| } | } | ||||
| }), | }), | ||||
| Container( | Container( | ||||
| harvestId: _harvest.id, | harvestId: _harvest.id, | ||||
| )); | )); | ||||
| } else { | } else { | ||||
| Get.to(EditActionHarvestProcessScreen( | |||||
| cropId: widget.cropId)); | |||||
| Get.to(EditActionHarvestProcessScreen(cropId: widget.cropId)); | |||||
| } | } | ||||
| }), | }), | ||||
| ButtonIconWidget( | ButtonIconWidget( | ||||
| harvestId: _harvest.id, | harvestId: _harvest.id, | ||||
| )); | )); | ||||
| } else { | } else { | ||||
| Get.to(EditActionPackingScreen( | |||||
| cropId: widget.cropId)); | |||||
| Get.to(EditActionPackingScreen(cropId: widget.cropId)); | |||||
| } | } | ||||
| }), | }), | ||||
| ButtonIconWidget( | ButtonIconWidget( | ||||
| harvestId: _harvest.id, | harvestId: _harvest.id, | ||||
| )); | )); | ||||
| } else { | } else { | ||||
| Get.to(EditActionSellScreen( | |||||
| cropId: widget.cropId)); | |||||
| Get.to(EditActionSellScreen(cropId: widget.cropId)); | |||||
| } | } | ||||
| }), | }), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 16, | height: 16, | ||||
| ), | ), | ||||
| Padding( | Padding( | ||||
| child: ButtonWidget( | child: ButtonWidget( | ||||
| title: 'CẬP NHẬT', | title: 'CẬP NHẬT', | ||||
| onPressed: () { | onPressed: () { | ||||
| FocusScopeNode currentFocus = | |||||
| FocusScope.of(context); | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | if (!currentFocus.hasPrimaryFocus) { | ||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } |
| class EditActionHarvestProcessScreen extends StatefulWidget { | class EditActionHarvestProcessScreen extends StatefulWidget { | ||||
| final int cropId; | final int cropId; | ||||
| final bool isEdit; | final bool isEdit; | ||||
| final int activityId; | |||||
| final int harvestId; | |||||
| EditActionHarvestProcessScreen( | |||||
| {@required this.cropId, | |||||
| this.isEdit = false, | |||||
| this.activityId, | |||||
| this.harvestId}); | |||||
| final int? activityId; | |||||
| final int? harvestId; | |||||
| EditActionHarvestProcessScreen({ | |||||
| required this.cropId, | |||||
| this.isEdit = false, | |||||
| this.activityId, | |||||
| this.harvestId, | |||||
| }); | |||||
| @override | @override | ||||
| _EditActionHarvestProcessScreenState createState() => | |||||
| _EditActionHarvestProcessScreenState(); | |||||
| _EditActionHarvestProcessScreenState createState() => _EditActionHarvestProcessScreenState(); | |||||
| } | } | ||||
| class _EditActionHarvestProcessScreenState | |||||
| extends State<EditActionHarvestProcessScreen> { | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| class _EditActionHarvestProcessScreenState extends State<EditActionHarvestProcessScreen> { | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |||||
| final _repository = Repository(); | final _repository = Repository(); | ||||
| GlobalKey<FormState> _formKey = GlobalKey(); | GlobalKey<FormState> _formKey = GlobalKey(); | ||||
| bool _autoValidate = false; | bool _autoValidate = false; | ||||
| TextEditingController _removedQuantityController = TextEditingController(); | TextEditingController _removedQuantityController = TextEditingController(); | ||||
| TextEditingController _descriptionController = TextEditingController(); | TextEditingController _descriptionController = TextEditingController(); | ||||
| final _executeByController = TextEditingController(); | final _executeByController = TextEditingController(); | ||||
| List<SuppliesUsing> suppliesUsing = new List<SuppliesUsing>(); | |||||
| List<SuppliesUsing> suppliesUsing = <SuppliesUsing>[]; | |||||
| var pref = LocalPref(); | var pref = LocalPref(); | ||||
| List<Harvest> _harvests = List<Harvest>(); | |||||
| Harvest harvestValue; | |||||
| String executeTimeView; | |||||
| List<Harvest> _harvests = <Harvest>[]; | |||||
| Harvest harvestValue = Harvest(); | |||||
| String executeTimeView = ''; | |||||
| DateTime executeTime = DateTime.now(); | DateTime executeTime = DateTime.now(); | ||||
| List<String> filePaths = List<String>(); | |||||
| List<String> filePaths = <String>[]; | |||||
| var changeFileController = Get.put(ChangeFileController()); | var changeFileController = Get.put(ChangeFileController()); | ||||
| Future<Null> getSharedPrefs() async { | Future<Null> getSharedPrefs() async { | ||||
| super.initState(); | super.initState(); | ||||
| getSharedPrefs(); | getSharedPrefs(); | ||||
| changeFileController.initValue(); | changeFileController.initValue(); | ||||
| _harvestProcess.suppliesUsing = new List<SuppliesUsing>(); | |||||
| _harvestProcess.executeDate = | |||||
| executeTime.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _harvestProcess.suppliesUsing = <SuppliesUsing>[]; | |||||
| _harvestProcess.executeDate = executeTime.convertLocalDateTimeToStringUtcDateTime(); | |||||
| executeTimeView = executeTime.displayDateTime_DDMMYYYY_HHmm(); | executeTimeView = executeTime.displayDateTime_DDMMYYYY_HHmm(); | ||||
| _harvestProcess.cropId = widget.cropId; | _harvestProcess.cropId = widget.cropId; | ||||
| } | } | ||||
| _validateInputs() async { | _validateInputs() async { | ||||
| if (_formKey.currentState.validate()) { | |||||
| _formKey.currentState.save(); | |||||
| if (_formKey.currentState!.validate()) { | |||||
| _formKey.currentState!.save(); | |||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| filePaths = Get.find<ChangeFileController>().newFiles; | filePaths = Get.find<ChangeFileController>().newFiles; | ||||
| List<SuppliesUsing> newSups = []; | |||||
| var newSups = <SuppliesUsing>[]; | |||||
| suppliesUsing.forEach((sup) { | suppliesUsing.forEach((sup) { | ||||
| var newSup = sup; | var newSup = sup; | ||||
| newSup.suppliesInWarehouseId = sup.tbSuppliesInWarehouseId; | newSup.suppliesInWarehouseId = sup.tbSuppliesInWarehouseId; | ||||
| _harvestProcess.suppliesUsing = newSups; | _harvestProcess.suppliesUsing = newSups; | ||||
| _harvestProcess.mediaDel = Get.find<ChangeFileController>().deleteFiles; | _harvestProcess.mediaDel = Get.find<ChangeFileController>().deleteFiles; | ||||
| try { | try { | ||||
| var activityHarvestProcess = | |||||
| jsonEncode(_harvestProcess.toJson()).toString(); | |||||
| var activityHarvestProcess = jsonEncode(_harvestProcess.toJson()).toString(); | |||||
| //ADD NEW | //ADD NEW | ||||
| if (_harvestProcess.activityId == null) { | if (_harvestProcess.activityId == null) { | ||||
| _repository.createAction((value) { | _repository.createAction((value) { | ||||
| if (snapshot.hasData) { | if (snapshot.hasData) { | ||||
| return DropdownButtonFormField<Harvest>( | return DropdownButtonFormField<Harvest>( | ||||
| value: harvestValue, | value: harvestValue, | ||||
| hint: Text("Mã thu hoạch"), | |||||
| onChanged: (Harvest newValue) { | |||||
| hint: const Text("Mã thu hoạch"), | |||||
| onChanged: (Harvest? newValue) { | |||||
| setState(() { | setState(() { | ||||
| harvestValue = newValue; | |||||
| _harvestProcess.harvestId = newValue.id; | |||||
| harvestValue = newValue ?? Harvest(); | |||||
| _harvestProcess.harvestId = newValue?.id ?? -1; | |||||
| }); | }); | ||||
| }, | }, | ||||
| isExpanded: true, | isExpanded: true, | ||||
| items: _buildDropMenu(_harvests)); | items: _buildDropMenu(_harvests)); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| return const Center( | |||||
| child: CircularProgressIndicator(), | child: CircularProgressIndicator(), | ||||
| ); | ); | ||||
| } | } | ||||
| Widget _btnExecuteTimePicker() { | Widget _btnExecuteTimePicker() { | ||||
| return FlatButton( | return FlatButton( | ||||
| padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| onPressed: () { | onPressed: () { | ||||
| DatePicker.showDateTimePicker(context, | |||||
| showTitleActions: true, onChanged: (date) {}, onConfirm: (date) { | |||||
| DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {}, onConfirm: (date) { | |||||
| setState(() { | setState(() { | ||||
| executeTime = date; | executeTime = date; | ||||
| _harvestProcess.executeDate = | |||||
| executeTime.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _harvestProcess.executeDate = executeTime.convertLocalDateTimeToStringUtcDateTime(); | |||||
| executeTimeView = executeTime.displayDateTime_DDMMYYYY_HHmm(); | executeTimeView = executeTime.displayDateTime_DDMMYYYY_HHmm(); | ||||
| }); | }); | ||||
| }, currentTime: executeTime, locale: LocaleType.vi); | }, currentTime: executeTime, locale: LocaleType.vi); | ||||
| }, | }, | ||||
| child: Container( | child: Container( | ||||
| padding: | |||||
| EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: BoxDecoration( | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: const BoxDecoration( | |||||
| border: kBorderTextField, | border: kBorderTextField, | ||||
| ), | ), | ||||
| child: Row( | child: Row( | ||||
| child: Text( | child: Text( | ||||
| //TODO: check condition | //TODO: check condition | ||||
| executeTimeView == null ? "$executeTime" : executeTimeView, | executeTimeView == null ? "$executeTime" : executeTimeView, | ||||
| style: TextStyle(fontSize: 14.0, color: Colors.black87), | |||||
| style: const TextStyle(fontSize: 14.0, color: Colors.black87), | |||||
| )), | )), | ||||
| Icon( | |||||
| const Icon( | |||||
| Icons.date_range, | Icons.date_range, | ||||
| color: Colors.grey, | color: Colors.grey, | ||||
| ), | ), | ||||
| hintValue: "Số lượng/khối lượng loại 1", | hintValue: "Số lượng/khối lượng loại 1", | ||||
| textController: _l1Controller, | textController: _l1Controller, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _harvestProcess.quantityLv1 = newValue.parseDoubleThousand(); | |||||
| _harvestProcess.quantityLv1 = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lượng/khối lượng loại 2", | hintValue: "Số lượng/khối lượng loại 2", | ||||
| textController: _l2Controller, | textController: _l2Controller, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _harvestProcess.quantityLv2 = newValue.parseDoubleThousand(); | |||||
| _harvestProcess.quantityLv2 = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lượng/khối lượng loại 3", | hintValue: "Số lượng/khối lượng loại 3", | ||||
| textController: _l3Controller, | textController: _l3Controller, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _harvestProcess.quantityLv3 = newValue.parseDoubleThousand(); | |||||
| _harvestProcess.quantityLv3 = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lượng/khối lượng loại bỏ", | hintValue: "Số lượng/khối lượng loại bỏ", | ||||
| textController: _removedQuantityController, | textController: _removedQuantityController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _harvestProcess.removedQuantity = newValue.parseDoubleThousand(); | |||||
| _harvestProcess.removedQuantity = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Người thực hiện"), | |||||
| decoration: const InputDecoration(labelText: "Người thực hiện"), | |||||
| enabled: false, | enabled: false, | ||||
| controller: _executeByController, | controller: _executeByController, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| appBar: AppBarWidget( | appBar: AppBarWidget( | ||||
| isBack: true, | isBack: true, | ||||
| action: InkWell( | action: InkWell( | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Huỷ', | 'Huỷ', | ||||
| style: TextStyle( | |||||
| color: Colors.red, fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: Colors.red, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| onTap: () { | onTap: () { | ||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| child: MultiBlocProvider( | child: MultiBlocProvider( | ||||
| providers: [ | providers: [ | ||||
| BlocProvider<ActionDetailBloc>( | BlocProvider<ActionDetailBloc>( | ||||
| create: (context) => | |||||
| ActionDetailBloc(repository: Repository()) | |||||
| ..add(FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: | |||||
| ConstCommon.apiDetailHarvestProcess, | |||||
| activityId: widget.activityId))), | |||||
| create: (context) => ActionDetailBloc(repository: Repository()) | |||||
| ..add( | |||||
| FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailHarvestProcess, | |||||
| activityId: widget.activityId ?? -1, | |||||
| ), | |||||
| ), | |||||
| ), | |||||
| BlocProvider<MediaHelperBloc>( | BlocProvider<MediaHelperBloc>( | ||||
| create: (context) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| ) | ) | ||||
| ], | ], | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | |||||
| // autovalidate: _autoValidate, | |||||
| child: SafeArea( | child: SafeArea( | ||||
| child: SingleChildScrollView( | child: SingleChildScrollView( | ||||
| child: | |||||
| BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | listener: (context, state) async { | ||||
| if (state is ActionDetailFailure) { | if (state is ActionDetailFailure) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| } else if (state is ActionDetailSuccess) { | } else if (state is ActionDetailSuccess) { | ||||
| LoadingDialog.hideLoadingDialog(context); | LoadingDialog.hideLoadingDialog(context); | ||||
| print(state.item); | print(state.item); | ||||
| _harvestProcess = | |||||
| HarvestProcess.fromJson(state.item); | |||||
| _harvestProcess.activityId = widget.activityId; | |||||
| _l1Controller.text = _harvestProcess.quantityLv1 | |||||
| .formatNumtoStringDecimal(); | |||||
| _l2Controller.text = _harvestProcess.quantityLv2 | |||||
| .formatNumtoStringDecimal(); | |||||
| _l3Controller.text = _harvestProcess.quantityLv3 | |||||
| .formatNumtoStringDecimal(); | |||||
| _removedQuantityController.text = _harvestProcess | |||||
| .removedQuantity | |||||
| .formatNumtoStringDecimal(); | |||||
| _descriptionController.text = | |||||
| _harvestProcess.description ?? ""; | |||||
| _executeByController.text = | |||||
| _harvestProcess.executeBy; | |||||
| _harvestProcess = HarvestProcess.fromJson(state.item); | |||||
| _harvestProcess.activityId = widget.activityId ?? -1; | |||||
| _l1Controller.text = _harvestProcess.quantityLv1?.formatNumtoStringDecimal() ?? ''; | |||||
| _l2Controller.text = _harvestProcess.quantityLv2?.formatNumtoStringDecimal() ?? ''; | |||||
| _l3Controller.text = _harvestProcess.quantityLv3?.formatNumtoStringDecimal() ?? ''; | |||||
| _removedQuantityController.text = _harvestProcess.removedQuantity?.formatNumtoStringDecimal() ?? ''; | |||||
| _descriptionController.text = _harvestProcess.description ?? ""; | |||||
| _executeByController.text = _harvestProcess.executeBy ?? ''; | |||||
| //select harvest | //select harvest | ||||
| getHarvestBloc.getHarvests((data) { | getHarvestBloc.getHarvests((data) { | ||||
| } | } | ||||
| }, (err) {}); | }, (err) {}); | ||||
| executeTime = _harvestProcess.executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime(); | |||||
| executeTimeView = | |||||
| executeTime.displayDateTime_DDMMYYYY_HHmm(); | |||||
| executeTime = _harvestProcess.executeDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now(); | |||||
| executeTimeView = executeTime.displayDateTime_DDMMYYYY_HHmm(); | |||||
| //Show media | //Show media | ||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _harvestProcess.media)) { | |||||
| BlocProvider.of<MediaHelperBloc>(context).add( | |||||
| ChangeListMedia( | |||||
| items: | |||||
| UtilAction.convertFilePathToMedia( | |||||
| _harvestProcess.media))); | |||||
| if (Validators.stringNotNullOrEmpty(_harvestProcess.media ?? '')) { | |||||
| BlocProvider.of<MediaHelperBloc>(context) | |||||
| .add(ChangeListMedia(items: UtilAction.convertFilePathToMedia(_harvestProcess.media ?? ''))); | |||||
| } | } | ||||
| //list supply | //list supply | ||||
| suppliesUsing = _harvestProcess.suppliesUsing; | |||||
| Get.find<ChangeSupplyUsing>() | |||||
| .changeInitList(suppliesUsing); | |||||
| suppliesUsing = _harvestProcess.suppliesUsing ?? <SuppliesUsing>[]; | |||||
| Get.find<ChangeSupplyUsing>().changeInitList(suppliesUsing); | |||||
| } else if (state is ActionDetailInitial) { | } else if (state is ActionDetailInitial) { | ||||
| } else if (state is ActionDetailLoading) { | } else if (state is ActionDetailLoading) { | ||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| Padding( | Padding( | ||||
| padding: const EdgeInsets.all(8.0), | padding: const EdgeInsets.all(8.0), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: | |||||
| CrossAxisAlignment.start, | |||||
| crossAxisAlignment: CrossAxisAlignment.start, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text( | |||||
| const Text( | |||||
| plot_action_harvest_process, | plot_action_harvest_process, | ||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.w500, | |||||
| fontSize: 22), | |||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | |||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Ngày thực hiện *", | "Ngày thực hiện *", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnExecuteTimePicker(), | _btnExecuteTimePicker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _dropdownHarvest(), | _dropdownHarvest(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _l1Field(), | _l1Field(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _l2Field(), | _l2Field(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _l3Field(), | _l3Field(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _removedQuantityField(), | _removedQuantityField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _descriptionField(), | _descriptionField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _executeByField(), | _executeByField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], | ||||
| onChangeSupplies: (value) { | onChangeSupplies: (value) { | ||||
| suppliesUsing = value; | suppliesUsing = value; | ||||
| }), | }), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| return WidgetMediaPicker( | return WidgetMediaPicker( | ||||
| currentItems: state.items, | currentItems: state.items, | ||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>() | |||||
| .change(newPathFiles, | |||||
| deletePathFiles); | |||||
| onChangeFiles: (newPathFiles, deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change(newPathFiles, deletePathFiles); | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| child: CircularProgressIndicator()); | |||||
| return const Center(child: CircularProgressIndicator()); | |||||
| } | } | ||||
| }), | }), | ||||
| Padding( | Padding( | ||||
| child: ButtonWidget( | child: ButtonWidget( | ||||
| title: 'CẬP NHẬT', | title: 'CẬP NHẬT', | ||||
| onPressed: () { | onPressed: () { | ||||
| FocusScopeNode currentFocus = | |||||
| FocusScope.of(context); | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | if (!currentFocus.hasPrimaryFocus) { | ||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } | ||||
| if (Get.find<ChangeFieldFormSupply>() | |||||
| .isChanged) { | |||||
| Utils.showDialogConfirmSupply( | |||||
| onConfirm: () { | |||||
| if (Get.find<ChangeFieldFormSupply>().isChanged) { | |||||
| Utils.showDialogConfirmSupply(onConfirm: () { | |||||
| Get.back(); | Get.back(); | ||||
| _validateInputs(); | _validateInputs(); | ||||
| }); | }); |
| class WidgetHarvestProcessSupply extends StatefulWidget { | class WidgetHarvestProcessSupply extends StatefulWidget { | ||||
| final List<SuppliesUsing> currentItems; | final List<SuppliesUsing> currentItems; | ||||
| final Function(List<SuppliesUsing> supplyChanges) onChangeSupplies; | final Function(List<SuppliesUsing> supplyChanges) onChangeSupplies; | ||||
| WidgetHarvestProcessSupply( | |||||
| {this.currentItems, @required this.onChangeSupplies}); | |||||
| WidgetHarvestProcessSupply({required this.currentItems, required this.onChangeSupplies}); | |||||
| @override | @override | ||||
| _WidgetHarvestProcessSupplyState createState() => | |||||
| _WidgetHarvestProcessSupplyState(); | |||||
| _WidgetHarvestProcessSupplyState createState() => _WidgetHarvestProcessSupplyState(); | |||||
| } | } | ||||
| class _WidgetHarvestProcessSupplyState | |||||
| extends State<WidgetHarvestProcessSupply> { | |||||
| class _WidgetHarvestProcessSupplyState extends State<WidgetHarvestProcessSupply> { | |||||
| final _dosageController = TextEditingController(); | final _dosageController = TextEditingController(); | ||||
| final _quantityController = TextEditingController(); | final _quantityController = TextEditingController(); | ||||
| final _howToUseController = TextEditingController(); | final _howToUseController = TextEditingController(); | ||||
| return Container( | return Container( | ||||
| height: 120, | height: 120, | ||||
| child: ListView.builder( | child: ListView.builder( | ||||
| physics: ClampingScrollPhysics(), | |||||
| physics: const ClampingScrollPhysics(), | |||||
| scrollDirection: Axis.horizontal, | scrollDirection: Axis.horizontal, | ||||
| shrinkWrap: true, | shrinkWrap: true, | ||||
| itemCount: value.currentItems.length, | itemCount: value.currentItems.length, | ||||
| ..name = editedSupplyUsing.equipmentName; | ..name = editedSupplyUsing.equipmentName; | ||||
| changeSelectedDevice.change(editedDevice); | changeSelectedDevice.change(editedDevice); | ||||
| changeUnit | |||||
| .updateListByUnitName(editedSupplyUsing.supplyUnit); | |||||
| changeUnit.updateSelected(editedSupplyUsing.supplyUnit); | |||||
| _dosageController.text = editedSupplyUsing.dosage; | |||||
| _howToUseController.text = editedSupplyUsing.howToUse; | |||||
| _quantityController.text = editedSupplyUsing.quantity | |||||
| .formatNumtoStringDecimal(); | |||||
| changeUnit.updateListByUnitName(editedSupplyUsing.supplyUnit ?? ''); | |||||
| changeUnit.updateSelected(editedSupplyUsing.supplyUnit ?? ''); | |||||
| _dosageController.text = editedSupplyUsing.dosage ?? ''; | |||||
| _howToUseController.text = editedSupplyUsing.howToUse ?? ''; | |||||
| _quantityController.text = editedSupplyUsing.quantity?.formatNumtoStringDecimal() ?? ''; | |||||
| }, | }, | ||||
| child: Card( | child: Card( | ||||
| child: Stack( | child: Stack( | ||||
| alignment: Alignment.bottomCenter, | alignment: Alignment.bottomCenter, | ||||
| overflow: Overflow.visible, | |||||
| // overflow: Overflow.visible, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Positioned( | Positioned( | ||||
| child: ClipRRect( | child: ClipRRect( | ||||
| borderRadius: BorderRadius.circular(8), | borderRadius: BorderRadius.circular(8), | ||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.all(4), | |||||
| padding: const EdgeInsets.all(4), | |||||
| width: 150, | width: 150, | ||||
| child: Column( | child: Column( | ||||
| mainAxisAlignment: MainAxisAlignment.center, | mainAxisAlignment: MainAxisAlignment.center, | ||||
| children: [ | children: [ | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 12.0, | height: 12.0, | ||||
| ), | ), | ||||
| Flexible( | Flexible( | ||||
| child: Text( | |||||
| value.currentItems[index].supplyName ?? | |||||
| "", | |||||
| overflow: TextOverflow.ellipsis, | |||||
| maxLines: 1), | |||||
| child: Text(value.currentItems[index].supplyName ?? "", overflow: TextOverflow.ellipsis, maxLines: 1), | |||||
| ), | ), | ||||
| Validators.stringNotNullOrEmpty( | |||||
| value.currentItems[index].dosage) | |||||
| Validators.stringNotNullOrEmpty(value.currentItems[index].dosage ?? '') | |||||
| ? Flexible(child: Text("${value.currentItems[index].dosage ?? ""}")) | |||||
| : const SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value.currentItems[index].quantity?.formatNumtoStringDecimal() ?? '') | |||||
| ? Flexible( | ? Flexible( | ||||
| child: Text( | child: Text( | ||||
| "${value.currentItems[index].dosage ?? ""}")) | |||||
| : SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value | |||||
| .currentItems[index].quantity | |||||
| .formatNumtoStringDecimal()) | |||||
| ? Flexible( | |||||
| child: Text( | |||||
| "${value.currentItems[index].quantity.formatNumtoStringDecimal() ?? ""} ${value.currentItems[index].supplyUnit ?? ""}")) | |||||
| : SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value | |||||
| .currentItems[index].equipmentName) | |||||
| ? Flexible( | |||||
| child: Text( | |||||
| "${value.currentItems[index].equipmentName ?? ""}")) | |||||
| : SizedBox(), | |||||
| Validators.stringNotNullOrEmpty( | |||||
| value.currentItems[index].howToUse) | |||||
| ? Flexible( | |||||
| child: Text( | |||||
| "${value.currentItems[index].howToUse ?? ""}")) | |||||
| : SizedBox(), | |||||
| "${value.currentItems[index].quantity?.formatNumtoStringDecimal() ?? ""} ${value.currentItems[index].supplyUnit ?? ""}")) | |||||
| : const SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value.currentItems[index].equipmentName ?? '') | |||||
| ? Flexible(child: Text("${value.currentItems[index].equipmentName ?? ""}")) | |||||
| : const SizedBox(), | |||||
| Validators.stringNotNullOrEmpty(value.currentItems[index].howToUse ?? '') | |||||
| ? Flexible(child: Text("${value.currentItems[index].howToUse ?? ""}")) | |||||
| : const SizedBox(), | |||||
| ], | ], | ||||
| ), | ), | ||||
| ), | ), | ||||
| top: -10, | top: -10, | ||||
| right: -10, | right: -10, | ||||
| child: IconButton( | child: IconButton( | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.cancel, | Icons.cancel, | ||||
| color: Colors.redAccent, | color: Colors.redAccent, | ||||
| ), | ), | ||||
| Widget _btnSelectSubstrates() { | Widget _btnSelectSubstrates() { | ||||
| return GetBuilder<ChangeSupply>(builder: (data) { | return GetBuilder<ChangeSupply>(builder: (data) { | ||||
| return FlatButton( | return FlatButton( | ||||
| padding: | |||||
| EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| onPressed: () { | onPressed: () { | ||||
| var currentIndexEdit = changeSupplyUsing.currentIndex; | var currentIndexEdit = changeSupplyUsing.currentIndex; | ||||
| Navigator.of(context) | Navigator.of(context) | ||||
| type: ConstCommon.supplyTypeAll, | type: ConstCommon.supplyTypeAll, | ||||
| selectedId: changeSelectedSupply.selectedSupplyId, | selectedId: changeSelectedSupply.selectedSupplyId, | ||||
| currentItems: changeSupplyUsing.currentItems, | currentItems: changeSupplyUsing.currentItems, | ||||
| currentEditId: (currentIndexEdit >= 0) | |||||
| ? changeSupplyUsing.currentItems[currentIndexEdit] | |||||
| .tbSuppliesInWarehouseId | |||||
| : -1, | |||||
| currentEditId: | |||||
| (currentIndexEdit >= 0) ? changeSupplyUsing.currentItems[currentIndexEdit].tbSuppliesInWarehouseId ?? -1 : -1, | |||||
| ), | ), | ||||
| fullscreenDialog: false)) | fullscreenDialog: false)) | ||||
| .then((value) { | .then((value) { | ||||
| if (value != null) { | if (value != null) { | ||||
| var result = value as Supply; | var result = value as Supply; | ||||
| changeSelectedSupply.change(result); | changeSelectedSupply.change(result); | ||||
| changeUnit.updateListByUnitName(result.unit); | |||||
| changeUnit.updateListByUnitName(result.unit ?? ''); | |||||
| changeFormField.change(true); | changeFormField.change(true); | ||||
| } | } | ||||
| }); | }); | ||||
| crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, | ||||
| children: [ | children: [ | ||||
| Container( | Container( | ||||
| padding: EdgeInsets.only( | |||||
| top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| border: Border( | border: Border( | ||||
| bottom: BorderSide( | |||||
| width: 1, | |||||
| color: isValid ? Colors.grey : Colors.red[900])), | |||||
| bottom: BorderSide( | |||||
| width: 1, | |||||
| color: isValid ? Colors.grey : Colors.red, | |||||
| ), | |||||
| ), | |||||
| ), | ), | ||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: CrossAxisAlignment.start, | crossAxisAlignment: CrossAxisAlignment.start, | ||||
| children: [ | children: [ | ||||
| Text( | Text( | ||||
| 'Hoá chất xử lý *', | 'Hoá chất xử lý *', | ||||
| style: TextStyle( | |||||
| fontSize: 13, | |||||
| fontWeight: FontWeight.normal, | |||||
| color: | |||||
| isValid ? Colors.black54 : Colors.red[600]), | |||||
| style: TextStyle(fontSize: 13, fontWeight: FontWeight.normal, color: isValid ? Colors.black54 : Colors.red[600]), | |||||
| ), | ), | ||||
| Row( | Row( | ||||
| children: [ | children: [ | ||||
| Expanded( | Expanded( | ||||
| child: Text( | |||||
| changeSelectedSupply.selectedSupplyName ?? | |||||
| "Hoá chất xử lý", | |||||
| style: TextStyle( | |||||
| fontSize: 14.0, | |||||
| color: Colors.black87))), | |||||
| Icon( | |||||
| child: Text(changeSelectedSupply.selectedSupplyName ?? "Hoá chất xử lý", | |||||
| style: const TextStyle(fontSize: 14.0, color: Colors.black87))), | |||||
| const Icon( | |||||
| Icons.arrow_drop_down, | Icons.arrow_drop_down, | ||||
| color: Colors.grey, | color: Colors.grey, | ||||
| ), | ), | ||||
| ), | ), | ||||
| ], | ], | ||||
| )), | )), | ||||
| isValid ? SizedBox() : WidgetErrorTextField() | |||||
| isValid ? const SizedBox() : WidgetErrorTextField() | |||||
| ], | ], | ||||
| ); | ); | ||||
| })); | })); | ||||
| Widget _btnSelectDevice() { | Widget _btnSelectDevice() { | ||||
| return GetBuilder<ChangeDevice>(builder: (data) { | return GetBuilder<ChangeDevice>(builder: (data) { | ||||
| return FlatButton( | return FlatButton( | ||||
| padding: | |||||
| EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| onPressed: () { | onPressed: () { | ||||
| Navigator.of(context) | Navigator.of(context) | ||||
| .push(MaterialPageRoute( | |||||
| builder: (_) => ListDeviceActivity( | |||||
| selectedId: changeSelectedDevice.selectedDeviceId), | |||||
| fullscreenDialog: false)) | |||||
| .push( | |||||
| MaterialPageRoute(builder: (_) => ListDeviceActivity(selectedId: changeSelectedDevice.selectedDeviceId), fullscreenDialog: false)) | |||||
| .then((value) { | .then((value) { | ||||
| if (value != null) { | if (value != null) { | ||||
| var result = value as Device; | var result = value as Device; | ||||
| }); | }); | ||||
| }, | }, | ||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.only( | |||||
| top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: BoxDecoration( | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: const BoxDecoration( | |||||
| border: kBorderTextField, | border: kBorderTextField, | ||||
| ), | ), | ||||
| child: Row( | child: Row( | ||||
| children: [ | children: [ | ||||
| GetBuilder<ChangeSupply>( | GetBuilder<ChangeSupply>( | ||||
| builder: (_) => Expanded( | builder: (_) => Expanded( | ||||
| child: Text( | |||||
| changeSelectedDevice.selectedDeviceName ?? | |||||
| "Thiết bị", | |||||
| style: TextStyle( | |||||
| fontSize: 14.0, color: Colors.black87)))), | |||||
| Icon( | |||||
| child: Text(changeSelectedDevice.selectedDeviceName ?? "Thiết bị", | |||||
| style: const TextStyle(fontSize: 14.0, color: Colors.black87)))), | |||||
| const Icon( | |||||
| Icons.arrow_drop_down, | Icons.arrow_drop_down, | ||||
| color: Colors.grey, | color: Colors.grey, | ||||
| ), | ), | ||||
| var oldSelected = data.selectedUnit; | var oldSelected = data.selectedUnit; | ||||
| if (oldSelected == value) { | if (oldSelected == value) { | ||||
| } else { | } else { | ||||
| assignValue = UtilAction.convertUnit( | |||||
| inputValue: assignValue, | |||||
| oldUnit: oldSelected, | |||||
| newUnit: value); | |||||
| assignValue = UtilAction.convertUnit(inputValue: assignValue, oldUnit: oldSelected, newUnit: value ?? ''); | |||||
| } | } | ||||
| _quantityController.text = assignValue.formatNumtoStringDecimal(); | _quantityController.text = assignValue.formatNumtoStringDecimal(); | ||||
| } | } | ||||
| changeUnit.updateSelected(value); | |||||
| changeUnit.updateSelected(value ?? ''); | |||||
| }, | }, | ||||
| ); | ); | ||||
| }); | }); | ||||
| return WidgetTextFormFieldNumber( | return WidgetTextFormFieldNumber( | ||||
| hintValue: "Tổng lượng sử dụng *", | hintValue: "Tổng lượng sử dụng *", | ||||
| textController: _quantityController, | textController: _quantityController, | ||||
| validator: (String value) { | |||||
| return Validators.validateNotNullOrEmpty( | |||||
| value, label_validate_input_empty); | |||||
| validator: (String? value) { | |||||
| // return Validators.validateNotNullOrEmpty(value, label_validate_input_empty); | |||||
| }, | }, | ||||
| onChanged: (value) { | onChanged: (value) { | ||||
| if (!Validators.stringNotNullOrEmpty(value) && | if (!Validators.stringNotNullOrEmpty(value) && | ||||
| changeFormField.change(true); | changeFormField.change(true); | ||||
| } | } | ||||
| }, | }, | ||||
| onSaved: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||||
| children: [ | children: [ | ||||
| _.isEdit | _.isEdit | ||||
| ? OutlineButton( | |||||
| shape: RoundedRectangleBorder( | |||||
| borderRadius: new BorderRadius.circular(8.0)), | |||||
| child: Text("Huỷ"), | |||||
| onPressed: () { | |||||
| ? InkWell( | |||||
| // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), | |||||
| child: const Text("Huỷ"), | |||||
| onTap: () { | |||||
| changeButton.resetValue(); | changeButton.resetValue(); | ||||
| _resetForm(); | _resetForm(); | ||||
| _hidenKeyboard(context); | _hidenKeyboard(context); | ||||
| }) | }) | ||||
| : SizedBox(), | |||||
| : const SizedBox(), | |||||
| _.isEdit | _.isEdit | ||||
| ? Expanded( | ? Expanded( | ||||
| child: FlatButton( | child: FlatButton( | ||||
| onPressed: () { | onPressed: () { | ||||
| if (_formSupplyKey.currentState.validate()) { | |||||
| _formSupplyKey.currentState.save(); | |||||
| if (_formSupplyKey.currentState!.validate()) { | |||||
| _formSupplyKey.currentState!.save(); | |||||
| if (changeSelectedSupply.selectedSupplyId <= 0) { | if (changeSelectedSupply.selectedSupplyId <= 0) { | ||||
| changeSelectedSupply.changeValid(false); | changeSelectedSupply.changeValid(false); | ||||
| } else { | } else { | ||||
| changeSelectedSupply.changeValid(true); | changeSelectedSupply.changeValid(true); | ||||
| } | } | ||||
| var currentSupply = | |||||
| changeSelectedSupply.currentSupply; | |||||
| var currentDevice = | |||||
| changeSelectedDevice.currentDevice; | |||||
| var currentQuantity = | |||||
| _quantityController.text.parseDoubleThousand(); | |||||
| if (currentSupply.id != null && | |||||
| (currentQuantity ?? 0) > 0) { | |||||
| var quantityWithCurrentSupplyUnit = | |||||
| UtilAction.convertUnit( | |||||
| inputValue: currentQuantity, | |||||
| oldUnit: changeUnit.selectedUnit, | |||||
| newUnit: changeSelectedSupply | |||||
| .currentSupply.unit); | |||||
| SuppliesUsing newSup = SuppliesUsing() | |||||
| var currentSupply = changeSelectedSupply.currentSupply; | |||||
| var currentDevice = changeSelectedDevice.currentDevice; | |||||
| var currentQuantity = _quantityController.text.parseDoubleThousand(); | |||||
| if (currentSupply.id != null && (currentQuantity ?? 0) > 0) { | |||||
| var quantityWithCurrentSupplyUnit = UtilAction.convertUnit( | |||||
| inputValue: currentQuantity, | |||||
| oldUnit: changeUnit.selectedUnit, | |||||
| newUnit: changeSelectedSupply.currentSupply.unit ?? '', | |||||
| ); | |||||
| var newSup = SuppliesUsing() | |||||
| ..dosage = _dosageController.text | ..dosage = _dosageController.text | ||||
| ..howToUse = _howToUseController.text | ..howToUse = _howToUseController.text | ||||
| ..quantity = quantityWithCurrentSupplyUnit | ..quantity = quantityWithCurrentSupplyUnit | ||||
| ..equipmentName = currentDevice.name | ..equipmentName = currentDevice.name | ||||
| ..supplyUnit = currentSupply.unit | ..supplyUnit = currentSupply.unit | ||||
| ..unit = currentSupply.unit; | ..unit = currentSupply.unit; | ||||
| changeSupplyUsing.editSupply( | |||||
| changeSupplyUsing.currentIndex, newSup); | |||||
| changeSupplyUsing.editSupply(changeSupplyUsing.currentIndex, newSup); | |||||
| _resetForm(); | _resetForm(); | ||||
| _hidenKeyboard(context); | _hidenKeyboard(context); | ||||
| } else if (currentSupply.id == null || | |||||
| ((currentQuantity ?? 0) <= 0)) { | |||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập vật tư và số lượng"); | |||||
| } else if (currentSupply.id == null || ((currentQuantity ?? 0) <= 0)) { | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập vật tư và số lượng"); | |||||
| } | } | ||||
| } else { | } else { | ||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập vật tư và số lượng"); | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập vật tư và số lượng"); | |||||
| if (changeSelectedSupply.selectedSupplyId <= 0) { | if (changeSelectedSupply.selectedSupplyId <= 0) { | ||||
| changeSelectedSupply.changeValid(false); | changeSelectedSupply.changeValid(false); | ||||
| } else { | } else { | ||||
| } | } | ||||
| } | } | ||||
| }, | }, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Sửa hoá chất xử lý", | "Sửa hoá chất xử lý", | ||||
| style: TextStyle(color: Colors.blue), | style: TextStyle(color: Colors.blue), | ||||
| )), | )), | ||||
| : Expanded( | : Expanded( | ||||
| child: FlatButton( | child: FlatButton( | ||||
| onPressed: () { | onPressed: () { | ||||
| if (_formSupplyKey.currentState.validate()) { | |||||
| _formSupplyKey.currentState.save(); | |||||
| if (_formSupplyKey.currentState!.validate()) { | |||||
| _formSupplyKey.currentState!.save(); | |||||
| if (changeSelectedSupply.selectedSupplyId <= 0) { | if (changeSelectedSupply.selectedSupplyId <= 0) { | ||||
| changeSelectedSupply.changeValid(false); | changeSelectedSupply.changeValid(false); | ||||
| } else { | } else { | ||||
| changeSelectedSupply.changeValid(true); | changeSelectedSupply.changeValid(true); | ||||
| } | } | ||||
| var currentSupply = | |||||
| changeSelectedSupply.currentSupply; | |||||
| var currentDevice = | |||||
| changeSelectedDevice.currentDevice; | |||||
| var currentQuantity = | |||||
| _quantityController.text.parseDoubleThousand(); | |||||
| if (currentSupply.id != null && | |||||
| (currentQuantity ?? 0) > 0) { | |||||
| var quantityWithCurrentSupplyUnit = | |||||
| UtilAction.convertUnit( | |||||
| inputValue: currentQuantity, | |||||
| oldUnit: changeUnit.selectedUnit, | |||||
| newUnit: changeSelectedSupply | |||||
| .currentSupply.unit); | |||||
| SuppliesUsing newSup = SuppliesUsing() | |||||
| var currentSupply = changeSelectedSupply.currentSupply; | |||||
| var currentDevice = changeSelectedDevice.currentDevice; | |||||
| var currentQuantity = _quantityController.text.parseDoubleThousand(); | |||||
| if (currentSupply.id != null && (currentQuantity ?? 0) > 0) { | |||||
| var quantityWithCurrentSupplyUnit = UtilAction.convertUnit( | |||||
| inputValue: currentQuantity, | |||||
| oldUnit: changeUnit.selectedUnit, | |||||
| newUnit: changeSelectedSupply.currentSupply.unit ?? '', | |||||
| ); | |||||
| var newSup = SuppliesUsing() | |||||
| ..dosage = _dosageController.text | ..dosage = _dosageController.text | ||||
| ..howToUse = _howToUseController.text | ..howToUse = _howToUseController.text | ||||
| ..quantity = quantityWithCurrentSupplyUnit | ..quantity = quantityWithCurrentSupplyUnit | ||||
| changeSupplyUsing.addSupply(newSup); | changeSupplyUsing.addSupply(newSup); | ||||
| _resetForm(); | _resetForm(); | ||||
| _hidenKeyboard(context); | _hidenKeyboard(context); | ||||
| } else if (currentSupply.id == null || | |||||
| ((currentQuantity ?? 0) <= 0)) { | |||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập vật tư và số lượng"); | |||||
| } else if (currentSupply.id == null || ((currentQuantity ?? 0) <= 0)) { | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập vật tư và số lượng"); | |||||
| } | } | ||||
| } else { | } else { | ||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập vật tư và số lượng"); | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập vật tư và số lượng"); | |||||
| if (changeSelectedSupply.selectedSupplyId <= 0) { | if (changeSelectedSupply.selectedSupplyId <= 0) { | ||||
| changeSelectedSupply.changeValid(false); | changeSelectedSupply.changeValid(false); | ||||
| } else { | } else { | ||||
| } | } | ||||
| } | } | ||||
| }, | }, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "+ Thêm hoá chất xử lý", | "+ Thêm hoá chất xử lý", | ||||
| style: TextStyle(color: Colors.blue), | style: TextStyle(color: Colors.blue), | ||||
| )), | )), | ||||
| child: Column( | child: Column( | ||||
| children: [ | children: [ | ||||
| Container( | Container( | ||||
| padding: EdgeInsets.all(8.0), | |||||
| margin: EdgeInsets.all(8.0), | |||||
| padding: const EdgeInsets.all(8.0), | |||||
| margin: const EdgeInsets.all(8.0), | |||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| shape: BoxShape.rectangle, | |||||
| borderRadius: BorderRadius.circular(10), | |||||
| color: Colors.white, | |||||
| border: Border.all(color: Colors.grey[300])), | |||||
| shape: BoxShape.rectangle, | |||||
| borderRadius: BorderRadius.circular(10), | |||||
| color: Colors.white, | |||||
| border: Border.all( | |||||
| color: Colors.grey, | |||||
| ), | |||||
| ), | |||||
| child: Column( | child: Column( | ||||
| children: [ | children: [ | ||||
| _btnSelectSubstrates(), | _btnSelectSubstrates(), | ||||
| TextFormField( | TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| controller: _dosageController, | controller: _dosageController, | ||||
| decoration: InputDecoration(labelText: "Liều lượng sử dụng"), | |||||
| decoration: const InputDecoration(labelText: "Liều lượng sử dụng"), | |||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| onChanged: (value) { | onChanged: (value) { | ||||
| if (!Validators.stringNotNullOrEmpty( | |||||
| _quantityController.text) && | |||||
| !Validators.stringNotNullOrEmpty( | |||||
| _howToUseController.text) && | |||||
| if (!Validators.stringNotNullOrEmpty(_quantityController.text) && | |||||
| !Validators.stringNotNullOrEmpty(_howToUseController.text) && | |||||
| !Validators.stringNotNullOrEmpty(value) && | !Validators.stringNotNullOrEmpty(value) && | ||||
| Get.find<ChangeSupply>().selectedSupplyId <= 0 && | Get.find<ChangeSupply>().selectedSupplyId <= 0 && | ||||
| changeSelectedDevice.selectedDeviceId <= 0) { | changeSelectedDevice.selectedDeviceId <= 0) { | ||||
| child: _quantityField(), | child: _quantityField(), | ||||
| ), | ), | ||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| width: 16.0, | width: 16.0, | ||||
| ), | ), | ||||
| Expanded( | Expanded( | ||||
| ]), | ]), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Thiết bị", | "Thiết bị", | ||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | style: TextStyle(color: Colors.black54, fontSize: 13.0), | ||||
| ), | ), | ||||
| TextFormField( | TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| controller: _howToUseController, | controller: _howToUseController, | ||||
| decoration: InputDecoration(labelText: "Phương pháp sử dụng"), | |||||
| decoration: const InputDecoration(labelText: "Phương pháp sử dụng"), | |||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| onChanged: (value) { | onChanged: (value) { | ||||
| if (!Validators.stringNotNullOrEmpty( | |||||
| _quantityController.text) && | |||||
| if (!Validators.stringNotNullOrEmpty(_quantityController.text) && | |||||
| !Validators.stringNotNullOrEmpty(value) && | !Validators.stringNotNullOrEmpty(value) && | ||||
| !Validators.stringNotNullOrEmpty( | |||||
| _dosageController.text) && | |||||
| !Validators.stringNotNullOrEmpty(_dosageController.text) && | |||||
| Get.find<ChangeSupply>().selectedSupplyId <= 0 && | Get.find<ChangeSupply>().selectedSupplyId <= 0 && | ||||
| changeSelectedDevice.selectedDeviceId <= 0) { | changeSelectedDevice.selectedDeviceId <= 0) { | ||||
| changeFormField.change(false); | changeFormField.change(false); | ||||
| } | } | ||||
| _hidenKeyboard(BuildContext context) { | _hidenKeyboard(BuildContext context) { | ||||
| FocusScopeNode currentFocus = FocusScope.of(context); | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | if (!currentFocus.hasPrimaryFocus) { | ||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } | ||||
| Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
| return Column( | return Column( | ||||
| children: [ | children: [ | ||||
| Padding( | |||||
| padding: const EdgeInsets.all(8.0), | |||||
| const Padding( | |||||
| padding: EdgeInsets.all(8.0), | |||||
| child: Align( | child: Align( | ||||
| alignment: Alignment.centerLeft, | alignment: Alignment.centerLeft, | ||||
| child: Text( | child: Text( | ||||
| ), | ), | ||||
| ), | ), | ||||
| _buildListSupply(), | _buildListSupply(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _formEdit() | _formEdit() |
| ExpansionListEvent event, | ExpansionListEvent event, | ||||
| ) async* { | ) async* { | ||||
| if (event is AddNew) { | if (event is AddNew) { | ||||
| List<NurseryDetail> items = new List<NurseryDetail>(); | |||||
| for (int i = 0; i < event.items.length; i++) { | |||||
| var items = <NurseryDetail>[]; | |||||
| for (var i = 0; i < event.items.length; i++) { | |||||
| var current = event.items[i]; | var current = event.items[i]; | ||||
| items.add(NurseryDetail.clone(current)); | items.add(NurseryDetail.clone(current)); | ||||
| } | } | ||||
| yield ExpansionListSuccess(items: items); | yield ExpansionListSuccess(items: items); | ||||
| } else if (event is DeleteItem) { | } else if (event is DeleteItem) { | ||||
| List<NurseryDetail> items = new List<NurseryDetail>(); | |||||
| for (int i = 0; i < event.items.length; i++) { | |||||
| var items = <NurseryDetail>[]; | |||||
| for (var i = 0; i < event.items.length; i++) { | |||||
| var current = event.items[i]; | var current = event.items[i]; | ||||
| if (i == event.index) { | if (i == event.index) { | ||||
| //ignore | //ignore | ||||
| yield ExpansionListSuccess(items: items); | yield ExpansionListSuccess(items: items); | ||||
| } else if (event is Update) { | } else if (event is Update) { | ||||
| List<NurseryDetail> items = new List<NurseryDetail>(); | |||||
| for (int i = 0; i < event.items.length; i++) { | |||||
| var items = <NurseryDetail>[]; | |||||
| for (var i = 0; i < event.items.length; i++) { | |||||
| var current = event.items[i]; | var current = event.items[i]; | ||||
| if (i == event.index) { | if (i == event.index) { | ||||
| items.add(NurseryDetail.clone(event.item)); | items.add(NurseryDetail.clone(event.item)); |
| final int index; | final int index; | ||||
| final NurseryDetail item; | final NurseryDetail item; | ||||
| final List<NurseryDetail> items; | final List<NurseryDetail> items; | ||||
| Update({@required this.index, @required this.item, @required this.items}); | |||||
| Update({required this.index, required this.item, required this.items}); | |||||
| } | } | ||||
| class AddNew extends ExpansionListEvent { | class AddNew extends ExpansionListEvent { | ||||
| final List<NurseryDetail> items; | final List<NurseryDetail> items; | ||||
| AddNew({@required this.items}); | |||||
| AddNew({required this.items}); | |||||
| } | } | ||||
| class DeleteItem extends ExpansionListEvent { | class DeleteItem extends ExpansionListEvent { | ||||
| final int index; | final int index; | ||||
| final List<NurseryDetail> items; | final List<NurseryDetail> items; | ||||
| DeleteItem({@required this.index, @required this.items}); | |||||
| DeleteItem({required this.index, required this.items}); | |||||
| } | } |
| class ExpansionListFailure extends ExpansionListState { | class ExpansionListFailure extends ExpansionListState { | ||||
| final String errorString; | final String errorString; | ||||
| ExpansionListFailure({@required this.errorString}); | |||||
| ExpansionListFailure({required this.errorString}); | |||||
| } | } | ||||
| class ExpansionListSuccess extends ExpansionListState { | class ExpansionListSuccess extends ExpansionListState { | ||||
| final List<NurseryDetail> items; | final List<NurseryDetail> items; | ||||
| const ExpansionListSuccess({this.items}); | |||||
| const ExpansionListSuccess({required this.items}); | |||||
| ExpansionListSuccess copyWith({List<NurseryDetail> items}) { | |||||
| ExpansionListSuccess copyWith({List<NurseryDetail>? items}) { | |||||
| return ExpansionListSuccess(items: items ?? this.items); | return ExpansionListSuccess(items: items ?? this.items); | ||||
| } | } | ||||
| class EditActionNurseryScreen extends StatefulWidget { | class EditActionNurseryScreen extends StatefulWidget { | ||||
| final int cropId; | final int cropId; | ||||
| final bool isEdit; | final bool isEdit; | ||||
| final int activityId; | |||||
| EditActionNurseryScreen( | |||||
| {@required this.cropId, this.isEdit = false, this.activityId}); | |||||
| final int? activityId; | |||||
| EditActionNurseryScreen({required this.cropId, this.isEdit = false, this.activityId}); | |||||
| @override | @override | ||||
| _EditActionNurseryState createState() => _EditActionNurseryState(); | _EditActionNurseryState createState() => _EditActionNurseryState(); | ||||
| } | } | ||||
| class _EditActionNurseryState extends State<EditActionNurseryScreen> { | class _EditActionNurseryState extends State<EditActionNurseryScreen> { | ||||
| final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | |||||
| final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); | |||||
| final _repository = Repository(); | final _repository = Repository(); | ||||
| GlobalKey<FormState> _formKey = GlobalKey(); | GlobalKey<FormState> _formKey = GlobalKey(); | ||||
| GlobalKey<FormState> _formWorkerKey = GlobalKey(); | GlobalKey<FormState> _formWorkerKey = GlobalKey(); | ||||
| TextEditingController _trayNumberController = TextEditingController(); | TextEditingController _trayNumberController = TextEditingController(); | ||||
| final _executeByController = TextEditingController(); | final _executeByController = TextEditingController(); | ||||
| DateTime executeTime = DateTime.now(); | DateTime executeTime = DateTime.now(); | ||||
| List<NurseryDetail> currentNurseryDetail = List<NurseryDetail>(); | |||||
| List<NurseryDetail> currentNurseryDetail = <NurseryDetail>[]; | |||||
| int currentIndexUpdate = -1; | int currentIndexUpdate = -1; | ||||
| bool isResetForm = true; | bool isResetForm = true; | ||||
| final changeSupply = Get.put(ChangeSupply()); | final changeSupply = Get.put(ChangeSupply()); | ||||
| int selectedSupplyId = -1; | int selectedSupplyId = -1; | ||||
| List<String> filePaths = List<String>(); | |||||
| List<String> filePaths = <String>[]; | |||||
| var changeFileController = Get.put(ChangeFileController()); | var changeFileController = Get.put(ChangeFileController()); | ||||
| Future<Null> getSharedPrefs() async { | Future<Null> getSharedPrefs() async { | ||||
| getSharedPrefs(); | getSharedPrefs(); | ||||
| changeSupply.initValue(); | changeSupply.initValue(); | ||||
| changeFileController.initValue(); | changeFileController.initValue(); | ||||
| _nursery.nurseryDetail = new List<NurseryDetail>(); | |||||
| _nursery.nurseryDetail = <NurseryDetail>[]; | |||||
| _nursery.cropId = widget.cropId; | _nursery.cropId = widget.cropId; | ||||
| } | } | ||||
| _validateInputs() async { | _validateInputs() async { | ||||
| if (_formKey.currentState.validate()) { | |||||
| _formKey.currentState.save(); | |||||
| if (_formKey.currentState!.validate()) { | |||||
| _formKey.currentState!.save(); | |||||
| LoadingDialog.showLoadingDialog(context); | LoadingDialog.showLoadingDialog(context); | ||||
| _nursery.nurseryDetail = currentNurseryDetail; | _nursery.nurseryDetail = currentNurseryDetail; | ||||
| filePaths = Get.find<ChangeFileController>().newFiles; | filePaths = Get.find<ChangeFileController>().newFiles; | ||||
| return WidgetFieldDateTimePicker( | return WidgetFieldDateTimePicker( | ||||
| initDateTime: executeTime, | initDateTime: executeTime, | ||||
| onUpdateDateTime: (selectedDate) { | onUpdateDateTime: (selectedDate) { | ||||
| _nursery.executeDate = | |||||
| selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| _nursery.executeDate = selectedDate.convertLocalDateTimeToStringUtcDateTime(); | |||||
| }); | }); | ||||
| } | } | ||||
| Widget _btnSelectSubstrates() { | Widget _btnSelectSubstrates() { | ||||
| return FlatButton( | return FlatButton( | ||||
| padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), | |||||
| onPressed: () { | onPressed: () { | ||||
| Navigator.of(context) | Navigator.of(context) | ||||
| .push(MaterialPageRoute( | .push(MaterialPageRoute( | ||||
| }); | }); | ||||
| }, | }, | ||||
| child: Container( | child: Container( | ||||
| padding: | |||||
| EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: BoxDecoration( | |||||
| padding: const EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0), | |||||
| decoration: const BoxDecoration( | |||||
| border: kBorderTextField, | border: kBorderTextField, | ||||
| ), | ), | ||||
| child: Row( | child: Row( | ||||
| children: [ | children: [ | ||||
| GetBuilder<ChangeSupply>( | GetBuilder<ChangeSupply>( | ||||
| builder: (_) => Expanded( | builder: (_) => Expanded( | ||||
| child: Text( | |||||
| changeSupply.selectedSupplyName == null | |||||
| ? "Loại giá thể" | |||||
| : changeSupply.selectedSupplyName.toString(), | |||||
| style: TextStyle( | |||||
| fontSize: 14.0, color: Colors.black87)))), | |||||
| Icon( | |||||
| child: Text(changeSupply.selectedSupplyName == null ? "Loại giá thể" : changeSupply.selectedSupplyName.toString(), | |||||
| style: const TextStyle(fontSize: 14.0, color: Colors.black87)))), | |||||
| const Icon( | |||||
| Icons.arrow_drop_down, | Icons.arrow_drop_down, | ||||
| color: Colors.grey, | color: Colors.grey, | ||||
| ), | ), | ||||
| hintValue: "Chiều dài mầm", | hintValue: "Chiều dài mầm", | ||||
| textController: _seedLengthController, | textController: _seedLengthController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _nursery.seedLength = newValue.parseDoubleThousand(); | |||||
| _nursery.seedLength = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Số lượng hạt gieo", | hintValue: "Số lượng hạt gieo", | ||||
| textController: _quantityController, | textController: _quantityController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _nursery.quantity = newValue.parseDoubleThousand(); | |||||
| _nursery.quantity = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| hintValue: "Thời gian ngâm hạt", | hintValue: "Thời gian ngâm hạt", | ||||
| textController: _seedIncubationTimeController, | textController: _seedIncubationTimeController, | ||||
| onSaved: (newValue) { | onSaved: (newValue) { | ||||
| _nursery.seedIncubationTime = newValue.parseDoubleThousand(); | |||||
| _nursery.seedIncubationTime = (newValue ?? '0').parseDoubleThousand(); | |||||
| }, | }, | ||||
| onChanged: (_) {}, | |||||
| validator: (_) {}, | |||||
| ); | ); | ||||
| } | } | ||||
| Widget _executeByField() { | Widget _executeByField() { | ||||
| return TextFormField( | return TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| decoration: InputDecoration(labelText: "Người thực hiện"), | |||||
| decoration: const InputDecoration(labelText: "Người thực hiện"), | |||||
| enabled: false, | enabled: false, | ||||
| controller: _executeByController, | controller: _executeByController, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| Widget _btnAddWorker() { | Widget _btnAddWorker() { | ||||
| //TODO :check flow error sua item -> xoa list -> bam nut them | //TODO :check flow error sua item -> xoa list -> bam nut them | ||||
| return Builder(builder: (context) { | return Builder(builder: (context) { | ||||
| return BlocConsumer<StatusAddFormBloc, StatusAddFormState>( | |||||
| listener: (context, state) { | |||||
| return BlocConsumer<StatusAddFormBloc, StatusAddFormState>(listener: (context, state) { | |||||
| if (state is Edit) { | if (state is Edit) { | ||||
| isResetForm = false; | isResetForm = false; | ||||
| _workerNameController.text = state.nurseryDetail.workerName; | |||||
| _trayNumberController.text = state.nurseryDetail.trayNumber; | |||||
| _workerNameController.text = state.nurseryDetail.workerName ?? ''; | |||||
| _trayNumberController.text = state.nurseryDetail.trayNumber ?? ''; | |||||
| } else if (state is Delete) { | } else if (state is Delete) { | ||||
| if (currentIndexUpdate == state.index) { | if (currentIndexUpdate == state.index) { | ||||
| isResetForm = true; | isResetForm = true; | ||||
| child: Column( | child: Column( | ||||
| children: [ | children: [ | ||||
| Container( | Container( | ||||
| padding: EdgeInsets.all(8.0), | |||||
| margin: EdgeInsets.all(8), | |||||
| padding: const EdgeInsets.all(8.0), | |||||
| margin: const EdgeInsets.all(8), | |||||
| decoration: BoxDecoration( | decoration: BoxDecoration( | ||||
| shape: BoxShape.rectangle, | |||||
| borderRadius: BorderRadius.circular(10), | |||||
| color: Colors.white, | |||||
| border: Border.all(color: Colors.grey[300])), | |||||
| shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(10), color: Colors.white, border: Border.all(color: Colors.grey)), | |||||
| child: Column( | child: Column( | ||||
| children: [ | children: [ | ||||
| TextFormField( | TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| controller: _workerNameController, | controller: _workerNameController, | ||||
| decoration: InputDecoration(labelText: "Tên công nhân *"), | |||||
| decoration: const InputDecoration(labelText: "Tên công nhân *"), | |||||
| validator: (value) { | validator: (value) { | ||||
| return Validators.validateNotNullOrEmpty( | |||||
| value, label_validate_input_empty); | |||||
| return Validators.validateNotNullOrEmpty(value ?? '', label_validate_input_empty); | |||||
| }, | }, | ||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| ), | ), | ||||
| TextFormField( | TextFormField( | ||||
| keyboardType: TextInputType.text, | keyboardType: TextInputType.text, | ||||
| controller: _trayNumberController, | controller: _trayNumberController, | ||||
| decoration: InputDecoration(labelText: "Ươm khây số"), | |||||
| decoration: const InputDecoration(labelText: "Ươm khây số"), | |||||
| onSaved: (newValue) {}, | onSaved: (newValue) {}, | ||||
| ), | ), | ||||
| ], | ], | ||||
| ), | ), | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| margin: EdgeInsets.all(8), | |||||
| margin: const EdgeInsets.all(8), | |||||
| child: Row( | child: Row( | ||||
| mainAxisAlignment: MainAxisAlignment.spaceBetween, | mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||||
| mainAxisSize: MainAxisSize.max, | mainAxisSize: MainAxisSize.max, | ||||
| children: [ | children: [ | ||||
| isResetForm | isResetForm | ||||
| ? Container() | ? Container() | ||||
| : OutlineButton( | |||||
| shape: RoundedRectangleBorder( | |||||
| borderRadius: new BorderRadius.circular(8.0)), | |||||
| child: Text("Huỷ"), | |||||
| onPressed: () { | |||||
| : InkWell( | |||||
| // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), | |||||
| child: const Text("Huỷ"), | |||||
| onTap: () { | |||||
| context.bloc<StatusAddFormBloc>().add(Reset()); | context.bloc<StatusAddFormBloc>().add(Reset()); | ||||
| }), | }), | ||||
| Expanded( | Expanded( | ||||
| child: FlatButton( | child: FlatButton( | ||||
| onPressed: () { | onPressed: () { | ||||
| if (_formWorkerKey.currentState.validate()) { | |||||
| _formWorkerKey.currentState.save(); | |||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _workerNameController.text)) { | |||||
| NurseryDetail _nurseryDetail = NurseryDetail() | |||||
| if (_formWorkerKey.currentState!.validate()) { | |||||
| _formWorkerKey.currentState!.save(); | |||||
| if (Validators.stringNotNullOrEmpty(_workerNameController.text)) { | |||||
| var _nurseryDetail = NurseryDetail() | |||||
| ..workerName = _workerNameController.text | ..workerName = _workerNameController.text | ||||
| ..trayNumber = _trayNumberController.text; | ..trayNumber = _trayNumberController.text; | ||||
| if (state is Edit) { | if (state is Edit) { | ||||
| context.bloc<ExpansionListBloc>().add(Update( | |||||
| index: state.index, | |||||
| item: _nurseryDetail, | |||||
| items: state.items)); | |||||
| context.bloc<ExpansionListBloc>().add( | |||||
| Update( | |||||
| index: state.index, | |||||
| item: _nurseryDetail, | |||||
| items: state.items ?? <NurseryDetail>[], | |||||
| ), | |||||
| ); | |||||
| } else { | } else { | ||||
| currentNurseryDetail.insert( | |||||
| 0, _nurseryDetail); | |||||
| BlocProvider.of<ExpansionListBloc>(context) | |||||
| .add(AddNew(items: currentNurseryDetail)); | |||||
| currentNurseryDetail.insert(0, _nurseryDetail); | |||||
| BlocProvider.of<ExpansionListBloc>(context).add(AddNew(items: currentNurseryDetail)); | |||||
| } | } | ||||
| context.bloc<StatusAddFormBloc>().add(Reset()); | context.bloc<StatusAddFormBloc>().add(Reset()); | ||||
| } else { | } else { | ||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập tên công nhân"); | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập tên công nhân"); | |||||
| } | } | ||||
| } else { | } else { | ||||
| // | // | ||||
| if (!Validators.stringNotNullOrEmpty( | |||||
| _workerNameController.text)) { | |||||
| Utils.showSnackBarWarning( | |||||
| message: "Vui lòng nhập tên công nhân"); | |||||
| if (!Validators.stringNotNullOrEmpty(_workerNameController.text)) { | |||||
| Utils.showSnackBarWarning(message: "Vui lòng nhập tên công nhân"); | |||||
| } | } | ||||
| } | } | ||||
| }, | }, | ||||
| child: Text( | child: Text( | ||||
| (state is Edit) | |||||
| ? "Sửa người thực hiện" | |||||
| : "+ Thêm người thực hiện", | |||||
| style: TextStyle(color: Colors.blue), | |||||
| (state is Edit) ? "Sửa người thực hiện" : "+ Thêm người thực hiện", | |||||
| style: const TextStyle(color: Colors.blue), | |||||
| )), | )), | ||||
| ) | ) | ||||
| ], | ], | ||||
| Widget _buildListAddWorker() { | Widget _buildListAddWorker() { | ||||
| return Builder(builder: (context) { | return Builder(builder: (context) { | ||||
| return BlocBuilder<ExpansionListBloc, ExpansionListState>( | |||||
| builder: (context, state) { | |||||
| return BlocBuilder<ExpansionListBloc, ExpansionListState>(builder: (context, state) { | |||||
| if (state is ExpansionListSuccess) { | if (state is ExpansionListSuccess) { | ||||
| currentNurseryDetail = state.items; | currentNurseryDetail = state.items; | ||||
| if (currentNurseryDetail.isEmpty) { | if (currentNurseryDetail.isEmpty) { | ||||
| return Container( | return Container( | ||||
| height: 70, | height: 70, | ||||
| child: ListView.builder( | child: ListView.builder( | ||||
| physics: ClampingScrollPhysics(), | |||||
| physics: const ClampingScrollPhysics(), | |||||
| scrollDirection: Axis.horizontal, | scrollDirection: Axis.horizontal, | ||||
| shrinkWrap: true, | shrinkWrap: true, | ||||
| itemCount: currentNurseryDetail.length, | itemCount: currentNurseryDetail.length, | ||||
| print("edit worker"); | print("edit worker"); | ||||
| currentIndexUpdate = index; | currentIndexUpdate = index; | ||||
| context.bloc<StatusAddFormBloc>().add(Changed( | context.bloc<StatusAddFormBloc>().add(Changed( | ||||
| status: CRUDStatus.edit, | |||||
| index: index, | |||||
| nurseryDetail: currentNurseryDetail[index], | |||||
| items: currentNurseryDetail)); | |||||
| status: CRUDStatus.edit, index: index, nurseryDetail: currentNurseryDetail[index], items: currentNurseryDetail)); | |||||
| }, | }, | ||||
| child: Card( | child: Card( | ||||
| child: Stack( | child: Stack( | ||||
| alignment: Alignment.bottomCenter, | alignment: Alignment.bottomCenter, | ||||
| overflow: Overflow.visible, | |||||
| // overflow: Overflow.visible, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Positioned( | Positioned( | ||||
| child: ClipRRect( | child: ClipRRect( | ||||
| borderRadius: BorderRadius.circular(8), | borderRadius: BorderRadius.circular(8), | ||||
| child: Container( | child: Container( | ||||
| padding: EdgeInsets.all(4), | |||||
| padding: const EdgeInsets.all(4), | |||||
| width: 120, | width: 120, | ||||
| child: Column( | child: Column( | ||||
| mainAxisAlignment: MainAxisAlignment.center, | mainAxisAlignment: MainAxisAlignment.center, | ||||
| children: [ | children: [ | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 12.0, | height: 12.0, | ||||
| ), | ), | ||||
| Flexible( | Flexible( | ||||
| child: Text( | |||||
| currentNurseryDetail[index] | |||||
| .workerName ?? | |||||
| "", | |||||
| overflow: TextOverflow.ellipsis, | |||||
| maxLines: 1), | |||||
| child: Text(currentNurseryDetail[index].workerName ?? "", overflow: TextOverflow.ellipsis, maxLines: 1), | |||||
| ), | ), | ||||
| Validators.stringNotNullOrEmpty( | |||||
| currentNurseryDetail[index] | |||||
| .trayNumber) | |||||
| ? Flexible( | |||||
| child: Text( | |||||
| currentNurseryDetail[index] | |||||
| .trayNumber ?? | |||||
| "")) | |||||
| : SizedBox() | |||||
| Validators.stringNotNullOrEmpty(currentNurseryDetail[index].trayNumber ?? '') | |||||
| ? Flexible(child: Text(currentNurseryDetail[index].trayNumber ?? "")) | |||||
| : const SizedBox() | |||||
| ], | ], | ||||
| ), | ), | ||||
| ), | ), | ||||
| top: -10, | top: -10, | ||||
| right: -10, | right: -10, | ||||
| child: IconButton( | child: IconButton( | ||||
| icon: Icon( | |||||
| icon: const Icon( | |||||
| Icons.cancel, | Icons.cancel, | ||||
| color: Colors.redAccent, | color: Colors.redAccent, | ||||
| ), | ), | ||||
| onPressed: () { | onPressed: () { | ||||
| print("Delete worker"); | print("Delete worker"); | ||||
| context.bloc<ExpansionListBloc>().add( | |||||
| DeleteItem( | |||||
| index: index, | |||||
| items: currentNurseryDetail)); | |||||
| context.bloc<StatusAddFormBloc>().add( | |||||
| Changed( | |||||
| status: CRUDStatus.delete, | |||||
| index: index, | |||||
| nurseryDetail: | |||||
| currentNurseryDetail[index], | |||||
| items: currentNurseryDetail)); | |||||
| context.bloc<ExpansionListBloc>().add(DeleteItem(index: index, items: currentNurseryDetail)); | |||||
| context.bloc<StatusAddFormBloc>().add(Changed( | |||||
| status: CRUDStatus.delete, | |||||
| index: index, | |||||
| nurseryDetail: currentNurseryDetail[index], | |||||
| items: currentNurseryDetail)); | |||||
| }), | }), | ||||
| ) | ) | ||||
| ], | ], | ||||
| appBar: AppBarWidget( | appBar: AppBarWidget( | ||||
| isBack: true, | isBack: true, | ||||
| action: InkWell( | action: InkWell( | ||||
| child: Text( | |||||
| child: const Text( | |||||
| 'Huỷ', | 'Huỷ', | ||||
| style: TextStyle( | |||||
| color: Colors.red, fontWeight: FontWeight.normal), | |||||
| style: TextStyle(color: Colors.red, fontWeight: FontWeight.normal), | |||||
| ), | ), | ||||
| onTap: () { | onTap: () { | ||||
| if (Get.isSnackbarOpen) Get.back(); | if (Get.isSnackbarOpen) Get.back(); | ||||
| create: (context) => StatusAddFormBloc(), | create: (context) => StatusAddFormBloc(), | ||||
| ), | ), | ||||
| BlocProvider<ActionDetailBloc>( | BlocProvider<ActionDetailBloc>( | ||||
| create: (context) => | |||||
| ActionDetailBloc(repository: Repository()) | |||||
| ..add(FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailNursery, | |||||
| activityId: widget.activityId))), | |||||
| create: (context) => ActionDetailBloc(repository: Repository()) | |||||
| ..add( | |||||
| FetchData( | |||||
| isNeedFetchData: widget.isEdit, | |||||
| apiActivity: ConstCommon.apiDetailNursery, | |||||
| activityId: widget.activityId ?? -1, | |||||
| ), | |||||
| ), | |||||
| ), | |||||
| BlocProvider<MediaHelperBloc>( | BlocProvider<MediaHelperBloc>( | ||||
| create: (context) => | |||||
| MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), | |||||
| ) | ) | ||||
| ], | ], | ||||
| child: Form( | child: Form( | ||||
| key: _formKey, | key: _formKey, | ||||
| autovalidate: _autoValidate, | |||||
| // autovalidate: _autoValidate, | |||||
| child: SafeArea( | child: SafeArea( | ||||
| child: SingleChildScrollView( | child: SingleChildScrollView( | ||||
| child: BlocConsumer<ActionDetailBloc, | |||||
| ActionDetailState>( | |||||
| child: BlocConsumer<ActionDetailBloc, ActionDetailState>( | |||||
| listener: (context, state) async { | listener: (context, state) async { | ||||
| if (state is ActionDetailFailure) { | if (state is ActionDetailFailure) { | ||||
| print("fail"); | print("fail"); | ||||
| print("success"); | print("success"); | ||||
| print(state.item); | print(state.item); | ||||
| _nursery = Nursery.fromJson(state.item); | _nursery = Nursery.fromJson(state.item); | ||||
| _seedLengthController.text = _nursery | |||||
| .seedLength | |||||
| .formatNumtoStringDecimal(); | |||||
| _quantityController.text = _nursery.quantity | |||||
| .formatNumtoStringDecimal(); | |||||
| _seedIncubationTimeController.text = | |||||
| _nursery.seedIncubationTime | |||||
| .formatNumtoStringDecimal(); | |||||
| _descriptionController.text = | |||||
| _nursery.description; | |||||
| _executeByController.text = | |||||
| _nursery.executeBy; | |||||
| Get.find<ChangeDateTimePicker>().change(_nursery | |||||
| .executeDate | |||||
| .convertStringServerDateTimeToLocalDateTime()); | |||||
| _seedLengthController.text = _nursery.seedLength?.formatNumtoStringDecimal() ?? ''; | |||||
| _quantityController.text = _nursery.quantity?.formatNumtoStringDecimal() ?? ''; | |||||
| _seedIncubationTimeController.text = _nursery.seedIncubationTime?.formatNumtoStringDecimal() ?? ''; | |||||
| _descriptionController.text = _nursery.description ?? ''; | |||||
| _executeByController.text = _nursery.executeBy ?? ''; | |||||
| Get.find<ChangeDateTimePicker>().change( | |||||
| _nursery.executeDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now(), | |||||
| ); | |||||
| //Show media | //Show media | ||||
| if (Validators.stringNotNullOrEmpty( | |||||
| _nursery.media)) { | |||||
| if (Validators.stringNotNullOrEmpty(_nursery.media ?? '')) { | |||||
| BlocProvider.of<MediaHelperBloc>(context) | BlocProvider.of<MediaHelperBloc>(context) | ||||
| .add(ChangeListMedia( | |||||
| items: UtilAction | |||||
| .convertFilePathToMedia( | |||||
| _nursery.media))); | |||||
| .add(ChangeListMedia(items: UtilAction.convertFilePathToMedia(_nursery.media ?? ''))); | |||||
| } | } | ||||
| //Show worker | //Show worker | ||||
| if (_nursery.nurseryDetail.length > 0) { | |||||
| BlocProvider.of<ExpansionListBloc>( | |||||
| context) | |||||
| .add(AddNew( | |||||
| items: _nursery.nurseryDetail)); | |||||
| if (_nursery.nurseryDetail != null) { | |||||
| if (_nursery.nurseryDetail!.length > 0) { | |||||
| BlocProvider.of<ExpansionListBloc>(context).add(AddNew(items: _nursery.nurseryDetail!)); | |||||
| } | |||||
| } | } | ||||
| //change subStrates | //change subStrates | ||||
| if (_nursery.substratesId != null) { | if (_nursery.substratesId != null) { | ||||
| Get.find<ChangeSupply>() | |||||
| .changeByIdAndName( | |||||
| _nursery.substratesId, | |||||
| _nursery.substrateName); | |||||
| Get.find<ChangeSupply>().changeByIdAndName(_nursery.substratesId!.toInt(), _nursery.substrateName ?? ''); | |||||
| } | } | ||||
| } else if (state is ActionDetailInitial) { | } else if (state is ActionDetailInitial) { | ||||
| print("init"); | print("init"); | ||||
| return Column( | return Column( | ||||
| children: [ | children: [ | ||||
| Padding( | Padding( | ||||
| padding: EdgeInsets.all(8), | |||||
| padding: const EdgeInsets.all(8), | |||||
| child: Column( | child: Column( | ||||
| crossAxisAlignment: | |||||
| CrossAxisAlignment.start, | |||||
| crossAxisAlignment: CrossAxisAlignment.start, | |||||
| children: <Widget>[ | children: <Widget>[ | ||||
| Text( | |||||
| const Text( | |||||
| 'Ươm', | 'Ươm', | ||||
| style: TextStyle( | |||||
| fontWeight: FontWeight.w500, | |||||
| fontSize: 22), | |||||
| style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22), | |||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Ngày thực hiện *", | "Ngày thực hiện *", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnExecuteTimePicker(), | _btnExecuteTimePicker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| width: double.infinity, | width: double.infinity, | ||||
| child: Text( | |||||
| child: const Text( | |||||
| "Loại giá thể", | "Loại giá thể", | ||||
| style: TextStyle( | |||||
| color: Colors.black54, | |||||
| fontSize: 13.0), | |||||
| style: TextStyle(color: Colors.black54, fontSize: 13.0), | |||||
| ), | ), | ||||
| ), | ), | ||||
| _btnSelectSubstrates(), | _btnSelectSubstrates(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _seedLengthField(), | _seedLengthField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _quantityField(), | _quantityField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _seedIncubationTimeField(), | _seedIncubationTimeField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _desciptionField(), | _desciptionField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _executeByField(), | _executeByField(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| ], | ], | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _buildListAddWorker(), | _buildListAddWorker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| _btnAddWorker(), | _btnAddWorker(), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| Container( | Container( | ||||
| height: 16, | height: 16, | ||||
| color: Colors.grey[200], | color: Colors.grey[200], | ||||
| ), | ), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 8.0, | height: 8.0, | ||||
| ), | ), | ||||
| BlocBuilder<MediaHelperBloc, | |||||
| MediaHelperState>( | |||||
| builder: (context, state) { | |||||
| BlocBuilder<MediaHelperBloc, MediaHelperState>(builder: (context, state) { | |||||
| if (state is MediaHelperSuccess) { | if (state is MediaHelperSuccess) { | ||||
| print("length: " + | |||||
| state.items.length.toString()); | |||||
| print("length: " + state.items.length.toString()); | |||||
| return WidgetMediaPicker( | return WidgetMediaPicker( | ||||
| currentItems: state.items, | currentItems: state.items, | ||||
| onChangeFiles: (newPathFiles, | |||||
| deletePathFiles) async { | |||||
| Get.find<ChangeFileController>() | |||||
| .change(newPathFiles, | |||||
| deletePathFiles); | |||||
| onChangeFiles: (newPathFiles, deletePathFiles) async { | |||||
| Get.find<ChangeFileController>().change(newPathFiles, deletePathFiles); | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| return Center( | |||||
| child: | |||||
| CircularProgressIndicator()); | |||||
| return const Center(child: CircularProgressIndicator()); | |||||
| } | } | ||||
| }), | }), | ||||
| SizedBox( | |||||
| const SizedBox( | |||||
| height: 16, | height: 16, | ||||
| ), | ), | ||||
| Padding( | Padding( | ||||
| child: ButtonWidget( | child: ButtonWidget( | ||||
| title: 'CẬP NHẬT', | title: 'CẬP NHẬT', | ||||
| onPressed: () { | onPressed: () { | ||||
| FocusScopeNode currentFocus = | |||||
| FocusScope.of(context); | |||||
| if (!currentFocus | |||||
| .hasPrimaryFocus) { | |||||
| var currentFocus = FocusScope.of(context); | |||||
| if (!currentFocus.hasPrimaryFocus) { | |||||
| currentFocus.unfocus(); | currentFocus.unfocus(); | ||||
| } | } | ||||
| if (!Validators | |||||
| .stringNotNullOrEmpty( | |||||
| _workerNameController | |||||
| .text) && | |||||
| !Validators | |||||
| .stringNotNullOrEmpty( | |||||
| _trayNumberController | |||||
| .text)) { | |||||
| if (!Validators.stringNotNullOrEmpty(_workerNameController.text) && | |||||
| !Validators.stringNotNullOrEmpty(_trayNumberController.text)) { | |||||
| _validateInputs(); | _validateInputs(); | ||||
| } else { | } else { | ||||
| Utils.showDialog( | Utils.showDialog( | ||||
| title: | |||||
| "Tên công nhân hoặc khây trồng đang cập nhật", | |||||
| message: | |||||
| "Bạn có muốn cập nhật?", | |||||
| title: "Tên công nhân hoặc khây trồng đang cập nhật", | |||||
| message: "Bạn có muốn cập nhật?", | |||||
| textConfirm: "Tiếp tục", | textConfirm: "Tiếp tục", | ||||
| textCancel: "Xem lại", | textCancel: "Xem lại", | ||||
| onConfirm: () { | onConfirm: () { |