| @@ -0,0 +1,43 @@ | |||
| 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; | |||
| } | |||
| } | |||
| @@ -3,12 +3,12 @@ import 'package:farm_tpf/custom_model/CropPlot.dart'; | |||
| import 'package:farm_tpf/custom_model/Device.dart'; | |||
| import 'package:farm_tpf/custom_model/EnvironmentParameter.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/account.dart'; | |||
| import 'package:farm_tpf/custom_model/password.dart'; | |||
| import 'package:farm_tpf/custom_model/user.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/utils/const_common.dart'; | |||
| import 'package:retrofit/retrofit.dart'; | |||
| @@ -37,8 +37,8 @@ abstract class RestClient { | |||
| @PUT("/api/update-my-profile") | |||
| 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 | |||
| @PUT("/api/update-fcmToken") | |||
| @@ -128,13 +128,13 @@ class _RestClient implements RestClient { | |||
| } | |||
| @override | |||
| getSupplies(type) async { | |||
| ArgumentError.checkNotNull(type, 'type'); | |||
| getSupplies({query = ""}) async { | |||
| const _extra = <String, dynamic>{}; | |||
| final queryParameters = <String, dynamic>{}; | |||
| queryParameters.removeWhere((k, v) => v == null); | |||
| final _data = <String, dynamic>{}; | |||
| final Response<List<dynamic>> _result = await _dio.request( | |||
| '/api/tb-supplies-by-type/$type', | |||
| '/api/list-supplies-in-warehouses/ALL?q=$query', | |||
| queryParameters: queryParameters, | |||
| options: RequestOptions( | |||
| method: 'GET', | |||
| @@ -6,6 +6,7 @@ import 'package:farm_tpf/custom_model/CropPlot.dart'; | |||
| import 'package:farm_tpf/custom_model/Device.dart'; | |||
| import 'package:farm_tpf/custom_model/EnvironmentParameter.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/user.dart'; | |||
| import 'package:farm_tpf/custom_model/user_request.dart'; | |||
| @@ -13,7 +14,6 @@ import 'package:farm_tpf/data/api/app_exception.dart'; | |||
| import 'package:farm_tpf/data/api/dio_provider.dart'; | |||
| import 'package:farm_tpf/data/api/rest_client.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/utils/const_common.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| @@ -78,9 +78,9 @@ class Repository { | |||
| return value; | |||
| } | |||
| Future<List<Supply>> getSupplies(String type) async { | |||
| Future<List<Supply>> getSupplies({String query = ""}) async { | |||
| final client = RestClient(dio); | |||
| return client.getSupplies(type); | |||
| return client.getSupplies(query: query); | |||
| } | |||
| Object getInstanceClass() { | |||
| @@ -1,20 +0,0 @@ | |||
| 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); | |||
| } | |||
| @@ -1,28 +0,0 @@ | |||
| // 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 | |||
| }; | |||
| @@ -1,4 +1,3 @@ | |||
| export 'Supply.dart'; | |||
| export 'Crop.dart'; | |||
| export 'ResourceHelper.dart'; | |||
| export 'ActionType.dart'; | |||
| @@ -3,9 +3,9 @@ import 'dart:convert'; | |||
| import 'package:farm_tpf/custom_model/Media.dart'; | |||
| import 'package:farm_tpf/custom_model/Nursery.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/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/widget_loading.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; | |||
| @@ -194,7 +194,7 @@ class _EditActionNurseryState extends State<EditActionNurseryScreen> { | |||
| .push(MaterialPageRoute( | |||
| builder: (_) => ResourceHelperScreen( | |||
| titleName: "Giá thể", | |||
| type: ConstCommon.supplyTypeSubStrate, | |||
| type: ConstCommon.supplyTypeAll, | |||
| selectedId: Get.find<ChangeSupply>().selectedSupplyId), | |||
| fullscreenDialog: false)) | |||
| .then((value) { | |||
| @@ -1,4 +1,4 @@ | |||
| import 'package:farm_tpf/models/Supply.dart'; | |||
| import 'package:farm_tpf/custom_model/Supply.dart'; | |||
| import 'package:get/get.dart'; | |||
| class ChangeSupply extends GetxController { | |||
| @@ -15,7 +15,7 @@ class ChangeSupply extends GetxController { | |||
| void change(Supply supply) { | |||
| currentSupply = supply; | |||
| selectedSupplyId = supply.id; | |||
| selectedSupplyName = supply.name; | |||
| selectedSupplyName = supply.tbSuppliesName; | |||
| update(); | |||
| } | |||
| @@ -2,9 +2,8 @@ import 'dart:async'; | |||
| import 'package:bloc/bloc.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/models/Supply.dart'; | |||
| import 'package:farm_tpf/utils/bloc/infinity_scroll_bloc.dart'; | |||
| import 'package:meta/meta.dart'; | |||
| part 'supply_event.dart'; | |||
| @@ -20,7 +19,7 @@ class SupplyBloc extends Bloc<SupplyEvent, SupplyState> { | |||
| ) async* { | |||
| if (event is DataFetched) { | |||
| try { | |||
| final response = await repository.getSupplies(event.type); | |||
| final response = await repository.getSupplies(query: event.type); | |||
| List<Supply> supplies = response.map((supply) { | |||
| if (supply.id == event.selectedId) { | |||
| supply.isSelected = true; | |||
| @@ -33,7 +32,7 @@ class SupplyBloc extends Bloc<SupplyEvent, SupplyState> { | |||
| } | |||
| } else if (event is OnRefresh) { | |||
| try { | |||
| final response = await repository.getSupplies(event.type); | |||
| final response = await repository.getSupplies(query: event.type); | |||
| List<Supply> supplies = response.map((supply) { | |||
| if (supply.id == event.selectedId) { | |||
| supply.isSelected = true; | |||
| @@ -46,10 +45,10 @@ class SupplyBloc extends Bloc<SupplyEvent, SupplyState> { | |||
| } | |||
| } else if (event is OnSearch) { | |||
| try { | |||
| final response = await repository.getSupplies(event.type); | |||
| final response = await repository.getSupplies(query: event.type); | |||
| bool query(Supply supply) => | |||
| event.searchString.isEmpty || | |||
| supply.name | |||
| supply.tbSuppliesName | |||
| .toLowerCase() | |||
| .contains(event.searchString.toLowerCase()); | |||
| final result = response.where(query).toList(); | |||
| @@ -1,5 +1,5 @@ | |||
| import 'package:farm_tpf/custom_model/Supply.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/loading_list_page.dart'; | |||
| import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart'; | |||
| @@ -132,10 +132,10 @@ class ItemInfinityWidget extends StatelessWidget { | |||
| child: Card( | |||
| child: Material( | |||
| child: RadioListTile( | |||
| title: Text(item.name.toString()), | |||
| subtitle: Text(item.manufacturer.toString()), | |||
| title: Text(item.tbSuppliesName.toString()), | |||
| subtitle: Text(item.tbWarehouseName.toString()), | |||
| value: item, | |||
| groupValue: item.isSelected == null ? null : item, | |||
| groupValue: item.isSelected == false ? null : item, | |||
| onChanged: (Supply value) { | |||
| print("selected value: ${value.id}"); | |||
| Navigator.of(context).pop(value); | |||
| @@ -1,4 +1,3 @@ | |||
| import 'package:farm_tpf/models/Supply.dart'; | |||
| import 'package:farm_tpf/presentation/screens/resources/bloc/supply_bloc.dart'; | |||
| import 'package:farm_tpf/utils/const_color.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| @@ -61,6 +61,7 @@ class ConstCommon { | |||
| static const String supplyTypeDung = "PHANBON"; | |||
| static const String supplyTypeSubStrate = "GIATHE"; | |||
| static const String supplyTypeProtectPlant = "THUOCBVTV"; | |||
| static const String supplyTypeAll = ""; | |||
| } | |||
| enum CRUDStatus { unknown, add, edit, delete } | |||