Skip to content

Commit

Permalink
harvesting module done, left statistics module
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielChang98 committed Jan 10, 2021
1 parent 5a2056c commit b5cb3e3
Show file tree
Hide file tree
Showing 23 changed files with 1,198 additions and 103 deletions.
Binary file added assets/images/harvesting_create.jfif
Binary file not shown.
Binary file added assets/images/harvesting_create.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/harvesting_view.jfif
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/data/farm/models/Forecast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Forecast {
.map((item) => Weather.fromDailyJson(item))
.toList()
.skip(1)
.take(3)
.take(5)
.toList();
}

Expand Down
26 changes: 26 additions & 0 deletions lib/data/farm/models/Weather.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,30 @@ class Weather {

return condition;
}

IconData getIconData(String iconCode){
switch(iconCode){
case '01d': return WeatherIcons.clear_day;
case '01n': return WeatherIcons.clear_night;
case '02d': return WeatherIcons.few_clouds_day;
case '02n': return WeatherIcons.few_clouds_day;
case '03d':
case '04d':
return WeatherIcons.clouds_day;
case '03n':
case '04n':
return WeatherIcons.clear_night;
case '09d': return WeatherIcons.shower_rain_day;
case '09n': return WeatherIcons.shower_rain_night;
case '10d': return WeatherIcons.rain_day;
case '10n': return WeatherIcons.rain_night;
case '11d': return WeatherIcons.thunder_storm_day;
case '11n': return WeatherIcons.thunder_storm_night;
case '13d': return WeatherIcons.snow_day;
case '13n': return WeatherIcons.snow_night;
case '50d': return WeatherIcons.mist_day;
case '50n': return WeatherIcons.mist_night;
default: return WeatherIcons.clear_day;
}
}
}
63 changes: 63 additions & 0 deletions lib/data/farm/repositories/harvest_storeData.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:intl/intl.dart';

final FirebaseAuth auth = FirebaseAuth.instance;
final FirebaseFirestore db = FirebaseFirestore.instance;

User user = auth.currentUser;
final uid = user.uid;

void harvestData(Map<String, dynamic> obj){
var month;

DateTime harvestDt = obj['harvestDate'];
print(harvestDt.month);

if(harvestDt.month==1){
month="January";
}
else{
month="February";
}

final DateFormat formatter = DateFormat('dd-MM-yyyy');
final String harvestDate = formatter.format(harvestDt);


CollectionReference cr =
db.collection("Harvesting").doc(uid).collection(month);

Map<String, dynamic> data = {
"name": obj['plantName'],
"noOfPlants": obj['plantNumber'],
"date": obj['plantDate'],
"estimatedHarvest": obj['plantEstimated'],
"month": harvestDt.month,
"year": harvestDt.year,
"day": harvestDt.day,
"week": harvestDt.weekday,
"harvestQuantity": obj['harvestQuantity'],
"harvestDate": harvestDate,
};

cr.doc().set(data);
}

void updatePlanting(int monthInt, String id){
var month;

if(monthInt==1){
month="January";
}
else{
month="February";
}

CollectionReference cr =
db.collection("Planting").doc(uid).collection(month);

cr.doc(id).update({
"harvested": true
}).then((value) => print('success'));
}
11 changes: 11 additions & 0 deletions lib/data/farm/repositories/storeData.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ void addData(Map<String, dynamic> obj) {
User user = auth.currentUser;
final uid = user.uid;
var month;
double estimate;
DateTime futureDate;
int day;

DateTime dt = obj['plantDate'];
print(dt.month);
Expand All @@ -25,6 +28,12 @@ void addData(Map<String, dynamic> obj) {
final DateFormat formatter = DateFormat('dd-MM-yyyy');
final String formatted = formatter.format(dt);

estimate = obj['plantEstimated'];
day = estimate.round() * 7;
futureDate = dt.add(new Duration(days: day));
final String harvestDate = formatter.format(futureDate);


CollectionReference cr =
db.collection("Planting").doc(uid).collection(month);

Expand All @@ -37,6 +46,8 @@ void addData(Map<String, dynamic> obj) {
"year": dt.year,
"day": dt.day,
"week": dt.weekday,
"harvestDate": harvestDate,
"harvested": false,
};

cr.doc().set(data);
Expand Down
24 changes: 22 additions & 2 deletions lib/ui/farm/farm_menu.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:farmassist/ui/farm/harvesting/harvesting_menu.dart';
import 'package:farmassist/ui/farm/news/news_home.dart';
import 'package:farmassist/ui/farm/planting/planting_menu.dart';
import 'package:farmassist/ui/farm/statistics/statistics_home.dart';
import 'package:farmassist/ui/farm/weather/weatherHome.dart';
import 'package:flutter/material.dart';
import 'package:getwidget/colors/gf_color.dart';
Expand Down Expand Up @@ -45,7 +47,16 @@ class _FarmMenuState extends State<FarmMenu> {
titleText: 'Harvesting',
color: Colors.blueGrey[100],
subtitleText: 'Store and view harvesting related activities.',
icon: Icon(Icons.chevron_right)),
icon: Icon(Icons.chevron_right),
onTap: (){
Navigator.push(
context,
PageTransition(
type: PageTransitionType.leftToRightWithFade,
child: HarvestMenu()),
);
},
),
GFListTile(
avatar: GFAvatar(
backgroundImage: AssetImage('assets/images/manage_news.png'),
Expand Down Expand Up @@ -74,7 +85,16 @@ class _FarmMenuState extends State<FarmMenu> {
subtitleText:
'Numbers based on your planting and harvesting history.',
color: Colors.blueGrey[100],
icon: Icon(Icons.chevron_right)),
icon: Icon(Icons.chevron_right),
onTap: () {
Navigator.push(
context,
PageTransition(
type: PageTransitionType.leftToRightWithFade,
child: StatisticsHome()),
);
},
),
],
),
);
Expand Down
180 changes: 180 additions & 0 deletions lib/ui/farm/harvesting/display_harvesting.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import 'package:farmassist/data/farm/repositories/harvest_storeData.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:getwidget/components/appbar/gf_appbar.dart';
import 'package:getwidget/components/button/gf_icon_button.dart';
import 'package:getwidget/types/gf_button_type.dart';
import 'package:intl/intl.dart';

import '../../../app_theme.dart';

class DisplayHarvesting extends StatefulWidget {
final String documentID;
final String plantName;
final String plantNo;
final String plantDate;
final double plantEstimate;
final String plantHarvest;
final String plantQuantity;
final int plantMonth;

DisplayHarvesting({
this.documentID,
this.plantName,
this.plantNo,
this.plantDate,
this.plantEstimate,
this.plantHarvest,
this.plantMonth,
this.plantQuantity
});

@override
_DisplayHarvestingState createState() =>_DisplayHarvestingState(
name:plantName, no:plantNo, date:plantDate, estimate:plantEstimate, harvest: plantHarvest, id: documentID, month: plantMonth, quantity: plantQuantity,
);
}

class _DisplayHarvestingState extends State<DisplayHarvesting> {
final _formKey = GlobalKey<FormBuilderState>();

final String id;
final String name;
final String no;
final String date;
final double estimate;
final String harvest;
final int month;
final String quantity;

_DisplayHarvestingState({
this.id,
this.name,
this.no,
this.date,
this.estimate,
this.harvest,
this.month,
this.quantity
});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: GFAppBar(
leading: GFIconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.white,
),
onPressed: () {
Navigator.pop(context);
},
type: GFButtonType.transparent,
),
title: Text("View Harvesting Entry",
style: TextStyle(
color: AppTheme.nearlyWhite,
),),
backgroundColor: AppTheme.pastelGreen,
),
body: Container(
padding: EdgeInsets.all(5.0),
child: Column(
children: <Widget>[
new Expanded(
child: ListView(
padding: EdgeInsets.all(10.0),
children: <Widget>[
FormBuilder(
key: _formKey,
child: Column(
children: <Widget>[
FormBuilderTextField(
readOnly: true,
initialValue: name,
name: 'plantName',
decoration: InputDecoration(
labelText: "Plant Name",
icon: Icon(Icons.local_florist_outlined),
),
keyboardType: TextInputType.text,
),
SizedBox(height: 10),
FormBuilderTextField(
readOnly: true,
name: 'plantNumber',
initialValue: no,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "No. of Plants",
icon: Icon(Icons.format_list_numbered),
),
),
SizedBox(height: 10),
FormBuilderTextField(
readOnly: true,
name: 'plantDate',
initialValue: date,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Date',
icon: Icon(Icons.date_range),
),
),
SizedBox(height: 10),
FormBuilderSlider(
enabled: false,
name: 'plantEstimated',
validator: FormBuilderValidators.compose([
FormBuilderValidators.min(context, 1),
]),
min: 1.0,
max: 12.0,
initialValue: estimate,
divisions: 11,
label: 'Weeks',
activeColor: Colors.red,
inactiveColor: Colors.pink[100],
decoration: InputDecoration(
labelText: 'Estimated Harvest Date (weeks)',
icon: Icon(Icons.timelapse),
),
),
SizedBox(height: 10),
FormBuilderTextField(
name: 'harvestQuantity',
readOnly: true,
initialValue: quantity,
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(context),
]),
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Harvest Yield",
icon: Icon(Icons.format_list_numbered),
),
),
SizedBox(height: 10),
FormBuilderTextField(
name: 'harvestDate',
readOnly: true,
initialValue: harvest,
decoration: InputDecoration(
labelText: 'Harvest Date',
icon: Icon(Icons.date_range),
),
),
],
),
),
SizedBox(height: 20),
],
),
)
],
),
)
);
}
}
Loading

0 comments on commit b5cb3e3

Please sign in to comment.