Browse Source

action packing

master
daivph 5 years ago
parent
commit
2cff308adc
8 changed files with 145 additions and 3 deletions
  1. +1
    -1
      ios/Flutter/.last_build_id
  2. +4
    -0
      lib/data/api/rest_client.dart
  3. +20
    -0
      lib/data/api/rest_client.g.dart
  4. +6
    -0
      lib/data/repository/repository.dart
  5. +32
    -0
      lib/presentation/screens/actions/bloc_get_harvest.dart
  6. +9
    -2
      lib/presentation/screens/actions/harvest/sc_edit_action_harvest.dart
  7. +66
    -0
      lib/presentation/screens/actions/packing/sc_edit_action_packing.dart
  8. +7
    -0
      lib/presentation/screens/plot_detail/sc_plot_action.dart

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

0d1f90510e22958a585802bb59f9c570
eb141365fb69a4e0decadd2584d53516

+ 4
- 0
lib/data/api/rest_client.dart View File

import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:farm_tpf/custom_model/CropPlot.dart'; import 'package:farm_tpf/custom_model/CropPlot.dart';
import 'package:farm_tpf/custom_model/Device.dart'; import 'package:farm_tpf/custom_model/Device.dart';
import 'package:farm_tpf/custom_model/Harvest.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';
@GET("/api/water-types") @GET("/api/water-types")
Future<List<WaterType>> getWaterTypes({@DioOptions() Options options}); Future<List<WaterType>> getWaterTypes({@DioOptions() Options options});


@GET("/api/tb-harvests")
Future<List<Harvest>> getHarvests();

//Crop //Crop
@GET( @GET(
"/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")

+ 20
- 0
lib/data/api/rest_client.g.dart View File

return value; return value;
} }


@override
getHarvests() async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
final Response<List<dynamic>> _result = await _dio.request(
'/api/tb-harvests',
queryParameters: queryParameters,
options: RequestOptions(
method: 'GET',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
var value = _result.data
.map((dynamic i) => Harvest.fromJson(i as Map<String, dynamic>))
.toList();
return value;
}

@override @override
getCropDetail(cropId, {page = 0, size = 20}) async { getCropDetail(cropId, {page = 0, size = 20}) async {
ArgumentError.checkNotNull(cropId, 'cropId'); ArgumentError.checkNotNull(cropId, 'cropId');

+ 6
- 0
lib/data/repository/repository.dart View File

import 'package:dio_http_cache/dio_http_cache.dart'; import 'package:dio_http_cache/dio_http_cache.dart';
import 'package:farm_tpf/custom_model/CropPlot.dart'; import 'package:farm_tpf/custom_model/CropPlot.dart';
import 'package:farm_tpf/custom_model/Device.dart'; import 'package:farm_tpf/custom_model/Device.dart';
import 'package:farm_tpf/custom_model/Harvest.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';
return client.getActionTypes(); return client.getActionTypes();
} }


Future<List<Harvest>> getHarvests() {
final client = RestClient(dio);
return client.getHarvests();
}

Future<List<WaterType>> getWaterTypes() { Future<List<WaterType>> getWaterTypes() {
final client = RestClient(dio); final client = RestClient(dio);
var op = buildConfigurableCacheOptions(forceRefresh: true); var op = buildConfigurableCacheOptions(forceRefresh: true);

+ 32
- 0
lib/presentation/screens/actions/bloc_get_harvest.dart View File

import 'package:farm_tpf/data/repository/repository.dart';
import 'package:rxdart/rxdart.dart';

class GetHarvestBloc {
final _repository = Repository();
final _getHarvestFetcher = PublishSubject<dynamic>();

Stream<dynamic> get actions => _getHarvestFetcher.stream;

void getHarvests(
Function(dynamic) onSuccess, Function(String) onError) async {
try {
_repository.getHarvests().then((value) {
onSuccess(value);
_getHarvestFetcher.sink.add(value);
}).catchError((onError) {
_getHarvestFetcher.addError(onError);
onError(onError);
});
} catch (e) {
_getHarvestFetcher.addError(e);
onError(e);
}
}

void dispose() async {
await _getHarvestFetcher.drain();
_getHarvestFetcher.close();
}
}

final getHarvestBloc = GetHarvestBloc();

+ 9
- 2
lib/presentation/screens/actions/harvest/sc_edit_action_harvest.dart View File

IconButton( IconButton(
icon: Icon(Icons.ac_unit), icon: Icon(Icons.ac_unit),
onPressed: () { onPressed: () {
Get.to(EditActionPackingScreen(
cropId: widget.cropId));
if (_harvest.id != null) {
Get.to(EditActionPackingScreen(
cropId: widget.cropId,
harvestId: _harvest.id,
));
} else {
Get.to(EditActionPackingScreen(
cropId: widget.cropId));
}
}) })
], ],
); );

+ 66
- 0
lib/presentation/screens/actions/packing/sc_edit_action_packing.dart View File

import 'dart:convert'; import 'dart:convert';


import 'package:farm_tpf/custom_model/Harvest.dart';
import 'package:farm_tpf/custom_model/Packing.dart'; import 'package:farm_tpf/custom_model/Packing.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/presentation/custom_widgets/widget_loading.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart';
import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart'; import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart';
import 'package:farm_tpf/presentation/screens/actions/bloc_get_harvest.dart';
import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_file_controller.dart'; import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_file_controller.dart';
import 'package:farm_tpf/utils/const_common.dart'; import 'package:farm_tpf/utils/const_common.dart';
import 'package:farm_tpf/utils/const_string.dart'; import 'package:farm_tpf/utils/const_string.dart';
TextEditingController _removedQuantityController = TextEditingController(); TextEditingController _removedQuantityController = TextEditingController();
TextEditingController _descriptionController = TextEditingController(); TextEditingController _descriptionController = TextEditingController();


List<Harvest> _harvests = List<Harvest>();
Harvest harvestValue;
String executeTimeView; String executeTimeView;
DateTime executeTime = DateTime.now(); DateTime executeTime = DateTime.now();
List<String> filePaths = List<String>(); List<String> filePaths = List<String>();
_packing.executeDate = "$parsedExecuteDate"; _packing.executeDate = "$parsedExecuteDate";
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime); executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime);
_packing.cropId = widget.cropId; _packing.cropId = widget.cropId;

if (!widget.isEdit) {
getHarvestBloc.getHarvests((data) {
_harvests = data;
for (var item in _harvests) {
if (item.id == widget.harvestId) {
harvestValue = item;
break;
}
}
}, (err) {});
}
} }


_validateInputs() async { _validateInputs() async {
} }
} }


List<DropdownMenuItem<Harvest>> _buildDropMenu(List<Harvest> actions) {
return actions
.map((action) => DropdownMenuItem<Harvest>(
child: Text("Lần thu hoạch " + action.id.toString()),
value: action,
))
.toList();
}

Widget _dropdownHarvest() {
return StreamBuilder(
stream: getHarvestBloc.actions,
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
return DropdownButtonFormField<Harvest>(
value: harvestValue,
hint: Text("Mã thu hoạch"),
onChanged: (Harvest newValue) {
setState(() {
harvestValue = newValue;
_packing.harvestId = newValue.id;
});
},
validator: (value) => value == null ? "Mã thu hoạch" : null,
isExpanded: true,
items: _buildDropMenu(_harvests));
} else {
return Center(
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: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
_descriptionController.text = _descriptionController.text =
_packing.description ?? ""; _packing.description ?? "";


//select harvest
getHarvestBloc.getHarvests((data) {
_harvests = data;
for (var item in _harvests) {
if (item.id == _packing.harvestId) {
harvestValue = item;
break;
}
}
}, (err) {});

try { try {
executeTime = executeTime =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
SizedBox( SizedBox(
height: 8.0, height: 8.0,
), ),
_dropdownHarvest(),
SizedBox(
height: 8.0,
),
_l1Field(), _l1Field(),
SizedBox( SizedBox(
height: 8.0, height: 8.0,

+ 7
- 0
lib/presentation/screens/plot_detail/sc_plot_action.dart View File

import 'package:farm_tpf/presentation/screens/actions/harvest/sc_edit_action_harvest.dart'; import 'package:farm_tpf/presentation/screens/actions/harvest/sc_edit_action_harvest.dart';
import 'package:farm_tpf/presentation/screens/actions/nursery/sc_edit_action_nursery.dart'; import 'package:farm_tpf/presentation/screens/actions/nursery/sc_edit_action_nursery.dart';
import 'package:farm_tpf/presentation/screens/actions/other/sc_edit_action_other.dart'; import 'package:farm_tpf/presentation/screens/actions/other/sc_edit_action_other.dart';
import 'package:farm_tpf/presentation/screens/actions/packing/sc_edit_action_packing.dart';
import 'package:farm_tpf/presentation/screens/actions/plant/sc_edit_action_plant.dart'; import 'package:farm_tpf/presentation/screens/actions/plant/sc_edit_action_plant.dart';
import 'package:farm_tpf/presentation/screens/actions/spraying/sc_edit_action_spraying.dart'; import 'package:farm_tpf/presentation/screens/actions/spraying/sc_edit_action_spraying.dart';
import 'package:farm_tpf/presentation/screens/actions/use_water/sc_edit_action_user_water.dart'; import 'package:farm_tpf/presentation/screens/actions/use_water/sc_edit_action_user_water.dart';
activityId: item.id, activityId: item.id,
isEdit: true, isEdit: true,
)); ));
} else if (item.activityTypeName == "ACTIVE_TYPE_PACKING") {
Get.to(EditActionPackingScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} }
}); });
} }

Loading…
Cancel
Save