Skip to content

Commit

Permalink
Merge pull request #18 from bmabir17/feat_loginPage
Browse files Browse the repository at this point in the history
Feat login page
  • Loading branch information
bmabir17 authored Apr 14, 2020
2 parents 138b512 + 306e931 commit 8ba86a6
Show file tree
Hide file tree
Showing 11 changed files with 430 additions and 31 deletions.
8 changes: 8 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
}
},
"oauth_client": [
{
"client_id": "665789288012-qrt6o10bcnhibij0nfarne175epguiiu.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.bmabir17.tran_dao",
"certificate_hash": "5b1f6c8e8b26f1da06b93eb987a0e403d5026a5d"
}
},
{
"client_id": "665789288012-6lk6m26rfhm9b3kviga0ur5pe3cc7rso.apps.googleusercontent.com",
"client_type": 3
Expand Down
Binary file added assets/google_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:tran_dao/ui/loginPage.dart';
import "package:tran_dao/ui/reliefMapPage.dart";
import "package:tran_dao/menu.dart";
import 'package:splashscreen/splashscreen.dart';

class TranDao extends StatefulWidget {
@override
_TranDaoState createState() => _TranDaoState();
Expand All @@ -17,9 +17,11 @@ class _TranDaoState extends State<TranDao> {

return MaterialApp(
home: _initPage,
// home: LoginPage(),
routes: <String, WidgetBuilder>{
// '/': (BuildContext context) => _initPage,
'/reliefMap': (BuildContext context) => ReliefMapPage(),
'/home': (BuildContext context) => MenuPage(),
'/login': (BuildContext context) => LoginPage(),
// '/signup': (BuildContext context) => SignupPage(),
// '/addCamera': (BuildContext context) => AddCamera(socketIO),
// '/home': (BuildContext context) => HomePage(),
Expand Down
63 changes: 63 additions & 0 deletions lib/common/sign_in.dart
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");
}

16 changes: 11 additions & 5 deletions lib/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:geolocator/geolocator.dart';

import "package:tran_dao/ui/reliefMapPage.dart";
import "package:tran_dao/ui/infectedMapPage.dart";
import 'package:tran_dao/ui/userProfilePage.dart';

class MenuPage extends StatefulWidget{
MenuPage();
Expand Down Expand Up @@ -43,13 +44,18 @@ class _MenuPageState extends State<MenuPage>{
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("ত্রান দাও : Relief Distribution Map"),
title: const Text("ত্রান দাও : Relief Distribution Map",textAlign: TextAlign.center,),
leading: new IconButton(
icon: new Icon(Icons.track_changes),
onPressed: () {},
),
backgroundColor: Colors.green[800],
),
body: Center(
child: <Widget>[
ReliefMapPage(currentPosition:_currentPosition),
InfectedMapPage(currentPosition:_currentPosition),
UserProfile(),
// Text(
// 'Index 2: School',
// style: optionStyle,
Expand All @@ -66,10 +72,10 @@ class _MenuPageState extends State<MenuPage>{
icon: Icon(Icons.warning),
title: Text('Infected Map'),
),
// BottomNavigationBarItem(
// icon: Icon(Icons.school),
// title: Text('School'),
// ),
BottomNavigationBarItem(
icon: Icon(Icons.person),
title: Text('Your profile'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.green[800],
Expand Down
61 changes: 51 additions & 10 deletions lib/ui/infectedMapPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {

Expand All @@ -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();

}
Expand All @@ -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,
Expand Down Expand Up @@ -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],
),
Expand Down Expand Up @@ -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),
Expand All @@ -168,11 +190,7 @@ class _InfectedMapPageState extends State<InfectedMapPage>{
rad = 10 + (quantity/ 200).round();
}
rad = 50;

}


// print("heatmaps:$_heatmaps");
setState(() {
_heatmaps.add(
Heatmap(
Expand Down Expand Up @@ -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 () {
Expand Down
76 changes: 76 additions & 0 deletions lib/ui/loginPage.dart
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),
),
),
],
),
),
);
}
}
Loading

0 comments on commit 8ba86a6

Please sign in to comment.