Browse Source

screen action type

master
daivph 5 years ago
parent
commit
701b386f5d
8 changed files with 171 additions and 17 deletions
  1. +2
    -0
      lib/data/api/rest_client.dart
  2. +21
    -1
      lib/data/api/rest_client.g.dart
  3. +5
    -0
      lib/data/repository/repository.dart
  4. +1
    -1
      lib/models/ActionType.g.dart
  5. +1
    -1
      lib/models/OtherAction.g.dart
  6. +27
    -0
      lib/presentation/screens/actions/other/bloc_get_action_type.dart
  7. +112
    -14
      lib/presentation/screens/actions/other/sc_edit_action_other.dart
  8. +2
    -0
      pubspec.yaml

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

@@ -42,4 +42,6 @@ abstract class RestClient {
@GET("/api/tb-crops?page={page}&size={size}&query={query}")
Future<List<Plot>> getPlots(
{@Path() int page = 0, @Path() int size = 20, @Path() String query = ""});
@GET("/api/listActivityTypesOther")
Future<List<ActionType>> getActionTypes();
}

+ 21
- 1
lib/data/api/rest_client.g.dart View File

@@ -9,7 +9,7 @@ part of 'rest_client.dart';
class _RestClient implements RestClient {
_RestClient(this._dio, {this.baseUrl}) {
ArgumentError.checkNotNull(_dio, '_dio');
this.baseUrl ??= 'https://tpf.aztrace.vn';
this.baseUrl ??= 'http://tpf.aztrace.vn';
}

final Dio _dio;
@@ -185,4 +185,24 @@ class _RestClient implements RestClient {
.toList();
return value;
}

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

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

@@ -11,6 +11,11 @@ import 'package:farm_tpf/utils/const_common.dart';
class Repository {
final dio = DioProvider.instance();

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

Future<List<Plot>> getPlots({int page, int size, String searchString}) {
final client = RestClient(dio);
return client.getPlots(page: page, size: size, query: searchString);

+ 1
- 1
lib/models/ActionType.g.dart View File

@@ -17,5 +17,5 @@ Map<String, dynamic> _$ActionTypeToJson(ActionType instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
'description': instance.description
'description': instance.description,
};

+ 1
- 1
lib/models/OtherAction.g.dart View File

@@ -23,5 +23,5 @@ Map<String, dynamic> _$OtherActionToJson(OtherAction instance) =>
'executeDate': instance.executeDate,
'description': instance.description,
'activityTypeName': instance.activityTypeName,
'workerName': instance.workerName
'workerName': instance.workerName,
};

+ 27
- 0
lib/presentation/screens/actions/other/bloc_get_action_type.dart View File

@@ -0,0 +1,27 @@
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:rxdart/rxdart.dart';

class GetActionTypeBloc {
final _repository = Repository();
final _getActionTypesFetcher = PublishSubject<dynamic>();

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

void getActionTypes(
Function(dynamic) onSuccess, Function(String) onError) async {
_repository.getActionTypes().then((value) {
onSuccess(value);
_getActionTypesFetcher.sink.add(value);
}).catchError((onError) {
onError(onError);
_getActionTypesFetcher.addError(onError);
});
}

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

final getActionTypeBloc = GetActionTypeBloc();

+ 112
- 14
lib/presentation/screens/actions/other/sc_edit_action_other.dart View File

@@ -1,5 +1,6 @@
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/models/index.dart';
import 'package:farm_tpf/presentation/screens/actions/other/bloc_get_action_type.dart';
import 'package:farm_tpf/utils/const_string.dart';
import 'package:farm_tpf/utils/const_style.dart';
import 'package:farm_tpf/utils/pref.dart';
@@ -8,6 +9,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart';

class EditActionOtherScreen extends StatefulWidget {
@override
@@ -20,6 +22,8 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> {
GlobalKey<FormState> _formKey = GlobalKey();
bool _autoValidate = false;
OtherAction _otherAction = OtherAction();
List<ActionType> _actionTypes = List<ActionType>();
ActionType _actionType;
var pref = LocalPref();
FlutterToast flutterToast;
TextEditingController _descriptionController = TextEditingController();
@@ -44,6 +48,17 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> {
_otherAction.executeDate = "$parsedExecuteDate";
}
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime);

//Get action types
getActionTypeBloc.getActionTypes((data) {
_actionTypes = data;
for (var item in _actionTypes) {
if (item.id == _otherAction.activityId) {
_actionType = item;
break;
}
}
}, (err) {});
}

Widget _btnExecuteTimePicker() {
@@ -72,7 +87,7 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> {
child: Text(
//TODO: check condition
executeTimeView == null ? "$executeTime" : executeTimeView,
style: TextStyle(fontSize: 15.0, color: Colors.black54),
style: TextStyle(fontSize: 14.0, color: Colors.black87),
)),
Icon(
Icons.date_range,
@@ -82,6 +97,44 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> {
)));
}

List<DropdownMenuItem<ActionType>> _buildDropMenu(List<ActionType> actions) {
return actions
.map((action) => DropdownMenuItem<ActionType>(
child: Text(action.name.toString()),
value: action,
))
.toList();
}

Widget _dropdownAcionTypes() {
return StreamBuilder(
stream: getActionTypeBloc.actions,
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
return DropdownButtonFormField<ActionType>(
value: _actionType,
hint: Text("Hoạt động"),
onChanged: (ActionType newValue) {
setState(() {
_actionType = newValue;
_otherAction.activityId = newValue.id;
_otherAction.activityTypeName = newValue.name;
});
},
validator: (value) => value == null ? "Hoạt động" : null,
isExpanded: true,
items: _buildDropMenu(_actionTypes));
} else if (snapshot.hasError) {
return Container();
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
);
}

Widget _desciptionField() {
return TextFormField(
keyboardType: TextInputType.text,
@@ -107,18 +160,63 @@ class _EditActionOtherScreenState extends State<EditActionOtherScreen> {
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(plot_action_other),
actions: <Widget>[
IconButton(
icon: Icon(Icons.done),
disabledColor: Colors.grey,
onPressed: 1 == 1 ? null : () {})
],
),
);
_actionAppBar() {
IconButton iconButton;
if (1 == 1) {
iconButton = IconButton(
icon: Icon(
Icons.done,
color: Colors.black,
),
onPressed: () {},
);
return <Widget>[iconButton];
}
return <Widget>[Container()];
}

@override
Widget build(BuildContext context) => KeyboardDismisser(
gestures: [
GestureType.onTap,
GestureType.onPanUpdateDownDirection,
],
child: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title: Text(plot_action_other),
actions: _actionAppBar()),
body: KeyboardDismisser(
child: Form(
key: _formKey,
autovalidate: _autoValidate,
child: SingleChildScrollView(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Container(
width: double.infinity,
child: Text(
"Ngày thực hiện",
style: TextStyle(
color: Colors.black54, fontSize: 13.0),
),
),
_btnExecuteTimePicker(),
SizedBox(
height: 8.0,
),
_dropdownAcionTypes(),
SizedBox(
height: 8.0,
),
_desciptionField(),
SizedBox(
height: 8.0,
),
_workerNameField()
],
),
)))));
}

+ 2
- 0
pubspec.yaml View File

@@ -41,7 +41,9 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
#flutter packages pub run build_runner build --delete-conflicting-outputs
retrofit_generator: ^1.3.7
# flutter packages pub run json_model
# json_model: ^0.0.2
build_runner: any
json_serializable: any

Loading…
Cancel
Save