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

@GET("/api/tb-crops?page={page}&size={size}&query={query}") @GET("/api/tb-crops?page={page}&size={size}&query={query}")
Future<List<Plot>> getPlots( Future<List<Plot>> getPlots(
{@Path() int page = 0, @Path() int size = 20, @Path() String query = ""}); {@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

class _RestClient implements RestClient { class _RestClient implements RestClient {
_RestClient(this._dio, {this.baseUrl}) { _RestClient(this._dio, {this.baseUrl}) {
ArgumentError.checkNotNull(_dio, '_dio'); ArgumentError.checkNotNull(_dio, '_dio');
this.baseUrl ??= 'https://tpf.aztrace.vn';
this.baseUrl ??= 'http://tpf.aztrace.vn';
} }


final Dio _dio; final Dio _dio;
.toList(); .toList();
return value; 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

class Repository { class Repository {
final dio = DioProvider.instance(); 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}) { Future<List<Plot>> getPlots({int page, int size, String searchString}) {
final client = RestClient(dio); final client = RestClient(dio);
return client.getPlots(page: page, size: size, query: searchString); return client.getPlots(page: page, size: size, query: searchString);

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

<String, dynamic>{ <String, dynamic>{
'id': instance.id, 'id': instance.id,
'name': instance.name, 'name': instance.name,
'description': instance.description
'description': instance.description,
}; };

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

'executeDate': instance.executeDate, 'executeDate': instance.executeDate,
'description': instance.description, 'description': instance.description,
'activityTypeName': instance.activityTypeName, 'activityTypeName': instance.activityTypeName,
'workerName': instance.workerName
'workerName': instance.workerName,
}; };

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

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

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/screens/actions/other/bloc_get_action_type.dart';
import 'package:farm_tpf/utils/const_string.dart'; import 'package:farm_tpf/utils/const_string.dart';
import 'package:farm_tpf/utils/const_style.dart'; import 'package:farm_tpf/utils/const_style.dart';
import 'package:farm_tpf/utils/pref.dart'; import 'package:farm_tpf/utils/pref.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart';


class EditActionOtherScreen extends StatefulWidget { class EditActionOtherScreen extends StatefulWidget {
@override @override
GlobalKey<FormState> _formKey = GlobalKey(); GlobalKey<FormState> _formKey = GlobalKey();
bool _autoValidate = false; bool _autoValidate = false;
OtherAction _otherAction = OtherAction(); OtherAction _otherAction = OtherAction();
List<ActionType> _actionTypes = List<ActionType>();
ActionType _actionType;
var pref = LocalPref(); var pref = LocalPref();
FlutterToast flutterToast; FlutterToast flutterToast;
TextEditingController _descriptionController = TextEditingController(); TextEditingController _descriptionController = TextEditingController();
_otherAction.executeDate = "$parsedExecuteDate"; _otherAction.executeDate = "$parsedExecuteDate";
} }
executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime); 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() { Widget _btnExecuteTimePicker() {
child: Text( child: Text(
//TODO: check condition //TODO: check condition
executeTimeView == null ? "$executeTime" : executeTimeView, executeTimeView == null ? "$executeTime" : executeTimeView,
style: TextStyle(fontSize: 15.0, color: Colors.black54),
style: TextStyle(fontSize: 14.0, color: Colors.black87),
)), )),
Icon( Icon(
Icons.date_range, Icons.date_range,
))); )));
} }


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() { Widget _desciptionField() {
return TextFormField( return TextFormField(
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
); );
} }


@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

dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
#flutter packages pub run build_runner build --delete-conflicting-outputs
retrofit_generator: ^1.3.7 retrofit_generator: ^1.3.7
# flutter packages pub run json_model
# json_model: ^0.0.2 # json_model: ^0.0.2
build_runner: any build_runner: any
json_serializable: any json_serializable: any

Loading…
Cancel
Save