| class Supply { | |||||
| 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.fromJson(Map<String, dynamic> json) { | |||||
| id = json['id']; | |||||
| quantity = json['quantity']; | |||||
| unit = json['unit']; | |||||
| tbWarehouseId = json['tbWarehouseId']; | |||||
| tbWarehouseName = json['tbWarehouseName']; | |||||
| tbSuppliesName = json['tbSuppliesName']; | |||||
| tbSuppliesId = json['tbSuppliesId']; | |||||
| isSelected = false; | |||||
| } | |||||
| 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; | |||||
| return data; | |||||
| } | |||||
| } |
| import 'package:farm_tpf/custom_model/Device.dart'; | import 'package:farm_tpf/custom_model/Device.dart'; | ||||
| import 'package:farm_tpf/custom_model/EnvironmentParameter.dart'; | import 'package:farm_tpf/custom_model/EnvironmentParameter.dart'; | ||||
| import 'package:farm_tpf/custom_model/Harvest.dart'; | import 'package:farm_tpf/custom_model/Harvest.dart'; | ||||
| import 'package:farm_tpf/custom_model/Supply.dart'; | |||||
| import 'package:farm_tpf/custom_model/WaterType.dart'; | import 'package:farm_tpf/custom_model/WaterType.dart'; | ||||
| import 'package:farm_tpf/custom_model/account.dart'; | import 'package:farm_tpf/custom_model/account.dart'; | ||||
| import 'package:farm_tpf/custom_model/password.dart'; | import 'package:farm_tpf/custom_model/password.dart'; | ||||
| import 'package:farm_tpf/custom_model/user.dart'; | import 'package:farm_tpf/custom_model/user.dart'; | ||||
| import 'package:farm_tpf/custom_model/user_request.dart'; | import 'package:farm_tpf/custom_model/user_request.dart'; | ||||
| import 'package:farm_tpf/models/Supply.dart'; | |||||
| import 'package:farm_tpf/models/index.dart'; | import 'package:farm_tpf/models/index.dart'; | ||||
| import 'package:farm_tpf/utils/const_common.dart'; | import 'package:farm_tpf/utils/const_common.dart'; | ||||
| import 'package:retrofit/retrofit.dart'; | import 'package:retrofit/retrofit.dart'; | ||||
| @PUT("/api/update-my-profile") | @PUT("/api/update-my-profile") | ||||
| Future<Account> updateProfile(@Body() Account account); | Future<Account> updateProfile(@Body() Account account); | ||||
| @GET("/api/tb-supplies-by-type/{type}") | |||||
| Future<List<Supply>> getSupplies(@Path() String type); | |||||
| @GET("/api/list-supplies-in-warehouses/ALL?q={query}") | |||||
| Future<List<Supply>> getSupplies({@Path() String query = ""}); | |||||
| //Common | //Common | ||||
| @PUT("/api/update-fcmToken") | @PUT("/api/update-fcmToken") |
| } | } | ||||
| @override | @override | ||||
| getSupplies(type) async { | |||||
| ArgumentError.checkNotNull(type, 'type'); | |||||
| getSupplies({query = ""}) async { | |||||
| const _extra = <String, dynamic>{}; | const _extra = <String, dynamic>{}; | ||||
| final queryParameters = <String, dynamic>{}; | final queryParameters = <String, dynamic>{}; | ||||
| queryParameters.removeWhere((k, v) => v == null); | |||||
| final _data = <String, dynamic>{}; | final _data = <String, dynamic>{}; | ||||
| final Response<List<dynamic>> _result = await _dio.request( | final Response<List<dynamic>> _result = await _dio.request( | ||||
| '/api/tb-supplies-by-type/$type', | |||||
| '/api/list-supplies-in-warehouses/ALL?q=$query', | |||||
| queryParameters: queryParameters, | queryParameters: queryParameters, | ||||
| options: RequestOptions( | options: RequestOptions( | ||||
| method: 'GET', | method: 'GET', |
| import 'package:farm_tpf/custom_model/Device.dart'; | import 'package:farm_tpf/custom_model/Device.dart'; | ||||
| import 'package:farm_tpf/custom_model/EnvironmentParameter.dart'; | import 'package:farm_tpf/custom_model/EnvironmentParameter.dart'; | ||||
| import 'package:farm_tpf/custom_model/Harvest.dart'; | import 'package:farm_tpf/custom_model/Harvest.dart'; | ||||
| import 'package:farm_tpf/custom_model/Supply.dart'; | |||||
| import 'package:farm_tpf/custom_model/WaterType.dart'; | import 'package:farm_tpf/custom_model/WaterType.dart'; | ||||
| import 'package:farm_tpf/custom_model/user.dart'; | import 'package:farm_tpf/custom_model/user.dart'; | ||||
| import 'package:farm_tpf/custom_model/user_request.dart'; | import 'package:farm_tpf/custom_model/user_request.dart'; | ||||
| import 'package:farm_tpf/data/api/dio_provider.dart'; | import 'package:farm_tpf/data/api/dio_provider.dart'; | ||||
| import 'package:farm_tpf/data/api/rest_client.dart'; | import 'package:farm_tpf/data/api/rest_client.dart'; | ||||
| import 'package:farm_tpf/models/PagedResult.dart'; | import 'package:farm_tpf/models/PagedResult.dart'; | ||||
| import 'package:farm_tpf/models/Supply.dart'; | |||||
| import 'package:farm_tpf/models/index.dart'; | import 'package:farm_tpf/models/index.dart'; | ||||
| import 'package:farm_tpf/utils/const_common.dart'; | import 'package:farm_tpf/utils/const_common.dart'; | ||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
| return value; | return value; | ||||
| } | } | ||||
| Future<List<Supply>> getSupplies(String type) async { | |||||
| Future<List<Supply>> getSupplies({String query = ""}) async { | |||||
| final client = RestClient(dio); | final client = RestClient(dio); | ||||
| return client.getSupplies(type); | |||||
| return client.getSupplies(query: query); | |||||
| } | } | ||||
| Object getInstanceClass() { | Object getInstanceClass() { |
| import 'package:json_annotation/json_annotation.dart'; | |||||
| part 'Supply.g.dart'; | |||||
| @JsonSerializable() | |||||
| class Supply { | |||||
| Supply(); | |||||
| num id; | |||||
| String name; | |||||
| String sku; | |||||
| String manufacturer; | |||||
| String unit; | |||||
| num tbSuppliesTypeId; | |||||
| num tbCustomerId; | |||||
| bool isSelected; | |||||
| factory Supply.fromJson(Map<String, dynamic> json) => _$SupplyFromJson(json); | |||||
| Map<String, dynamic> toJson() => _$SupplyToJson(this); | |||||
| } |
| // GENERATED CODE - DO NOT MODIFY BY HAND | |||||
| part of 'Supply.dart'; | |||||
| // ************************************************************************** | |||||
| // JsonSerializableGenerator | |||||
| // ************************************************************************** | |||||
| Supply _$SupplyFromJson(Map<String, dynamic> json) { | |||||
| return Supply() | |||||
| ..id = json['id'] as num | |||||
| ..name = json['name'] as String | |||||
| ..sku = json['sku'] as String | |||||
| ..manufacturer = json['manufacturer'] as String | |||||
| ..unit = json['unit'] as String | |||||
| ..tbSuppliesTypeId = json['tbSuppliesTypeId'] as num | |||||
| ..tbCustomerId = json['tbCustomerId'] as num; | |||||
| } | |||||
| Map<String, dynamic> _$SupplyToJson(Supply instance) => <String, dynamic>{ | |||||
| 'id': instance.id, | |||||
| 'name': instance.name, | |||||
| 'sku': instance.sku, | |||||
| 'manufacturer': instance.manufacturer, | |||||
| 'unit': instance.unit, | |||||
| 'tbSuppliesTypeId': instance.tbSuppliesTypeId, | |||||
| 'tbCustomerId': instance.tbCustomerId | |||||
| }; |
| export 'Supply.dart'; | |||||
| export 'Crop.dart'; | export 'Crop.dart'; | ||||
| export 'ResourceHelper.dart'; | export 'ResourceHelper.dart'; | ||||
| export 'ActionType.dart'; | export 'ActionType.dart'; |
| import 'package:farm_tpf/custom_model/Media.dart'; | import 'package:farm_tpf/custom_model/Media.dart'; | ||||
| import 'package:farm_tpf/custom_model/Nursery.dart'; | import 'package:farm_tpf/custom_model/Nursery.dart'; | ||||
| import 'package:farm_tpf/custom_model/NurseryDetail.dart'; | import 'package:farm_tpf/custom_model/NurseryDetail.dart'; | ||||
| import 'package:farm_tpf/custom_model/Supply.dart'; | |||||
| import 'package:farm_tpf/data/api/app_exception.dart'; | import 'package:farm_tpf/data/api/app_exception.dart'; | ||||
| import 'package:farm_tpf/data/repository/repository.dart'; | import 'package:farm_tpf/data/repository/repository.dart'; | ||||
| import 'package:farm_tpf/models/index.dart'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart'; | import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; | import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; | ||||
| .push(MaterialPageRoute( | .push(MaterialPageRoute( | ||||
| builder: (_) => ResourceHelperScreen( | builder: (_) => ResourceHelperScreen( | ||||
| titleName: "Giá thể", | titleName: "Giá thể", | ||||
| type: ConstCommon.supplyTypeSubStrate, | |||||
| type: ConstCommon.supplyTypeAll, | |||||
| selectedId: Get.find<ChangeSupply>().selectedSupplyId), | selectedId: Get.find<ChangeSupply>().selectedSupplyId), | ||||
| fullscreenDialog: false)) | fullscreenDialog: false)) | ||||
| .then((value) { | .then((value) { |
| import 'package:farm_tpf/models/Supply.dart'; | |||||
| import 'package:farm_tpf/custom_model/Supply.dart'; | |||||
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||
| class ChangeSupply extends GetxController { | class ChangeSupply extends GetxController { | ||||
| void change(Supply supply) { | void change(Supply supply) { | ||||
| currentSupply = supply; | currentSupply = supply; | ||||
| selectedSupplyId = supply.id; | selectedSupplyId = supply.id; | ||||
| selectedSupplyName = supply.name; | |||||
| selectedSupplyName = supply.tbSuppliesName; | |||||
| update(); | update(); | ||||
| } | } | ||||
| import 'package:bloc/bloc.dart'; | import 'package:bloc/bloc.dart'; | ||||
| import 'package:equatable/equatable.dart'; | import 'package:equatable/equatable.dart'; | ||||
| import 'package:farm_tpf/custom_model/Supply.dart'; | |||||
| import 'package:farm_tpf/data/repository/repository.dart'; | import 'package:farm_tpf/data/repository/repository.dart'; | ||||
| import 'package:farm_tpf/models/Supply.dart'; | |||||
| import 'package:farm_tpf/utils/bloc/infinity_scroll_bloc.dart'; | |||||
| import 'package:meta/meta.dart'; | import 'package:meta/meta.dart'; | ||||
| part 'supply_event.dart'; | part 'supply_event.dart'; | ||||
| ) async* { | ) async* { | ||||
| if (event is DataFetched) { | if (event is DataFetched) { | ||||
| try { | try { | ||||
| final response = await repository.getSupplies(event.type); | |||||
| final response = await repository.getSupplies(query: event.type); | |||||
| List<Supply> supplies = response.map((supply) { | List<Supply> supplies = response.map((supply) { | ||||
| if (supply.id == event.selectedId) { | if (supply.id == event.selectedId) { | ||||
| supply.isSelected = true; | supply.isSelected = true; | ||||
| } | } | ||||
| } else if (event is OnRefresh) { | } else if (event is OnRefresh) { | ||||
| try { | try { | ||||
| final response = await repository.getSupplies(event.type); | |||||
| final response = await repository.getSupplies(query: event.type); | |||||
| List<Supply> supplies = response.map((supply) { | List<Supply> supplies = response.map((supply) { | ||||
| if (supply.id == event.selectedId) { | if (supply.id == event.selectedId) { | ||||
| supply.isSelected = true; | supply.isSelected = true; | ||||
| } | } | ||||
| } else if (event is OnSearch) { | } else if (event is OnSearch) { | ||||
| try { | try { | ||||
| final response = await repository.getSupplies(event.type); | |||||
| final response = await repository.getSupplies(query: event.type); | |||||
| bool query(Supply supply) => | bool query(Supply supply) => | ||||
| event.searchString.isEmpty || | event.searchString.isEmpty || | ||||
| supply.name | |||||
| supply.tbSuppliesName | |||||
| .toLowerCase() | .toLowerCase() | ||||
| .contains(event.searchString.toLowerCase()); | .contains(event.searchString.toLowerCase()); | ||||
| final result = response.where(query).toList(); | final result = response.where(query).toList(); |
| import 'package:farm_tpf/custom_model/Supply.dart'; | |||||
| import 'package:farm_tpf/data/repository/repository.dart'; | import 'package:farm_tpf/data/repository/repository.dart'; | ||||
| import 'package:farm_tpf/models/Supply.dart'; | |||||
| import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; | import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart'; | import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart'; | ||||
| child: Card( | child: Card( | ||||
| child: Material( | child: Material( | ||||
| child: RadioListTile( | child: RadioListTile( | ||||
| title: Text(item.name.toString()), | |||||
| subtitle: Text(item.manufacturer.toString()), | |||||
| title: Text(item.tbSuppliesName.toString()), | |||||
| subtitle: Text(item.tbWarehouseName.toString()), | |||||
| value: item, | value: item, | ||||
| groupValue: item.isSelected == null ? null : item, | |||||
| groupValue: item.isSelected == false ? null : item, | |||||
| onChanged: (Supply value) { | onChanged: (Supply value) { | ||||
| print("selected value: ${value.id}"); | print("selected value: ${value.id}"); | ||||
| Navigator.of(context).pop(value); | Navigator.of(context).pop(value); |
| import 'package:farm_tpf/models/Supply.dart'; | |||||
| import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart'; | import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart'; | ||||
| import 'package:farm_tpf/utils/const_color.dart'; | import 'package:farm_tpf/utils/const_color.dart'; | ||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; |
| static const String supplyTypeDung = "PHANBON"; | static const String supplyTypeDung = "PHANBON"; | ||||
| static const String supplyTypeSubStrate = "GIATHE"; | static const String supplyTypeSubStrate = "GIATHE"; | ||||
| static const String supplyTypeProtectPlant = "THUOCBVTV"; | static const String supplyTypeProtectPlant = "THUOCBVTV"; | ||||
| static const String supplyTypeAll = ""; | |||||
| } | } | ||||
| enum CRUDStatus { unknown, add, edit, delete } | enum CRUDStatus { unknown, add, edit, delete } |