Browse Source

post nursery

master
daivph 5 years ago
parent
commit
20c640b27a
6 changed files with 70 additions and 16 deletions
  1. +6
    -3
      lib/data/api/app_exception.dart
  2. +8
    -8
      lib/data/api/dio_provider.dart
  3. +23
    -0
      lib/data/repository/repository.dart
  4. +29
    -3
      lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart
  5. +2
    -2
      pubspec.lock
  6. +2
    -0
      pubspec.yaml

+ 6
- 3
lib/data/api/app_exception.dart View File

import 'dart:convert';

import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
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) { static String handleError(dynamic error) {
String errorDescription = ""; String errorDescription = "";
if (error is DioError) {
DioError dioError = error;

try {
DioError dioError = error as DioError;
switch (dioError.type) { switch (dioError.type) {
case DioErrorType.CANCEL: case DioErrorType.CANCEL:
errorDescription = exception_dio_cancle; errorDescription = exception_dio_cancle;
errorDescription = exception_dio_send_timeout; errorDescription = exception_dio_send_timeout;
break; break;
} }
} else {
} catch (_) {
errorDescription = exception_common; errorDescription = exception_common;
} }
return errorDescription; return errorDescription;

+ 8
- 8
lib/data/api/dio_provider.dart View File

var token = await pref.getString(DATA_CONST.TOKEN_KEY); var token = await pref.getString(DATA_CONST.TOKEN_KEY);
options.headers["Authorization"] = "Bearer $token"; options.headers["Authorization"] = "Bearer $token";
options.receiveTimeout = 20000; options.receiveTimeout = 20000;
// log("onRequest: ${options.uri}\n"
// "data=${options.data}\n"
// "method=${options.method}\n"
// "headers=${options.headers}\n"
// "queryParameters=${options.queryParameters}");
log("onRequest: ${options.uri}\n"
"data=${options.data}\n"
"method=${options.method}\n"
"headers=${options.headers}\n"
"queryParameters=${options.queryParameters}");
return options; return options;
} }


@override @override
Future onResponse(Response response) { Future onResponse(Response response) {
// log("onResponse: $response");
log("onResponse: $response");
return super.onResponse(response); return super.onResponse(response);
} }


@override @override
Future onError(DioError err) { Future onError(DioError err) {
// log("onError: $err\n"
// "Response: ${err.response}");
log("onError: $err\n"
"Response: ${err.response}");
return super.onError(err); return super.onError(err);
} }
} }

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

import 'dart:io';

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/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/app_exception.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';
} }
return instanceClass; return instanceClass;
} }

//Action
Future<void> createNursery(Function(dynamic) onSuccess,
Function(String) onError, String activityNursery,
{List<File> files}) async {
FormData formData =
new FormData.fromMap({"activityNursery": activityNursery});
try {
await dio
.post("${ConstCommon.baseUrl}/api/createNursery", data: formData)
.then((value) {
onSuccess(value);
}).catchError((onError) {
onError(AppException.handleError(onError));
});
} catch (e) {
onError(AppException.handleError(e));
}
}
} }

+ 29
- 3
lib/presentation/screens/actions/nursery/sc_edit_action_nursery.dart View File

import 'dart:convert';

import 'package:farm_tpf/custom_model/Nursery.dart'; import 'package:farm_tpf/custom_model/Nursery.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/models/index.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_media_helper.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_media_helper.dart';
_nursery.nurseryDetail = new List<NurseryDetail>(); _nursery.nurseryDetail = new List<NurseryDetail>();
flutterToast = FlutterToast(context); flutterToast = FlutterToast(context);
//UPDATE //UPDATE
if (_nursery != null) {
if (_nursery.cropId != null) {
try { try {
executeTime = executeTime =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(_nursery.executeDate); DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(_nursery.executeDate);
var parsedExecuteDate = var parsedExecuteDate =
DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime); DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime);
_nursery.executeDate = "$parsedExecuteDate"; _nursery.executeDate = "$parsedExecuteDate";
//TODO: update cropid
_nursery.cropId = 1;
} }
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime); executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime);
} }


_validateInputs() async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
var activityNursery = jsonEncode(_nursery.toJson()).toString();
_repository.createNursery((value) {
print("post ok");
}, (error) {
print("--------------------------------");
print(error);
}, activityNursery);
} else {
_autoValidate = true;
}
}

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),
child: Text( child: Text(
changeSupply.currentSupply.name == null changeSupply.currentSupply.name == null
? "Loại giá thể" ? "Loại giá thể"
: _nursery.substrates.toString(),
: changeSupply.currentSupply.name.toString(),
style: TextStyle( style: TextStyle(
fontSize: 14.0, color: Colors.black87)))), fontSize: 14.0, color: Colors.black87)))),
Icon( Icon(
Icons.done, Icons.done,
color: Colors.black, color: Colors.black,
), ),
onPressed: () {},
onPressed: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
_validateInputs();
},
); );
return <Widget>[iconButton]; return <Widget>[iconButton];
} }

+ 2
- 2
pubspec.lock View File

source: hosted source: hosted
version: "0.14.0+3" version: "0.14.0+3"
http: http:
dependency: transitive
dependency: "direct main"
description: description:
name: http name: http
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.2.0" version: "2.2.0"
http_parser: http_parser:
dependency: transitive
dependency: "direct main"
description: description:
name: http_parser name: http_parser
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

+ 2
- 0
pubspec.yaml View File

intl: ^0.16.1 intl: ^0.16.1
flutter_datetime_picker: ^1.3.8 flutter_datetime_picker: ^1.3.8
# analyzer: ^0.39.14 # analyzer: ^0.39.14
http: ^0.12.2
http_parser: ^3.1.4


dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save