Skip to content

Commit

Permalink
finished create planting module, news module seem fine too.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielChang98 committed Jan 9, 2021
1 parent bfa77a1 commit 5a2056c
Show file tree
Hide file tree
Showing 19 changed files with 530 additions and 118 deletions.
Binary file added assets/images/planting_view.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 fonts/weathericons-regular-webfont.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions lib/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class AppTheme {
static const Color background = Color(0xFFEEEFF4);
static const Color nearlyDarkGreen = Color(0xFF2EC821);
static const Color nearlyGreen = Color(0xFF24D900);
static const Color pastelGreen = Color(0xFF10d180);

static const Color notWhite = Color(0xFFEDF0F2);
static const Color nearlyWhite = Color(0xFFFEFEFE);
Expand Down
1 change: 1 addition & 0 deletions lib/data/farm/models/Forecast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Forecast {
var currentForcast = Weather(
cloudiness: int.parse(json['current']['clouds'].toString()),
temp: json['current']['temp'].toDouble(),
iconCode: weather['icon'],
condition: Weather.mapStringToWeatherCondition(
weather['main'], int.parse(json['current']['clouds'].toString())),
description: weather['description'],
Expand Down
6 changes: 3 additions & 3 deletions lib/data/farm/models/Planting.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Planting {
String _name;
int _noOfPlants;
DateTime _date;
String _date;
String _estimatedHarvest;
String _location;
String _fertilizers;
Expand Down Expand Up @@ -40,9 +40,9 @@ class Planting {
_estimatedHarvest = value;
}

DateTime get date => _date;
String get date => _date;

set date(DateTime value) {
set date(String value) {
_date = value;
}

Expand Down
1 change: 0 additions & 1 deletion lib/data/farm/models/Weather.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'package:farmassist/data/farm/utils/WeatherIconMapper.dart';
import 'package:flutter/material.dart';

Expand Down
32 changes: 28 additions & 4 deletions lib/data/farm/repositories/storeData.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:farmassist/data/farm/models/Planting.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:intl/intl.dart';


void addData(Map<String, dynamic> obj) {
String month = DateTime.now().month.toString().toLowerCase();
final FirebaseAuth auth = FirebaseAuth.instance;
final FirebaseFirestore db = FirebaseFirestore.instance;

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

DateTime dt = obj['plantDate'];
print(dt.month);

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

final DateFormat formatter = DateFormat('dd-MM-yyyy');
final String formatted = formatter.format(dt);

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

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

cr.doc().set(data);
Expand Down
8 changes: 6 additions & 2 deletions lib/data/farm/view_model/weather_app_forecast_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ForecastViewModel with ChangeNotifier {

WeatherCondition _condition;
String _description;
String _iconCode;
IconData _iconData;
double _minTemp;
double _maxTemp;
double _temp;
Expand All @@ -29,10 +31,11 @@ class ForecastViewModel with ChangeNotifier {
double _longitude;
List<Weather> _daily;
bool _isDayTime;
String _iconData;

WeatherCondition get condition => _condition;
IconData get iconData => getIconData(_iconCode);
String get description => _description;
String get iconCode => _iconCode;
double get minTemp => _minTemp;
double get maxTemp => _maxTemp;
double get temp => _temp;
Expand All @@ -44,7 +47,6 @@ class ForecastViewModel with ChangeNotifier {
double get latitide => _latitude;
bool get isDaytime => _isDayTime;
List<Weather> get daily => _daily;
String get iconData => _iconData;

ForecastService forecastService;

Expand Down Expand Up @@ -85,6 +87,8 @@ class ForecastViewModel with ChangeNotifier {

_condition = forecast.current.condition;
_city = forecast.city;
_iconCode = forecast.current.iconCode;

_description = Strings.toTitleCase(forecast.current.description);
_lastUpdated = forecast.lastUpdated;
_temp = TemperatureConvert.kelvinToCelsius(forecast.current.temp);
Expand Down
65 changes: 36 additions & 29 deletions lib/ui/farm/news/Widget/newsCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:farmassist/ui/farm/news_details/bloc/bloc.dart';
import 'package:farmassist/ui/widgets/news_customWidget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:farmassist/ui/farm/news_details/newsDetailPage.dart';
import 'package:page_transition/page_transition.dart';

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

Expand Down Expand Up @@ -37,7 +39,12 @@ class NewsCard extends StatelessWidget {
onTap: () {
BlocProvider.of<DetailBloc>(context)
.add(SelectNewsForDetail(article: artical));
Navigator.pushNamed(context, '/detail');
Navigator.push(
context,
PageTransition(
type: PageTransitionType.leftToRightWithFade,
child: NewsDetailPage()
));;
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20),
Expand All @@ -54,7 +61,7 @@ class NewsCard extends StatelessWidget {
fit: StackFit.expand,
children: <Widget>[
Container(
color: Theme.of(context).primaryColor,
color: Colors.grey,
child: artical.urlToImage == null ||
artical.urlToImage.isEmpty
? Container()
Expand All @@ -66,38 +73,38 @@ class NewsCard extends StatelessWidget {
SizedBox(width: 10),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SizedBox(),
Container(
height: 52,
child: Text(
artical.title,
style: Theme.of(context).textTheme.body1,
overflow: TextOverflow.fade,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
SizedBox(),
Container(
padding:
EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Theme.of(context).primaryColor,
),
height: 52,
child: Text(
'$type',
style: AppTheme.headline6.copyWith(
color: Theme.of(context).colorScheme.onPrimary),
artical.title,
style: Theme.of(context).textTheme.bodyText1,
overflow: TextOverflow.fade,
),
),
Container(
padding: EdgeInsets.only(left: 10),
child: Text(artical.getDateOnly(),
style: AppTheme.subtitle2),
),
],
Row(
children: <Widget>[
Container(
padding:
EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.black,
),
child: Text(
'$type',
style: AppTheme.headline6.copyWith(
color: Colors.white),
),
),
Container(
padding: EdgeInsets.only(left: 10),
child: Text(artical.getDateOnly(),
style: AppTheme.subtitle2),
),
],
)
],
))
Expand Down
7 changes: 3 additions & 4 deletions lib/ui/farm/news/news_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ class HomePage extends StatelessWidget {
title: Text(
'${type.toUpperCase()} NEWS',
style: AppTheme.headline5
.copyWith(color: Theme.of(context).colorScheme.primaryVariant),
.copyWith(color: Colors.black),
),
backgroundColor: Colors.white,
elevation: 10.0,
shadowColor: Colors.grey,
pinned: true,
),
SliverToBoxAdapter(
child: _headerNews(list.first),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => NewsCard(
Expand Down
64 changes: 25 additions & 39 deletions lib/ui/farm/news_details/newsDetailPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,9 @@ class NewsDetailPage extends StatelessWidget {
},
icon: Icon(
Icons.keyboard_backspace,
color: Theme.of(context).backgroundColor,
color: Colors.blueGrey,
),
),
Expanded(child: SizedBox()),
IconButton(
onPressed: () {},
icon: Icon(
Icons.favorite_border,
color: Theme.of(context).backgroundColor,
),
),
IconButton(
onPressed: () {},
icon: Icon(
Icons.share,
color: Theme.of(context).backgroundColor,
),
)
],
),
)
Expand All @@ -55,40 +40,41 @@ class NewsDetailPage extends StatelessWidget {
}

Widget _body(BuildContext context, Article article) {
print(article.content);
return CustomScrollView(
slivers: <Widget>[
SliverToBoxAdapter(
child: _headerNews(context, article),
),
SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10,
),
Text(article.title, style: AppTheme.headline4),
SizedBox(
height: 10,
),
Row(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(article.author ?? '', style: AppTheme.headline4),
SizedBox(
width: 10,
height: 10,
),
Text(article.title, style: AppTheme.headline5),
SizedBox(
height: 10,
),
Row(
children: <Widget>[
Text(article.author ?? '', style: AppTheme.subtitle2),
SizedBox(
width: 10,
),
Text(article.getTime(), style: AppTheme.subtitle2),
],
),
Text(article.getTime(), style: AppTheme.headline4),
Divider(
height: 20,
thickness: 1,
),
Text(article.content ?? '', style: AppTheme.bodyText1)
],
),
Divider(
height: 20,
thickness: 1,
),
Text(article.content ?? '', style: AppTheme.headline4)
],
),
))
],
);
Expand All @@ -97,7 +83,7 @@ class NewsDetailPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
backgroundColor: Colors.white,
body: SafeArea(child: BlocBuilder<DetailBloc, DetailState>(
builder: (context, state) {
if (state == null) {
Expand Down
Loading

0 comments on commit 5a2056c

Please sign in to comment.