Skip to content

Commit c33d2f4

Browse files
committed
added profile page and updation of data and water add modal
1 parent cb74831 commit c33d2f4

26 files changed

+844
-218
lines changed

assets/icons/01.png

10.2 KB
Loading

assets/icons/02.png

13.3 KB
Loading

assets/icons/025-sun.png

-31 KB
Binary file not shown.

assets/icons/03.png

8.15 KB
Loading

assets/icons/04.png

13.3 KB
Loading

assets/icons/09.png

13.2 KB
Loading

assets/icons/10.png

16.5 KB
Loading

assets/icons/11.png

12.7 KB
Loading

assets/icons/13.png

20.9 KB
Loading

assets/icons/50.png

11.5 KB
Loading

assets/images/profile.jpg

-620 KB
Binary file not shown.

lib/main.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:drinkable/screens/add_water_screen.dart';
12
import 'package:drinkable/screens/data_entry_screen.dart';
23
import 'package:flutter/material.dart';
34
import 'package:flutter/services.dart';
@@ -22,10 +23,10 @@ void main() async {
2223
DeviceOrientation.portraitUp
2324
]
2425
);
25-
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
26-
statusBarColor: Colors.transparent,
27-
statusBarIconBrightness: Brightness.dark,
28-
));
26+
// SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
27+
// statusBarColor: Colors.transparent,
28+
// statusBarIconBrightness: Brightness.dark,
29+
// ));
2930
runApp(MyApp());
3031
}
3132

@@ -49,6 +50,11 @@ class MyApp extends StatelessWidget {
4950
theme: ThemeData(
5051
primarySwatch: Colors.blue,
5152
visualDensity: VisualDensity.adaptivePlatformDensity,
53+
pageTransitionsTheme: PageTransitionsTheme(
54+
builders: {
55+
TargetPlatform.android : CupertinoPageTransitionsBuilder()
56+
}
57+
)
5258
),
5359
//home: HomeScreen(),
5460
//home: CustomDrawer(),
@@ -59,7 +65,8 @@ class MyApp extends StatelessWidget {
5965
// '/' : (ctx)=>OnboardScreen(),
6066
DataEntryScreen.routeName : (ctx)=>DataEntryScreen(),
6167
// AuthScreen.routeName : (ctx)=>AuthScreen(),
62-
// CustomDrawer.routeName : (ctx)=>CustomDrawer()
68+
// CustomDrawer.routeName : (ctx)=>CustomDrawer(),
69+
AddWaterScreen.routeName : (ctx)=>AddWaterScreen()
6370
},
6471
),
6572
);

lib/models/app_user.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ class AppUser {
2727
factory AppUser.fromDoc(Map<String,dynamic> doc){
2828
return AppUser(
2929
uid: doc['uid'],
30+
googleId: doc['google_id'],
31+
email: doc['email'],
3032
name: doc['name'],
33+
gender: doc['gender'],
34+
birthday: (doc['birthday'] as Timestamp).toDate(),
35+
weight: doc['weight'],
36+
wakeUpTime: TimeOfDay(
37+
hour: doc['wake_up_time']['hour'],
38+
minute: doc['wake_up_time']['minute']
39+
),
3140
dailyTarget: doc['daily_target']
3241
);
3342
}

lib/providers/home_provider.dart

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ class HomeProvider extends ChangeNotifier {
2222
DocumentReference _userRef;
2323
DocumentReference _currentWeek;
2424
Location _location = Location();
25-
Map<String,dynamic> weather;
26-
27-
// HomeProvider(){
28-
// _weekColRef = _firebaseFirestore.collection('users').doc(_uid).collection('week');
29-
// _userRef = _firebaseFirestore.collection('users').doc(_uid);
30-
// }
25+
Map<String,dynamic> _weather;
26+
LocationData _locationData;
3127

3228
void update(User user){
3329
print('Updating user in home provider');
@@ -36,6 +32,7 @@ class HomeProvider extends ChangeNotifier {
3632
_weekColRef = _firebaseFirestore.collection('users').doc(_uid).collection('weeks');
3733
_userRef = _firebaseFirestore.collection('users').doc(_uid);
3834
}else{
35+
_isInited = false;
3936
_uid = null;
4037
_appUser = null;
4138
_weekColRef = null;
@@ -44,6 +41,10 @@ class HomeProvider extends ChangeNotifier {
4441
notifyListeners();
4542
}
4643

44+
Map<String,dynamic> get weather {
45+
return _weather;
46+
}
47+
4748
String get dailyTarget {
4849
int target = _appUser.dailyTarget;
4950
if(target<1000){
@@ -71,6 +72,8 @@ class HomeProvider extends ChangeNotifier {
7172
return consumed/target;
7273
}
7374

75+
AppUser get appUser => _appUser;
76+
7477
Future<void> init()async{
7578
if(_isInited==false){
7679
try {
@@ -88,17 +91,21 @@ class HomeProvider extends ChangeNotifier {
8891
_weeklyData = WeeklyData.fromDoc(snapshot.data());
8992
}
9093
_isInited = true;
94+
bool canGetLocation = await getLocationService();
95+
print(canGetLocation);
96+
if(canGetLocation){
97+
_locationData = await _location.getLocation();
98+
print(_locationData.latitude);
99+
print(_locationData.longitude);
100+
http.Response response = await http.get(
101+
'https://api.openweathermap.org/data/2.5/weather?lat=${_locationData.latitude}&lon=${_locationData.longitude}&appid=5c079888a15f3da50f160e44ce22723e&units=metric'
102+
);
103+
if(response.statusCode==200){
104+
final weatherInfo = jsonDecode(response.body);
105+
_weather = weatherInfo['weather'][0];
106+
}
107+
}
91108
notifyListeners();
92-
// LocationData _locationData = await _location.getLocation();
93-
// print(_locationData.latitude);
94-
// print(_locationData.longitude);
95-
// http.Response response = await http.get(
96-
// 'https://api.openweathermap.org/data/2.5/weather?lat=${_locationData.latitude}&lon=${_locationData.longitude}&appid=5c079888a15f3da50f160e44ce22723e&units=metric'
97-
// );
98-
// if(response.statusCode==200){
99-
// final weatherInfo = jsonDecode(response.body);
100-
// print(weatherInfo['main']);
101-
// }
102109
}catch(e){
103110
print(e);
104111
}
@@ -107,49 +114,64 @@ class HomeProvider extends ChangeNotifier {
107114
}
108115
}
109116

110-
Future<void> addWater(int amount) async {
117+
Future<void> addWater(int amount,DateTime time) async {
111118
try{
112-
int weekday = DateTime.now().weekday;
119+
int weekday = time.weekday;
120+
int week = getWeek(time);
121+
String weekId = '${time.year}_$week';
113122
_firebaseFirestore.runTransaction((transaction)async{
114-
DocumentReference yearDocRef = _firebaseFirestore.collection('users').doc(_uid).collection('years').doc('${_today.year}');
115-
DocumentReference monthDocRef = _firebaseFirestore.collection('users').doc(_uid).collection('months').doc('${_today.year}_${_today.month}');
123+
DocumentReference weekDocRef = _firebaseFirestore.collection('users').doc(_uid).collection('weeks').doc(weekId);
124+
DocumentReference yearDocRef = _firebaseFirestore.collection('users').doc(_uid).collection('years').doc('${time.year}');
125+
DocumentReference monthDocRef = _firebaseFirestore.collection('users').doc(_uid).collection('months').doc('${time.year}_${time.month}');
116126
DocumentSnapshot yearDocSnap = await transaction.get(yearDocRef);
117127
DocumentSnapshot monthDocSnap = await transaction.get(monthDocRef);
128+
DocumentSnapshot weekDocSnap = await transaction.get(weekDocRef);
118129

119130
if(!yearDocSnap.exists){
120131
transaction.set(yearDocRef, {
121-
'year' : _today.year
132+
'year' : time.year
122133
},SetOptions(merge: true));
123134
}
124135

125136
if(!monthDocSnap.exists){
126137
transaction.set(monthDocRef, {
127-
'year' : _today.year,
128-
'month' : _today.month
138+
'year' : time.year,
139+
'month' : time.month
140+
},SetOptions(merge: true));
141+
}
142+
143+
if(!weekDocSnap.exists){
144+
transaction.set(weekDocRef, {
145+
'year' : time.year,
146+
'month' : time.month,
147+
'week' : week,
148+
'id' : weekId
129149
},SetOptions(merge: true));
130150
}
131151

132152
transaction.update(yearDocRef, {
133-
'amounts.${_today.month}' : FieldValue.increment(amount)
153+
'amounts.${time.month}' : FieldValue.increment(amount)
134154
});
135155

136156
transaction.update(monthDocRef, {
137-
'amounts.${_today.day}' : FieldValue.increment(amount)
157+
'amounts.${time.day}' : FieldValue.increment(amount)
138158
});
139-
transaction.update(_currentWeek, {
159+
transaction.update(weekDocRef, {
140160
'amounts.$weekday' : FieldValue.increment(amount)
141161
});
142162

143163
});
144-
_weeklyData.amounts[weekday.toString()] += amount;
145-
notifyListeners();
164+
if(_weeklyData.id==weekId){
165+
_weeklyData.amounts[weekday.toString()] += amount;
166+
notifyListeners();
167+
}
146168
}catch(e){
147169
print(e);
148170
}
149171

150172
}
151173

152-
Future<void> getLocation()async{
174+
Future<bool> getLocationService()async{
153175
bool isServiceEnabled = await _location.serviceEnabled();
154176
print(isServiceEnabled);
155177

@@ -158,19 +180,29 @@ class HomeProvider extends ChangeNotifier {
158180
if (_enabled) {
159181
print('Service is enabled now');
160182
}else{
161-
return;
183+
return false;
162184
}
163185
}
164-
print('Service is already enables');
165186

166187
PermissionStatus permissionGranted = await _location.hasPermission();
167188
if (permissionGranted == PermissionStatus.denied) {
168189
PermissionStatus _isGranted = await _location.requestPermission();
169190
if (_isGranted != PermissionStatus.granted) {
170-
return;
191+
return false;
171192
}
172193
}
173-
print('Ok');
194+
return true;
174195
}
196+
197+
Future<void> updateUser(AppUser appUser)async{
198+
try{
199+
print(appUser.toDoc());
200+
await _userRef.update(appUser.toDoc());
201+
_appUser = appUser;
202+
notifyListeners();
203+
}catch(e){
204+
print(e);
205+
}
206+
}
175207
}
176208

lib/screens/auth_screen.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
44
import 'package:google_sign_in/google_sign_in.dart';
55
import 'package:provider/provider.dart';
66
import 'package:google_fonts/google_fonts.dart';
7+
import 'package:flutter/services.dart';
78

89
class AuthScreen extends StatefulWidget {
910
static const routeName = 'auth-screen';
@@ -15,6 +16,15 @@ class AuthScreen extends StatefulWidget {
1516
class _AuthScreenState extends State<AuthScreen> {
1617
bool _loading = false;
1718

19+
@override
20+
void initState() {
21+
super.initState();
22+
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
23+
statusBarColor: Colors.transparent,
24+
statusBarIconBrightness: Brightness.dark,
25+
));
26+
}
27+
1828
void toggleLoading(){
1929
setState(() {
2030
_loading = !_loading;

lib/screens/data_entry_screen.dart

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
44
import 'package:google_sign_in/google_sign_in.dart';
55
import 'package:intl/intl.dart';
66
import '../utils/time_converter.dart';
7+
import '../widgets/custom_form_field.dart';
78

89
class DataEntryScreen extends StatelessWidget {
910
static const routeName = 'data-entry-screen';
@@ -102,21 +103,22 @@ class _DataEntryFormState extends State<DataEntryForm> {
102103
if(!_formKey.currentState.validate()){
103104
return;
104105
}
105-
// toggleLoading();
106-
// try{
107-
// await Provider.of<AuthProvider>(context,listen: false).signUp(
108-
// _gender,
109-
// _birthday,
110-
// _weight,
111-
// _wakeUpTime,
112-
// _water
113-
// );
114-
// Navigator.of(context).pop();
115-
// return;
116-
// }catch(e){
117-
// print(e);
118-
// }
119-
// toggleLoading();
106+
_formKey.currentState.save();
107+
toggleLoading();
108+
try{
109+
await Provider.of<AuthProvider>(context,listen: false).signUp(
110+
_gender,
111+
_birthday,
112+
_weight,
113+
_wakeUpTime,
114+
_water
115+
);
116+
Navigator.of(context).pop();
117+
return;
118+
}catch(e){
119+
print(e);
120+
}
121+
toggleLoading();
120122
}
121123

122124
void setWater({double weight}){
@@ -368,48 +370,7 @@ class _DataEntryFormState extends State<DataEntryForm> {
368370
}
369371
}
370372

371-
class CustomFormField extends StatelessWidget {
372-
final String label;
373-
final Widget child;
374-
CustomFormField({this.child,this.label});
375-
@override
376-
Widget build(BuildContext context) {
377-
return Container(
378-
//color: Colors.yellow,
379-
height: 60,
380-
child: Stack(
381-
children: [
382-
Container(
383-
width: double.infinity,
384-
height: double.infinity,
385-
margin: EdgeInsets.only(top: 6),
386-
padding: EdgeInsets.symmetric(horizontal: 12),
387-
decoration: BoxDecoration(
388-
border: Border.all(color: Colors.black.withOpacity(0.3),width: 1.1),
389-
borderRadius: BorderRadius.circular(4)
390-
),
391-
alignment: Alignment.centerLeft,
392-
child: child
393-
),
394-
Positioned(
395-
left: 14,
396-
child: Container(
397-
color: Colors.white,
398-
padding: EdgeInsets.symmetric(horizontal: 3),
399-
child: Text(
400-
label,
401-
style: TextStyle(
402-
fontSize: 12,
403-
fontWeight: FontWeight.w500
404-
),
405-
)
406-
),
407-
)
408-
],
409-
),
410-
);
411-
}
412-
}
373+
413374

414375
// RaisedButton(
415376
// child: Text('Lest go'),

0 commit comments

Comments
 (0)