From 7d6126fbbf9d8498f7f7f88990d51db1ee6b7372 Mon Sep 17 00:00:00 2001 From: Priggelpitt Date: Sat, 23 Nov 2019 19:57:50 +0100 Subject: [PATCH 1/2] Added new inspection support --- .../repositories/inspections_repository.dart | 17 + .../inspections_api_service.chopper.dart | 12 + .../inspections/inspections_api_service.dart | 6 + .../inspectionsender.dart | 3 + .../inspectionsender_bloc.dart | 69 +++ .../inspectionsender_event.dart | 61 ++ .../inspectionsender_state.dart | 28 + lib/main.dart | 4 + lib/screens/boxinfo_screen.dart | 6 + lib/screens/boxlist_screen.dart | 7 +- lib/screens/login_screen.dart | 8 +- lib/screens/newinspection_screen.dart | 576 ++++++++++-------- 12 files changed, 553 insertions(+), 244 deletions(-) create mode 100644 lib/blocs/inspectionsender_bloc/inspectionsender.dart create mode 100644 lib/blocs/inspectionsender_bloc/inspectionsender_bloc.dart create mode 100644 lib/blocs/inspectionsender_bloc/inspectionsender_event.dart create mode 100644 lib/blocs/inspectionsender_bloc/inspectionsender_state.dart diff --git a/lib/backend/repositories/inspections_repository.dart b/lib/backend/repositories/inspections_repository.dart index 51dfb24d..d6cd1041 100644 --- a/lib/backend/repositories/inspections_repository.dart +++ b/lib/backend/repositories/inspections_repository.dart @@ -159,4 +159,21 @@ class InspectionsRepository { return null; } } + + Future addNewInspection(Inspection inspection) async { + InspectionsApiService _inspectionsApi = + InspectionsApiService.create(_authBloc.domain); + var inspectionString = json.encode(inspection); + print(inspectionString); + final response = await _inspectionsApi.postNewInspection( + inspectionString, _authBloc.auth); + print(response.statusCode); + print(response.body); + if (response.statusCode == 201) { + final Map result = json.decode(response.body); + return Inspection.fromJson(result); + } else { + return null; + } + } } diff --git a/lib/backend/services/inspections/inspections_api_service.chopper.dart b/lib/backend/services/inspections/inspections_api_service.chopper.dart index 18ee8186..1e73613e 100644 --- a/lib/backend/services/inspections/inspections_api_service.chopper.dart +++ b/lib/backend/services/inspections/inspections_api_service.chopper.dart @@ -41,4 +41,16 @@ class _$InspectionsApiService extends InspectionsApiService { final $request = Request('GET', $url, client.baseUrl, headers: $headers); return client.send($request); } + + Future postNewInspection(String inspection, String authHeader) { + final $url = '/inspections'; + final $headers = { + 'Authorization': authHeader, + 'Content-Type': 'application/json' + }; + final $body = inspection; + final $request = + Request('POST', $url, client.baseUrl, body: $body, headers: $headers); + return client.send($request); + } } diff --git a/lib/backend/services/inspections/inspections_api_service.dart b/lib/backend/services/inspections/inspections_api_service.dart index 603c462c..4c3e00d5 100644 --- a/lib/backend/services/inspections/inspections_api_service.dart +++ b/lib/backend/services/inspections/inspections_api_service.dart @@ -29,6 +29,12 @@ abstract class InspectionsApiService extends ChopperService { @Header('Authorization') String authHeader, ]); + @Post(headers: {'Content-Type': 'application/json'}) + Future postNewInspection( + @Body() String inspection, + @Header('Authorization') String authHeader, + ); + static InspectionsApiService create(String url) { final client = ChopperClient( baseUrl: 'https://$url/api/v1', diff --git a/lib/blocs/inspectionsender_bloc/inspectionsender.dart b/lib/blocs/inspectionsender_bloc/inspectionsender.dart new file mode 100644 index 00000000..7d047b84 --- /dev/null +++ b/lib/blocs/inspectionsender_bloc/inspectionsender.dart @@ -0,0 +1,3 @@ +export 'inspectionsender_bloc.dart'; +export 'inspectionsender_event.dart'; +export 'inspectionsender_state.dart'; diff --git a/lib/blocs/inspectionsender_bloc/inspectionsender_bloc.dart b/lib/blocs/inspectionsender_bloc/inspectionsender_bloc.dart new file mode 100644 index 00000000..9a3ed704 --- /dev/null +++ b/lib/blocs/inspectionsender_bloc/inspectionsender_bloc.dart @@ -0,0 +1,69 @@ +import 'dart:async'; +import 'package:bloc/bloc.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:nesteo_app/backend/repositories/auth_repository.dart'; +import 'package:nesteo_app/backend/repositories/nestingboxes_repository.dart'; +import 'package:nesteo_app/backend/repositories/inspections_repository.dart'; +import 'package:nesteo_app/blocs/boxdata_bloc/boxdata.dart'; +import 'package:nesteo_app/model/inspection.dart'; +import 'package:nesteo_app/model/nestingbox.dart'; +import 'package:nesteo_app/model/owner.dart'; +import 'package:nesteo_app/model/region.dart'; +import 'package:nesteo_app/model/species.dart'; +import 'package:nesteo_app/model/user.dart'; +import './inspectionsender.dart'; + +class InspectionSenderBloc + extends Bloc { + @override + InspectionSenderState get initialState => WaitingForSend(); + + @override + Stream mapEventToState( + InspectionSenderEvent event, + ) async* { + if (event is SendInspectionEvent && state is WaitingForSend) { + yield SendingInspectionState(); + var inspRepo = InspectionsRepository(event.authBloc); + var authRepo = AuthRepository(event.authBloc); + + User user = await authRepo.getAuth(); + + Inspection response = await inspRepo.addNewInspection( + Inspection( + ageInDays: event.ageInDays, + chickCount: event.chickCount, + comment: event.comment, + condition: event.condition, + containsEggs: event.containsEggs, + eggCount: event.eggCount, + femaleParentBirdDiscovery: event.femaleParent, + maleParentBirdDiscovery: event.maleParent, + hasBeenCleaned: event.cleaned, + inspectedByUser: user, + id: null, + inspectionDate: event.inspectionDate, + justRepaired: event.repaired, + nestingBox: event.nestingBox, + nestingBoxId: event.nestingBox.id, + occupied: event.occupied, + ringedChickCount: event.ringedChickCount, + species: (event.speciesString != null) + ? Species(id: null, name: event.speciesString) + : event.species, + hasImage: null, + lastUpdated: null, + ), + ); + + if (response != null) { + yield InspectionSentState(); + } else { + yield SendErrorState(); + } + } + if (event is NewInspectionDoneEvent) { + yield WaitingForSend(); + } + } +} diff --git a/lib/blocs/inspectionsender_bloc/inspectionsender_event.dart b/lib/blocs/inspectionsender_bloc/inspectionsender_event.dart new file mode 100644 index 00000000..ec99b088 --- /dev/null +++ b/lib/blocs/inspectionsender_bloc/inspectionsender_event.dart @@ -0,0 +1,61 @@ +import 'package:equatable/equatable.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; +import 'package:nesteo_app/blocs/authentication_bloc/authentication_bloc.dart'; +import 'package:nesteo_app/model/nestingbox.dart'; +import 'package:nesteo_app/model/owner.dart'; +import 'package:nesteo_app/model/region.dart'; +import 'package:nesteo_app/model/species.dart'; + +abstract class InspectionSenderEvent extends Equatable { + const InspectionSenderEvent(); +} + +class NewInspectionDoneEvent extends InspectionSenderEvent { + @override + List get props => null; +} + +class SendInspectionEvent extends InspectionSenderEvent { + final AuthenticationBloc authBloc; + final NestingBox nestingBox; + final String id; + final DateTime inspectionDate; + final String comment; + final bool cleaned; + final bool repaired; + final String condition; + final bool containsEggs; + final int eggCount; + final bool occupied; + final int chickCount; + final int ringedChickCount; + final int ageInDays; + final String femaleParent; + final String maleParent; + final Species species; + final String speciesString; + + SendInspectionEvent( + {this.id, + this.nestingBox, + this.authBloc, + this.inspectionDate, + this.comment, + this.cleaned, + this.repaired, + this.condition, + this.containsEggs, + this.eggCount, + this.occupied, + this.chickCount, + this.ringedChickCount, + this.ageInDays, + this.femaleParent, + this.maleParent, + this.species, + this.speciesString}) + : super(); + + @override + List get props => null; +} diff --git a/lib/blocs/inspectionsender_bloc/inspectionsender_state.dart b/lib/blocs/inspectionsender_bloc/inspectionsender_state.dart new file mode 100644 index 00000000..8a5c300b --- /dev/null +++ b/lib/blocs/inspectionsender_bloc/inspectionsender_state.dart @@ -0,0 +1,28 @@ +import 'package:equatable/equatable.dart'; + +abstract class InspectionSenderState extends Equatable { + const InspectionSenderState(); +} + +class WaitingForSend extends InspectionSenderState { + @override + List get props => []; +} + +class SendingInspectionState extends InspectionSenderState { + @override + // TODO: implement props + List get props => null; +} + +class InspectionSentState extends InspectionSenderState { + @override + // TODO: implement props + List get props => null; +} + +class SendErrorState extends InspectionSenderState { + @override + // TODO: implement props + List get props => null; +} diff --git a/lib/main.dart b/lib/main.dart index 80b8bca5..2a48bebc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:nesteo_app/blocs/authentication_bloc/authentication_bloc.dart'; import 'package:nesteo_app/blocs/authentication_bloc/authentication_event.dart'; import 'package:nesteo_app/blocs/boxsender_bloc/boxsender.dart'; import 'package:nesteo_app/blocs/dropdown_bloc/dropdown_bloc.dart'; +import 'package:nesteo_app/blocs/inspectionsender_bloc/inspectionsender_bloc.dart'; import 'package:nesteo_app/blocs/mapcontrol_bloc/mapcontrol.dart'; import 'package:nesteo_app/blocs/pagecontrol_bloc/pagecontrol.dart'; import 'package:nesteo_app/blocs/snackbar_bloc/snackbar.dart'; @@ -55,6 +56,9 @@ class MyApp extends StatelessWidget { BlocProvider( builder: (BuildContext context) => BoxSenderBloc(), ), + BlocProvider( + builder: (BuildContext context) => InspectionSenderBloc(), + ), BlocProvider( builder: (BuildContext context) => DropdownBloc(), ), diff --git a/lib/screens/boxinfo_screen.dart b/lib/screens/boxinfo_screen.dart index 31ad811e..133ece03 100644 --- a/lib/screens/boxinfo_screen.dart +++ b/lib/screens/boxinfo_screen.dart @@ -7,6 +7,8 @@ import 'package:nesteo_app/blocs/inspectiondata_bloc/inspectiondata.dart'; import 'package:nesteo_app/model/nestingbox.dart'; import 'package:nesteo_app/screens/nesteo_screen.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:nesteo_app/blocs/dropdown_bloc/dropdown.dart'; +import 'package:nesteo_app/blocs/authentication_bloc/authentication.dart'; import 'package:nesteo_app/blocs/pagecontrol_bloc/pagecontrol.dart'; import 'package:nesteo_app/generated/locale_base.dart'; import 'package:nesteo_app/blocs/snackbar_bloc/snackbar.dart'; @@ -55,6 +57,10 @@ class BoxInfoScreen extends NesteoFullScreen { label: Text(loc.boxInfo.newInspection, style: TextStyle(fontSize: 16)), onPressed: () { + BlocProvider.of(context).add( + UpdateSpeciesEvent( + authBloc: + BlocProvider.of(context))); pageControlBloc.add(GoToNewInspectionEvent()); }, ), diff --git a/lib/screens/boxlist_screen.dart b/lib/screens/boxlist_screen.dart index ad11e6a2..146071b5 100644 --- a/lib/screens/boxlist_screen.dart +++ b/lib/screens/boxlist_screen.dart @@ -4,7 +4,8 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:nesteo_app/blocs/boxdata_bloc/boxdata.dart'; import 'package:nesteo_app/blocs/mapcontrol_bloc/mapcontrol.dart'; import 'package:nesteo_app/blocs/pagecontrol_bloc/pagecontrol.dart'; -import 'package:nesteo_app/blocs/snackbar_bloc/snackbar.dart'; +import 'package:nesteo_app/blocs/dropdown_bloc/dropdown.dart'; +import 'package:nesteo_app/blocs/authentication_bloc/authentication.dart'; import 'package:nesteo_app/screens/nesteo_screen.dart'; import 'package:nesteo_app/generated/locale_base.dart'; @@ -18,6 +19,8 @@ class BoxListScreen extends NesteoFramedScreen { appBarLeading: null, floatingActionButton: FloatingActionButton( onPressed: () { + BlocProvider.of(context).add(UpdateAllEvent( + authBloc: BlocProvider.of(context))); BlocProvider.of(context).add(GoToNewBoxEvent()); }, child: Icon(Icons.add), @@ -73,7 +76,7 @@ class BoxListScreen extends NesteoFramedScreen { color: Color.lerp( Colors.white, Colors.red, - log(daysSinceLastInspection / 330), + log((daysSinceLastInspection + 1) / 330), ), child: ListTile( leading: (daysSinceLastInspection > 300) diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart index e0cb207b..98a3efbd 100644 --- a/lib/screens/login_screen.dart +++ b/lib/screens/login_screen.dart @@ -124,9 +124,11 @@ class _LoginScreenDataState extends State { : state is NotAuthenticatedState ? Colors.red : Colors.green, - onPressed: () { - authBloc.add(CheckNewAuthenticationEvent()); - }, + onPressed: (state is AuthenticatingState) + ? null + : () { + authBloc.add(CheckNewAuthenticationEvent()); + }, child: Text( loc.login.logInButton, style: TextStyle( diff --git a/lib/screens/newinspection_screen.dart b/lib/screens/newinspection_screen.dart index 872a527f..94736fa8 100644 --- a/lib/screens/newinspection_screen.dart +++ b/lib/screens/newinspection_screen.dart @@ -1,7 +1,18 @@ import 'package:datetime_picker_formfield/datetime_picker_formfield.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; +import 'package:nesteo_app/blocs/authentication_bloc/authentication_bloc.dart'; +import 'package:nesteo_app/blocs/boxdata_bloc/boxdata.dart'; +import 'package:nesteo_app/blocs/dropdown_bloc/dropdown.dart'; +import 'package:nesteo_app/blocs/inspectiondata_bloc/inspectiondata.dart'; +import 'package:nesteo_app/blocs/inspectionsender_bloc/inspectionsender.dart'; +import 'package:nesteo_app/blocs/inspectionsender_bloc/inspectionsender_bloc.dart'; +import 'package:nesteo_app/blocs/inspectionsender_bloc/inspectionsender_event.dart'; +import 'package:nesteo_app/blocs/pagecontrol_bloc/pagecontrol.dart'; +import 'package:nesteo_app/model/inspection.dart'; +import 'package:nesteo_app/model/species.dart'; import 'package:nesteo_app/screens/nesteo_screen.dart'; import 'package:nesteo_app/generated/locale_base.dart'; @@ -36,7 +47,7 @@ class _NewInspectionDataState extends State { DateTime _inspectionDate; bool _hasBeenCleaned = false; bool _justRepaired = false; - String _condition; + String _condition = "Good"; bool _occupied = false; bool _containsEggs = false; String _femaleParent = "None"; @@ -48,298 +59,385 @@ class _NewInspectionDataState extends State { String _comment; double _sliderCondition = 2; Color sliderColor; + String _speciesString; + Species _species; Widget build(BuildContext context) { final loc = Localizations.of(context, LocaleBase); + final dropdownBloc = BlocProvider.of(context); - return ListView(children: [ - Card( - child: ListTile( - title: Row(children: [ - Icon(FontAwesomeIcons.calendarAlt), - Padding(padding: EdgeInsets.fromLTRB(0, 20, 10, 10)), - Text("Date"), - ]), - subtitle: Padding( - padding: EdgeInsets.fromLTRB(0, 10, 0, 10), - child: DateTimePickerFormField( - decoration: InputDecoration( - labelText: "select Day", - filled: true, - fillColor: Colors.white, + return ListView( + children: [ + Card( + child: ListTile( + title: Row(children: [ + Icon(FontAwesomeIcons.calendarAlt), + Padding(padding: EdgeInsets.fromLTRB(0, 20, 10, 10)), + Text("Date"), + ]), + subtitle: Padding( + padding: EdgeInsets.fromLTRB(0, 10, 0, 10), + child: DateTimePickerFormField( + decoration: InputDecoration( + labelText: "select Day", + filled: true, + fillColor: Colors.white, + ), + inputType: InputType.date, + format: DateFormat("yyyy-MM-dd"), + initialDate: DateTime.now(), + editable: false, + onChanged: (dt) { + setState(() => _inspectionDate = dt); + }, ), - inputType: InputType.date, - format: DateFormat("yyyy-MM-dd"), - initialDate: DateTime.now(), - editable: false, - onChanged: (dt) { - setState(() => _inspectionDate = dt); - }, ), ), ), - ), - Card( - child: Container( - child: Column( - children: [ - ListTile( - title: Row(children: [ - Icon(FontAwesomeIcons.tools), - Padding( + Card( + child: Container( + child: Column( + children: [ + ListTile( + title: Row(children: [ + Icon(FontAwesomeIcons.tools), + Padding( + padding: EdgeInsets.fromLTRB(10, 10, 10, 10), + child: Text("Box")), + ]), + ), + CheckboxListTile( + title: Text(loc.boxInfo.cleaned), + value: _hasBeenCleaned, + onChanged: (bool newValue) { + setState(() { + _hasBeenCleaned = newValue; + }); + }), + CheckboxListTile( + title: Text(loc.boxInfo.repair), + value: _justRepaired, + onChanged: (bool newValue) { + setState(() { + _justRepaired = newValue; + }); + }), + ListTile( + title: Row( + children: [ + Expanded(child: Text(loc.boxInfo.boxCondition)), + Slider( + value: _sliderCondition, + label: getSliderLabel(_sliderCondition), + activeColor: sliderColor, + min: 0, + max: 2, + divisions: 2, + onChanged: (double newValue) { + setState(() { + _sliderCondition = newValue; + _condition = getSliderLabel(_sliderCondition); + }); + }, + ), + ], + )), + ], + ), + ), + ), + Card( + child: Container( + child: Column( + children: [ + ListTile( + title: Row(children: [ + Icon(FontAwesomeIcons.egg), + Padding( padding: EdgeInsets.fromLTRB(10, 10, 10, 10), - child: Text("Box")), - ]), - ), - CheckboxListTile( - title: Text(loc.boxInfo.cleaned), - value: _hasBeenCleaned, - onChanged: (bool newValue) { - setState(() { - _hasBeenCleaned = newValue; - }); - }), - CheckboxListTile( - title: Text(loc.boxInfo.repair), - value: _justRepaired, - onChanged: (bool newValue) { - setState(() { - _justRepaired = newValue; - }); - }), - ListTile( - title: Row( - children: [ - Expanded(child: Text(loc.boxInfo.boxCondition)), - Slider( - value: _sliderCondition, - label: getSliderLabel(_sliderCondition), - activeColor: sliderColor, - min: 0, - max: 2, - divisions: 2, - onChanged: (double newValue) { + child: Text("Eggs"), + ) + ]), + ), + CheckboxListTile( + title: Text(loc.boxInfo.containsEggs), + value: _containsEggs, + onChanged: (bool newValue) { setState(() { - _sliderCondition = newValue; - _condition = getSliderLabel(_sliderCondition); + _containsEggs = newValue; }); - }, + }), + ListTile( + title: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(loc.boxInfo.eggCount), + Row( + children: [ + IconButton( + icon: new Icon(Icons.remove), + onPressed: (_eggCount > 0) + ? () => setState(() => _eggCount--) + : null, + ), + Text(_eggCount.toString()), + IconButton( + icon: new Icon(Icons.add), + onPressed: () => setState(() => _eggCount++)) + ], + ), + ], ), - ], - )), - ], + ), + ], + ), ), ), - ), - Card( - child: Container( - child: Column( - children: [ + Card( + child: Container( + child: Column(children: [ ListTile( title: Row(children: [ - Icon(FontAwesomeIcons.egg), + Icon(FontAwesomeIcons.kiwiBird), Padding( padding: EdgeInsets.fromLTRB(10, 10, 10, 10), - child: Text("Eggs"), + child: Text("Birds"), ) ]), ), CheckboxListTile( - title: Text(loc.boxInfo.containsEggs), - value: _containsEggs, + title: Text(loc.boxInfo.occupied), + value: _occupied, onChanged: (bool newValue) { setState(() { - _containsEggs = newValue; + _occupied = newValue; }); }), ListTile( title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text(loc.boxInfo.eggCount), + Text(loc.boxInfo.chickCount), Row( children: [ IconButton( icon: new Icon(Icons.remove), - onPressed: (_eggCount > 0) - ? () => setState(() => _eggCount--) + onPressed: (_chickCount > 0) + ? () => setState(() => _chickCount--) : null, ), - Text(_eggCount.toString()), + Text(_chickCount.toString()), IconButton( icon: new Icon(Icons.add), - onPressed: () => setState(() => _eggCount++)) + onPressed: () => setState(() => _chickCount++)) ], ), ], ), ), - ], - ), - ), - ), - Card( - child: Container( - child: Column(children: [ - ListTile( - title: Row(children: [ - Icon(FontAwesomeIcons.kiwiBird), - Padding( - padding: EdgeInsets.fromLTRB(10, 10, 10, 10), - child: Text("Birds"), - ) - ]), - ), - CheckboxListTile( - title: Text(loc.boxInfo.occupied), - value: _occupied, - onChanged: (bool newValue) { - setState(() { - _occupied = newValue; - }); - }), - ListTile( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(loc.boxInfo.chickCount), - Row( - children: [ - IconButton( - icon: new Icon(Icons.remove), - onPressed: (_chickCount > 0) - ? () => setState(() => _chickCount--) - : null, - ), - Text(_chickCount.toString()), - IconButton( - icon: new Icon(Icons.add), - onPressed: () => setState(() => _chickCount++)) - ], - ), - ], - ), - ), - ListTile( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(loc.boxInfo.ringed), - Row( - children: [ - IconButton( - icon: new Icon(Icons.remove), - onPressed: (_ringedChickCount > 0) - ? () => setState(() => _ringedChickCount--) - : null, - ), - Text(_ringedChickCount.toString()), - IconButton( - icon: new Icon(Icons.add), - onPressed: () => setState(() => _ringedChickCount++)) - ], - ), - ], + ListTile( + title: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(loc.boxInfo.ringed), + Row( + children: [ + IconButton( + icon: new Icon(Icons.remove), + onPressed: (_ringedChickCount > 0) + ? () => setState(() => _ringedChickCount--) + : null, + ), + Text(_ringedChickCount.toString()), + IconButton( + icon: new Icon(Icons.add), + onPressed: () => + setState(() => _ringedChickCount++)) + ], + ), + ], + ), ), - ), - ListTile( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(loc.boxInfo.chickAge), - Row( - children: [ - IconButton( - icon: new Icon(Icons.remove), - onPressed: (_ageInDays > 0) - ? () => setState(() => _ageInDays--) - : null, - ), - Text(_ageInDays.toString()), - IconButton( - icon: new Icon(Icons.add), - onPressed: () => setState(() => _ageInDays++)) - ], - ), - ], + ListTile( + title: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(loc.boxInfo.chickAge), + Row( + children: [ + IconButton( + icon: new Icon(Icons.remove), + onPressed: (_ageInDays > 0) + ? () => setState(() => _ageInDays--) + : null, + ), + Text(_ageInDays.toString()), + IconButton( + icon: new Icon(Icons.add), + onPressed: () => setState(() => _ageInDays++)) + ], + ), + ], + ), ), - ), - ListTile( - title: Row( - children: [ - Expanded( - child: Text(loc.boxInfo.femaleInBox), - ), - _createFemaleParentBirdSelection(context) - ], + ListTile( + title: Row( + children: [ + Expanded( + child: Text(loc.boxInfo.femaleInBox), + ), + _createFemaleParentBirdSelection(context) + ], + ), ), - ), - ListTile( - title: Row( - children: [ - Expanded( - child: Text(loc.boxInfo.femaleInBox), - ), - _createMaleParentBirdSelection(context) - ], + ListTile( + title: Row( + children: [ + Expanded( + child: Text(loc.boxInfo.femaleInBox), + ), + _createMaleParentBirdSelection(context) + ], + ), ), - ), - ListTile( - title: Text(loc.boxInfo.specie), - subtitle: Column( - children: [ - TextFormField( - maxLines: 1, - maxLength: 1, - textAlign: TextAlign.left, - decoration: InputDecoration( - labelText: "New Species", - filled: true, - fillColor: Colors.white, + ListTile( + subtitle: Column( + children: [ + BlocBuilder( + builder: (context, state) { + if (state is ReadyDropdownState) { + if (_species == null) + _species = dropdownBloc.species[0]; + return DropdownButton( + isExpanded: true, + value: (_species != null) + ? dropdownBloc.species + .indexOf(_species) + .toString() + : "0", + icon: Icon(Icons.arrow_drop_down), + iconSize: 24, + onChanged: (String newValue) { + setState(() { + print(newValue); + _species = + dropdownBloc.species[int.parse(newValue)]; + }); + }, + items: dropdownBloc.species + .map>( + (Species value) { + return DropdownMenuItem( + value: dropdownBloc.species + .indexOf(value) + .toString(), + child: Text("${value.name}"), + ); + }, + ).toList(), + ); + } else { + return CircularProgressIndicator(); + } + }, ), - ), - ], + TextFormField( + maxLines: 1, + maxLength: 1, + textAlign: TextAlign.left, + decoration: InputDecoration( + labelText: "New Species", + filled: true, + fillColor: Colors.white, + ), + ), + ], + ), ), - ), - ]), - ), - ), - Card( - child: ListTile( - title: Row( - children: [ - Icon(FontAwesomeIcons.comment), - Padding( - padding: EdgeInsets.fromLTRB(10, 10, 10, 10), - child: Text("Comment")) - ], - ), - subtitle: TextFormField( - maxLines: 3, - textAlign: TextAlign.left, - onChanged: (String value) { - setState(() { - _comment = value; - }); - }, + ]), ), ), - ), - Padding( - padding: EdgeInsets.fromLTRB(60, 0, 60, 0), - child: RaisedButton( - color: Colors.blue, - onPressed: () {}, - child: Text( - "Send", - style: TextStyle( - fontSize: 20, - color: Colors.white, + Card( + child: ListTile( + title: Row( + children: [ + Icon(FontAwesomeIcons.comment), + Padding( + padding: EdgeInsets.fromLTRB(10, 10, 10, 10), + child: Text("Comment")) + ], + ), + subtitle: TextFormField( + maxLines: 3, + textAlign: TextAlign.left, + onChanged: (String value) { + setState(() { + _comment = value; + }); + }, ), ), ), - ), - ]); + Padding( + padding: EdgeInsets.fromLTRB(60, 0, 60, 0), + child: BlocBuilder( + builder: (context, state) { + if (state is WaitingForSend) { + return RaisedButton( + color: Colors.blue, + onPressed: () { + BlocProvider.of(context).add( + SendInspectionEvent( + ageInDays: _ageInDays, + nestingBox: + BlocProvider.of(context).nestingBox, + authBloc: BlocProvider.of(context), + chickCount: _chickCount, + cleaned: _hasBeenCleaned, + comment: _comment, + condition: _condition, + containsEggs: _containsEggs, + eggCount: _eggCount, + femaleParent: _femaleParent, + maleParent: _maleParent, + id: null, + inspectionDate: (_inspectionDate == null) + ? DateTime.now() + : _inspectionDate, + occupied: _occupied, + repaired: _justRepaired, + ringedChickCount: _ringedChickCount, + species: _species, + speciesString: _speciesString, + ), + ); + }, + child: Text( + "Create new Inspection", + style: TextStyle( + fontSize: 20, + color: Colors.white, + ), + ), + ); + } + if (state is InspectionSentState) { + BlocProvider.of(context) + .add(GetInspectionPreviewsByNestingBoxEvent()); + BlocProvider.of(context).add(GetBoxEvent()); + BlocProvider.of(context) + .add(NewInspectionDoneEvent()); + BlocProvider.of(context) + .add(BackButtonEvent()); + BlocProvider.of(context) + .add(GoToInspectionListEvent()); + } + return Container(); + }, + ), + ), + ], + ); } String getSliderLabel(double value) { From d94dcec470ecfdb81643c7e45faed4d72d8014cd Mon Sep 17 00:00:00 2001 From: Priggelpitt Date: Sat, 23 Nov 2019 20:00:01 +0100 Subject: [PATCH 2/2] Resolves #148 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index ff161835..1337ee16 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: nesteo_app description: Nesting box management app for ringing associations. -version: 0.5.1+22 +version: 0.5.3+23 environment: sdk: ">=2.1.0 <3.0.0"