-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from bmabir17/feat_loginPage
Feat login page
- Loading branch information
Showing
11 changed files
with
430 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
|
||
final FirebaseAuth _auth = FirebaseAuth.instance; | ||
final GoogleSignIn googleSignIn = GoogleSignIn(); | ||
|
||
String name; | ||
String email; | ||
String imageUrl; | ||
|
||
// ref https://blog.codemagic.io/firebase-authentication-google-sign-in-using-flutter/ | ||
Future<String> signInWithGoogle() async { | ||
final GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn(); | ||
final GoogleSignInAuthentication googleSignInAuthentication = | ||
await googleSignInAccount.authentication; | ||
|
||
final AuthCredential credential = GoogleAuthProvider.getCredential( | ||
accessToken: googleSignInAuthentication.accessToken, | ||
idToken: googleSignInAuthentication.idToken, | ||
); | ||
|
||
final AuthResult authResult = await _auth.signInWithCredential(credential); | ||
final FirebaseUser user = authResult.user; | ||
|
||
// Checking if email and name is null | ||
assert(user.email != null); | ||
assert(user.displayName != null); | ||
assert(user.photoUrl != null); | ||
|
||
name = user.displayName; | ||
email = user.email; | ||
imageUrl = user.photoUrl; | ||
|
||
assert(!user.isAnonymous); | ||
assert(await user.getIdToken() != null); | ||
|
||
final FirebaseUser currentUser = await _auth.currentUser(); | ||
assert(user.uid == currentUser.uid); | ||
|
||
return 'signInWithGoogle succeeded: $user'; | ||
} | ||
|
||
Future<bool> checkLogin() async { | ||
final FirebaseUser currentUser = await _auth.currentUser(); | ||
if(currentUser != null ){ | ||
if(email ==null){ | ||
name = currentUser.displayName; | ||
email = currentUser.email; | ||
imageUrl = currentUser.photoUrl; | ||
} | ||
//userLogged in | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
|
||
void signOutGoogle() async{ | ||
await _auth.signOut(); | ||
|
||
print("User Sign Out"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; | |
import 'package:geolocator/geolocator.dart'; | ||
import 'package:google_maps_flutter_heatmap/google_maps_flutter_heatmap.dart'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:tran_dao/common/sign_in.dart'; | ||
|
||
class InfectedMapPage extends StatefulWidget{ | ||
final Position currentPosition; | ||
|
@@ -28,7 +29,10 @@ class _InfectedMapPageState extends State<InfectedMapPage>{ | |
var selectedLocationID; | ||
var selectedLocationQuantity; | ||
var selectedLocationMarkerId; | ||
|
||
bool loginStatus; | ||
|
||
String adminEmail ="[email protected]"; | ||
|
||
void _onMapCreated(GoogleMapController controller) { | ||
|
||
|
@@ -40,9 +44,13 @@ class _InfectedMapPageState extends State<InfectedMapPage>{ | |
_currentPosition = currentPosition; | ||
if(currentPosition == null){ | ||
_getCurrentLocation(); | ||
print("current location not passed"); | ||
} | ||
getInfectedData(); | ||
checkLogin().then((bool stat){ | ||
setState(() { | ||
loginStatus = stat; | ||
}); | ||
}); | ||
super.initState(); | ||
|
||
} | ||
|
@@ -52,7 +60,7 @@ class _InfectedMapPageState extends State<InfectedMapPage>{ | |
return | ||
Stack( | ||
children:<Widget>[ | ||
_currentPosition != null ? GoogleMap( | ||
(_currentPosition != null) ? GoogleMap( | ||
onMapCreated: _onMapCreated, | ||
myLocationEnabled: true, | ||
myLocationButtonEnabled: true, | ||
|
@@ -80,23 +88,37 @@ class _InfectedMapPageState extends State<InfectedMapPage>{ | |
alignment: Alignment.bottomRight, | ||
child:FloatingActionButton.extended( | ||
onPressed: () { | ||
_showQuantityModal(context); | ||
if (loginStatus && email!=null){ | ||
if(email == adminEmail){ | ||
_showQuantityModal(context); | ||
}else{ | ||
_showDialog("Admin Permission needed"); | ||
} | ||
}else{ | ||
Navigator.of(context).pushNamed('/login').then((value){ | ||
checkLogin().then((bool stat){ | ||
setState(() { | ||
loginStatus = stat; | ||
}); | ||
}); | ||
}); | ||
} | ||
}, | ||
label: Text('New infection'), | ||
icon: Icon(Icons.add), | ||
backgroundColor: Colors.red[800], | ||
), | ||
), | ||
), | ||
selectedLocationID != null ? Padding( | ||
(selectedLocationID != null && loginStatus) ? Padding( | ||
padding: const EdgeInsets.all(20.0), | ||
child: Align( | ||
alignment: Alignment.bottomLeft, | ||
child:FloatingActionButton.extended( | ||
onPressed: () { | ||
_showQuantityModal(context,selectedLocationID,selectedLocationQuantity,selectedLocationMarkerId); | ||
}, | ||
label: Text('Update data $selectedLocationQuantity'), | ||
label: Text('Update: $selectedLocationQuantity'), | ||
icon: Icon(Icons.edit), | ||
backgroundColor: Colors.yellow[800], | ||
), | ||
|
@@ -141,7 +163,7 @@ class _InfectedMapPageState extends State<InfectedMapPage>{ | |
markerId: MarkerId(location.toString()), | ||
position: location, | ||
infoWindow: InfoWindow( | ||
title: 'Data Source: $orgName, Entry: $dataType $documentID' , | ||
title: 'Data Source: $orgName, Entry: $dataType' , | ||
snippet: ' Number of infected: $quantity ,Date: $dateString', | ||
), | ||
icon: BitmapDescriptor.defaultMarkerWithHue(20), | ||
|
@@ -168,11 +190,7 @@ class _InfectedMapPageState extends State<InfectedMapPage>{ | |
rad = 10 + (quantity/ 200).round(); | ||
} | ||
rad = 50; | ||
|
||
} | ||
|
||
|
||
// print("heatmaps:$_heatmaps"); | ||
setState(() { | ||
_heatmaps.add( | ||
Heatmap( | ||
|
@@ -276,6 +294,29 @@ class _InfectedMapPageState extends State<InfectedMapPage>{ | |
) | ||
); | ||
} | ||
// https://medium.com/@nils.backe/flutter-alert-dialogs-9b0bb9b01d28 | ||
void _showDialog(String message,[String title="Alert"]) { | ||
// flutter defined function | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) { | ||
// return object of type Dialog | ||
return AlertDialog( | ||
title: new Text(title), | ||
content: new Text(message), | ||
actions: <Widget>[ | ||
// usually buttons at the bottom of the dialog | ||
new FlatButton( | ||
child: new Text("ok"), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
// ------------------ I/O functions ------------ | ||
// Reference https://alligator.io/flutter/geolocator-plugin/ | ||
_getCurrentLocation () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:tran_dao/common/sign_in.dart'; | ||
|
||
class LoginPage extends StatefulWidget{ | ||
@override | ||
_LoginPageState createState() => _LoginPageState(); | ||
} | ||
|
||
class _LoginPageState extends State<LoginPage>{ | ||
|
||
@override | ||
Widget build(BuildContext context){ | ||
return Scaffold( | ||
body: Container( | ||
color: Colors.white, | ||
child: Center( | ||
child: Column( | ||
mainAxisSize: MainAxisSize.max, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Image(image: AssetImage("assets/icon/product.png"),height:100.0), | ||
Text('ত্রান দাও', | ||
style: new TextStyle( | ||
fontWeight: FontWeight.bold, | ||
fontSize: 35.0, | ||
), | ||
), | ||
// FlutterLogo(size:150), | ||
SizedBox(height:50), | ||
_signInButton(), | ||
SizedBox(height:30), | ||
Text("ত্রান এর হিসাব দিতে", | ||
style: new TextStyle( | ||
fontStyle: FontStyle.italic, | ||
fontSize: 20.0, | ||
color: Colors.green | ||
), | ||
) | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
Widget _signInButton() { | ||
return OutlineButton( | ||
onPressed: (){ | ||
signInWithGoogle().whenComplete((){ | ||
Navigator.pop(context); | ||
// Navigator.pushNamed(context, '/home'); | ||
}); | ||
}, | ||
splashColor: Colors.grey, | ||
shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(40)), | ||
highlightElevation: 0, | ||
borderSide: BorderSide(color: Colors.grey), | ||
child: Padding( | ||
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10), | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Image(image: AssetImage("assets/google_logo.png"),height:35.0), | ||
Padding( | ||
padding: const EdgeInsets.only(left:10), | ||
child: Text( | ||
'Sign in with google', | ||
style: TextStyle(fontSize: 20,color:Colors.grey), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.