| @@ -0,0 +1,24 @@ | |||
| class ActionType { | |||
| int id; | |||
| String name; | |||
| String description; | |||
| String urlLogo; | |||
| ActionType({this.id, this.name, this.description, this.urlLogo}); | |||
| ActionType.fromJson(Map<String, dynamic> json) { | |||
| id = json['id']; | |||
| name = json['name']; | |||
| description = json['description']; | |||
| urlLogo = json['urlLogo']; | |||
| } | |||
| 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['urlLogo'] = this.urlLogo; | |||
| return data; | |||
| } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| import 'package:dio/dio.dart'; | |||
| import 'package:farm_tpf/custom_model/ActionType.dart'; | |||
| import 'package:farm_tpf/custom_model/CropPlot.dart'; | |||
| import 'package:farm_tpf/custom_model/Device.dart'; | |||
| import 'package:farm_tpf/custom_model/EnvironmentParameter.dart'; | |||
| @@ -12,7 +13,6 @@ 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/index.dart'; | |||
| import 'package:farm_tpf/utils/const_common.dart'; | |||
| import 'package:retrofit/retrofit.dart'; | |||
| @@ -56,6 +56,7 @@ abstract class RestClient { | |||
| Future<List<TbCropDTO>> getPlots( | |||
| {@Path() int page = 0, @Path() int size = 20, @Path() String query = ""}); | |||
| //TODO: check clean code | |||
| @GET("/api/listActivityTypesOther") | |||
| Future<List<ActionType>> getActionTypes({@DioOptions() Options options}); | |||
| @@ -2,6 +2,7 @@ import 'dart:convert'; | |||
| import 'package:dio/dio.dart'; | |||
| import 'package:dio_http_cache/dio_http_cache.dart'; | |||
| import 'package:farm_tpf/custom_model/ActionType.dart'; | |||
| import 'package:farm_tpf/custom_model/CropPlot.dart'; | |||
| import 'package:farm_tpf/custom_model/Device.dart'; | |||
| import 'package:farm_tpf/custom_model/EnvironmentParameter.dart'; | |||
| @@ -211,11 +212,10 @@ class Repository { | |||
| } | |||
| //NEW IMPLEMENT | |||
| Future<void> actionTypes(int cropTypeId, Function(List<ActionType>) onSuccess, | |||
| Function(dynamic) onError) async { | |||
| Future<void> allActionTypes( | |||
| Function(List<ActionType>) onSuccess, Function(dynamic) onError) async { | |||
| try { | |||
| var url = | |||
| '${ConstCommon.baseUrl}/api/listActivityTypesCulture/$cropTypeId'; | |||
| var url = '${ConstCommon.baseUrl}/api/tb-activity-types'; | |||
| final Response<List<dynamic>> _result = await dio.get(url); | |||
| var value = _result.data | |||
| @@ -1,15 +0,0 @@ | |||
| import 'package:json_annotation/json_annotation.dart'; | |||
| part 'ActionType.g.dart'; | |||
| @JsonSerializable() | |||
| class ActionType { | |||
| ActionType(); | |||
| num id; | |||
| String name; | |||
| String description; | |||
| factory ActionType.fromJson(Map<String,dynamic> json) => _$ActionTypeFromJson(json); | |||
| Map<String, dynamic> toJson() => _$ActionTypeToJson(this); | |||
| } | |||
| @@ -1,21 +0,0 @@ | |||
| // 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, | |||
| }; | |||
| @@ -1,2 +1 @@ | |||
| export 'ResourceHelper.dart'; | |||
| export 'ActionType.dart'; | |||
| @@ -1,5 +1,6 @@ | |||
| import 'dart:convert'; | |||
| import 'package:farm_tpf/custom_model/ActionType.dart'; | |||
| import 'package:farm_tpf/custom_model/Other.dart'; | |||
| import 'package:farm_tpf/data/api/app_exception.dart'; | |||
| import 'package:farm_tpf/data/repository/repository.dart'; | |||
| @@ -1,5 +1,6 @@ | |||
| import 'package:bloc/bloc.dart'; | |||
| import 'package:equatable/equatable.dart'; | |||
| import 'package:farm_tpf/custom_model/ActionType.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'; | |||
| @@ -10,10 +11,10 @@ class PlotActionTypeCubit extends Cubit<PlotActionTypeState> { | |||
| final Repository repository; | |||
| PlotActionTypeCubit(this.repository) : super(PlotActionTypeInitial()); | |||
| Future<void> getActionTypes(int cropTypeId) async { | |||
| Future<void> getAllActionTypes() async { | |||
| try { | |||
| emit(PlotActionTypeLoading()); | |||
| await repository.actionTypes(cropTypeId, (data) { | |||
| await repository.allActionTypes((data) { | |||
| emit(PlotActionTypeSuccess(data)); | |||
| }, (error) { | |||
| emit(PlotActionTypeError(AppException.handleError(error))); | |||
| @@ -1,4 +1,5 @@ | |||
| import 'package:cached_network_image/cached_network_image.dart'; | |||
| import 'package:farm_tpf/custom_model/ActionType.dart'; | |||
| import 'package:farm_tpf/data/repository/repository.dart'; | |||
| import 'package:farm_tpf/models/index.dart'; | |||
| import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | |||
| @@ -160,7 +161,7 @@ class _PlotActionScreenState extends State<PlotActionScreen> | |||
| Widget build(BuildContext context) { | |||
| return BlocProvider( | |||
| create: (contex) => | |||
| PlotActionTypeCubit(Repository())..getActionTypes(widget.cropType), | |||
| PlotActionTypeCubit(Repository())..getAllActionTypes(), | |||
| child: BlocBuilder<PlotActionTypeCubit, PlotActionTypeState>( | |||
| builder: (context, state) { | |||
| if (state is PlotActionTypeLoading) { | |||
| @@ -51,6 +51,7 @@ dependencies: | |||
| flutter_image_compress: ^0.7.0 | |||
| flutter_svg: ^0.19.1 | |||
| google_fonts: ^1.1.1 | |||
| dev_dependencies: | |||
| flutter_test: | |||