Browse Source

show plot infor

master
daivph 5 years ago
parent
commit
2d30135871
5 changed files with 213 additions and 80 deletions
  1. +1
    -11
      lib/presentation/screens/plot/sc_plot.dart
  2. +28
    -0
      lib/presentation/screens/plot_detail/bloc_plot_information.dart
  3. +11
    -0
      lib/presentation/screens/plot_detail/sc_plot_detail.dart
  4. +170
    -69
      lib/presentation/screens/plot_detail/sc_plot_information.dart
  5. +3
    -0
      lib/utils/const_string.dart

+ 1
- 11
lib/presentation/screens/plot/sc_plot.dart View File

Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
appBar: AppBar(
centerTitle: true,
title: Text("Danh sách lô"),
actions: <Widget>[
IconButton(
icon: Icon(FontAwesomeIcons.infoCircle),
onPressed: () {
Get.to(PlotInformationScreen());
})
],
),
appBar: AppBar(centerTitle: true, title: Text("Danh sách lô")),
body: InfinityView()); body: InfinityView());
} }
} }

+ 28
- 0
lib/presentation/screens/plot_detail/bloc_plot_information.dart View File

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

class GetPlotInfoBloc {
final _repository = Repository();
final _getPlotInfoFetcher = PublishSubject<dynamic>();

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

void getPlotInfo(
int cropId, Function(dynamic) onSuccess, Function(String) onError) async {
_repository.getPlotDetail(cropId).then((value) {
onSuccess(value);
_getPlotInfoFetcher.sink.add(value);
}).catchError((onError) {
onError(AppException.handleError(onError));
_getPlotInfoFetcher.addError(AppException.handleError(onError));
});
}

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

final getPlotInfoBloc = GetPlotInfoBloc();

+ 11
- 0
lib/presentation/screens/plot_detail/sc_plot_detail.dart View File

import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_parameter.dart'; import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_parameter.dart';
import 'package:farm_tpf/utils/const_color.dart'; import 'package:farm_tpf/utils/const_color.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';


class PlotDetailScreen extends StatefulWidget { class PlotDetailScreen extends StatefulWidget {
final int cropId; final int cropId;
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
title: Text("Chi tiết lô"), title: Text("Chi tiết lô"),
actions: <Widget>[
IconButton(
icon: Icon(FontAwesomeIcons.infoCircle),
onPressed: () {
Get.to(PlotInformationScreen(
cropId: widget.cropId,
));
})
],
), ),
body: DefaultTabController( body: DefaultTabController(
length: 2, length: 2,

+ 170
- 69
lib/presentation/screens/plot_detail/sc_plot_information.dart View File

import 'package:farm_tpf/custom_model/CropPlot.dart';
import 'package:farm_tpf/models/index.dart'; import 'package:farm_tpf/models/index.dart';
import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
import 'package:farm_tpf/presentation/screens/plot_detail/bloc_plot_information.dart';
import 'package:farm_tpf/utils/const_color.dart'; import 'package:farm_tpf/utils/const_color.dart';
import 'package:farm_tpf/utils/const_string.dart';
import 'package:farm_tpf/utils/validators.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart'; import 'package:keyboard_dismisser/keyboard_dismisser.dart';
import 'package:farm_tpf/utils/formatter.dart';


class PlotInformationScreen extends StatefulWidget { class PlotInformationScreen extends StatefulWidget {
final int cropId;
final PlotCrop plot; final PlotCrop plot;
PlotInformationScreen({this.plot});
PlotInformationScreen({@required this.cropId, this.plot});
@override @override
_PlotInformationScreenState createState() => _PlotInformationScreenState(); _PlotInformationScreenState createState() => _PlotInformationScreenState();
} }
class _PlotInformationScreenState extends State<PlotInformationScreen> { class _PlotInformationScreenState extends State<PlotInformationScreen> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
GlobalKey<FormState> _formKey = GlobalKey(); GlobalKey<FormState> _formKey = GlobalKey();
TextEditingController _statusController = TextEditingController();
TextEditingController _houseNameController = TextEditingController();
TextEditingController _codeController = TextEditingController();
TextEditingController _supplyNameController = TextEditingController();
TextEditingController _seedingDateController = TextEditingController();
TextEditingController _timeSoakSeedController = TextEditingController();
TextEditingController _timeNurserySeedController = TextEditingController();
TextEditingController _quantityPlantController = TextEditingController();
TextEditingController _currentPlantController = TextEditingController();
TextEditingController _timeEndGrowController = TextEditingController();
TextEditingController _mainTechnicianController = TextEditingController();
TextEditingController _areaController = TextEditingController();
TextEditingController _descriptionController = TextEditingController();

bool _autoValidate = false; bool _autoValidate = false;
PlotCrop _plot = PlotCrop();
TbCropDTO _crop = TbCropDTO();
final controller = Get.put(DescriptionChangeControler());

@override
void initState() {
super.initState();
getPlotInfoBloc.getPlotInfo(widget.cropId, (data) {
var result = data as CropPlot;
_crop = result.tbCropDTO;
var statusCrop;
switch (_crop.status) {
case "STATUS_ARE_ACTIVE":
statusCrop = plot_status_active;
break;
case "STATUS_FINISHED":
statusCrop = plot_status_end;
break;
default:
statusCrop = plot_status_unknown;
}

_statusController.text = statusCrop;
_houseNameController.text = _crop.netHouseName.toString();
_codeController.text = _crop.code.toString();
_supplyNameController.text = _crop.suppliesName.toString();
_areaController.text = _crop.areaM2.formatNumtoStringDecimal();
_crop.description = "";
}, (err) {});
}


_validateInputs() async { _validateInputs() async {
if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {


Widget _statusField() { Widget _statusField() {
return TextFormField( return TextFormField(
controller: _statusController,
decoration: InputDecoration(labelText: "Trạng thái"), decoration: InputDecoration(labelText: "Trạng thái"),
); );
} }


Widget _houseNameField() { Widget _houseNameField() {
return TextFormField( return TextFormField(
controller: _houseNameController,
decoration: InputDecoration(labelText: "Nhà màng"), decoration: InputDecoration(labelText: "Nhà màng"),
); );
} }


Widget _codeField() { Widget _codeField() {
return TextFormField( return TextFormField(
controller: _codeController,
decoration: InputDecoration(labelText: "Mã lô"), decoration: InputDecoration(labelText: "Mã lô"),
); );
} }


Widget _supplyNameField() { Widget _supplyNameField() {
return TextFormField( return TextFormField(
controller: _supplyNameController,
decoration: InputDecoration(labelText: "Giống"), decoration: InputDecoration(labelText: "Giống"),
); );
} }


Widget _seedingDateField() { Widget _seedingDateField() {
return TextFormField( return TextFormField(
controller: _seedingDateController,
decoration: InputDecoration(labelText: "Ngày gieo trồng"), decoration: InputDecoration(labelText: "Ngày gieo trồng"),
); );
} }


Widget _timeSoakSeedField() { Widget _timeSoakSeedField() {
return TextFormField( return TextFormField(
controller: _timeSoakSeedController,
decoration: InputDecoration(labelText: "Thời gian ngâm hạt"), decoration: InputDecoration(labelText: "Thời gian ngâm hạt"),
); );
} }


Widget _timeNurserySeedField() { Widget _timeNurserySeedField() {
return TextFormField( return TextFormField(
controller: _timeNurserySeedController,
decoration: InputDecoration(labelText: "Thời gian vô khây ươm"), decoration: InputDecoration(labelText: "Thời gian vô khây ươm"),
); );
} }


Widget _quantityPlantField() { Widget _quantityPlantField() {
return TextFormField( return TextFormField(
controller: _quantityPlantController,
decoration: InputDecoration(labelText: "Số lượng cây trồng"), decoration: InputDecoration(labelText: "Số lượng cây trồng"),
); );
} }


Widget _currentPlantField() { Widget _currentPlantField() {
return TextFormField( return TextFormField(
controller: _currentPlantController,
decoration: InputDecoration(labelText: "Số lượng cây hiện tại"), decoration: InputDecoration(labelText: "Số lượng cây hiện tại"),
); );
} }


Widget _timeEndGrowField() { Widget _timeEndGrowField() {
return TextFormField( return TextFormField(
controller: _timeEndGrowController,
decoration: InputDecoration(labelText: "Ngày kết thúc canh tác"), decoration: InputDecoration(labelText: "Ngày kết thúc canh tác"),
); );
} }


Widget _mainTechnicianField() { Widget _mainTechnicianField() {
return TextFormField( return TextFormField(
controller: _mainTechnicianController,
decoration: InputDecoration(labelText: "Kỹ sư trực tiếp"), decoration: InputDecoration(labelText: "Kỹ sư trực tiếp"),
); );
} }


Widget _areaField() { Widget _areaField() {
return TextFormField( return TextFormField(
controller: _areaController,
decoration: InputDecoration(labelText: "Diện tích (m\u00B2)"), decoration: InputDecoration(labelText: "Diện tích (m\u00B2)"),
); );
} }


Widget _descriptionField() { Widget _descriptionField() {
return TextFormField( return TextFormField(
keyboardType: TextInputType.text,
controller: _descriptionController,
decoration: InputDecoration(labelText: "Ghi chú"), decoration: InputDecoration(labelText: "Ghi chú"),
onSaved: (newValue) {
_crop.description = newValue;
},
onChanged: (newValue) {
controller.changeValue(_crop.description, newValue);
},
); );
} }


_actionAppBar() { _actionAppBar() {
IconButton iconButton;
iconButton = IconButton(
icon: Icon(
Icons.done,
),
onPressed: () {},
);
return <Widget>[iconButton];
return <Widget>[
GetBuilder<DescriptionChangeControler>(
builder: (_) {
return IconButton(
icon: Icon(
Icons.done,
),
disabledColor: Colors.grey,
onPressed: controller.isChanged == false ? null : () {},
);
},
)
];
} }


@override @override
title: Text("Thông tin lô"), title: Text("Thông tin lô"),
actions: _actionAppBar()), actions: _actionAppBar()),
body: KeyboardDismisser( body: KeyboardDismisser(
child: Form(
key: _formKey,
autovalidate: _autoValidate,
child: SingleChildScrollView(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
_statusField(),
SizedBox(
height: 4.0,
),
_houseNameField(),
SizedBox(
height: 4.0,
),
_codeField(),
SizedBox(
height: 4.0,
),
_supplyNameField(),
SizedBox(
height: 4.0,
),
_seedingDateField(),
SizedBox(
height: 4.0,
),
_timeSoakSeedField(),
SizedBox(
height: 4.0,
),
_timeNurserySeedField(),
SizedBox(
height: 4.0,
),
_quantityPlantField(),
SizedBox(
height: 4.0,
),
_currentPlantField(),
SizedBox(
height: 4.0,
),
_timeEndGrowField(),
SizedBox(
height: 4.0,
),
_mainTechnicianField(),
SizedBox(
height: 4.0,
),
_areaField(),
SizedBox(
height: 4.0,
),
_descriptionField()
],
),
)))))));
child: StreamBuilder(
stream: getPlotInfoBloc.actions,
builder: (BuildContext context,
AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
return Form(
key: _formKey,
autovalidate: _autoValidate,
child: SingleChildScrollView(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
_statusField(),
SizedBox(
height: 4.0,
),
_houseNameField(),
SizedBox(
height: 4.0,
),
_codeField(),
SizedBox(
height: 4.0,
),
_supplyNameField(),
SizedBox(
height: 4.0,
),
_seedingDateField(),
SizedBox(
height: 4.0,
),
_timeSoakSeedField(),
SizedBox(
height: 4.0,
),
_timeNurserySeedField(),
SizedBox(
height: 4.0,
),
_quantityPlantField(),
SizedBox(
height: 4.0,
),
_currentPlantField(),
SizedBox(
height: 4.0,
),
_timeEndGrowField(),
SizedBox(
height: 4.0,
),
_mainTechnicianField(),
SizedBox(
height: 4.0,
),
_areaField(),
SizedBox(
height: 4.0,
),
_descriptionField()
],
),
));
} else if (snapshot.hasError) {
return Center(
child: Text(snapshot.error.toString()),
);
} else {
return LoadingListPage();
}
}))))));
}

class DescriptionChangeControler extends GetxController {
bool isChanged = false;

void changeValue(String oldValue, String newValue) {
if (oldValue != newValue) {
isChanged = true;
} else {
isChanged = false;
}
update();
}
} }

+ 3
- 0
lib/utils/const_string.dart View File

const String plot_action_finish = "Kết thúc canh tác"; const String plot_action_finish = "Kết thúc canh tác";


const String plot_detail_title = "Lịch sử canh tác"; const String plot_detail_title = "Lịch sử canh tác";
const String plot_status_active = "Đang canh tác";
const String plot_status_end = "Kết thúc canh tác";
const String plot_status_unknown = "Chưa canh tác";


//Common //Common



Loading…
Cancel
Save