Skip to content

Commit

Permalink
Issue 68 (#79)
Browse files Browse the repository at this point in the history
* Resolved SignUp and logIn button Problem

* Done structuring of files #53

* Added proper structuring of files inside lib#53

* Added Structuring of files

* Added profile button functionality#49

* Added profile button fuctionality#49

* added navigation firt time users to userdetails screen #68

* Added Navigation first time users to user details screen #68

* Resolved issue #68
  • Loading branch information
Borahb committed Apr 29, 2021
1 parent 15d6eab commit 662b20a
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 72 deletions.
6 changes: 5 additions & 1 deletion lib/Services/authentication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class AuthenticationService {
databaseRef.push().set({'email': data});
}

Future<String> getuid()async{
return _auth.currentUser.uid;
}

Future<dynamic> signInWithEmailAndPassword(
String email, String password) async {
try {
Expand All @@ -36,7 +40,7 @@ class AuthenticationService {

final User user = (await _auth.createUserWithEmailAndPassword(
email: email, password: password)).user;
addData(user.email);
//addData(user.email);

// Email Verification Sending
user.sendEmailVerification();
Expand Down
2 changes: 1 addition & 1 deletion lib/Services/facebook_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AuthService {

// Create a credential from the access token
final OAuthCredential facebookAuthCredential =
FacebookAuthProvider.credential(result.accessToken.token);
FacebookAuthProvider.credential(result.token);

// Once signed in, return the UserCredential
final UserCredential authResult = await FirebaseAuth.instance
Expand Down
2 changes: 1 addition & 1 deletion lib/UI/create_goal_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class _CreateGoalPageState extends State<CreateGoalPage> {
),
),
Text(
Jiffy().add(months: noOfMonth.toInt()).yMMMM,
Jiffy().add(months: noOfMonth.toInt()).yMMMM.toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 35,
Expand Down
2 changes: 1 addition & 1 deletion lib/UI/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class _LoginScreenState extends State<LoginScreen> {
if (_formkey.currentState.validate()) {
dynamic result = await _auth.signInWithEmailAndPassword(
_email, _password);
print(result);
//print(result);
if (result == true) {
setState(() {
showSpinner = false;
Expand Down
15 changes: 12 additions & 3 deletions lib/UI/sign_up.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:batua/Services/authentication_service.dart';
import 'package:batua/UI/loading.dart';
import 'package:batua/UI/user_details_screen.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:batua/utils/constants.dart';

Expand All @@ -22,6 +26,8 @@ class SignUpScreenState extends State<SignUpScreen> {
String _email = '';
bool ishidden = true;
bool ishidden_ = true;
final db = FirebaseFirestore.instance;
final FirebaseAuth _fire = FirebaseAuth.instance;

// ignore: non_constant_identifier_names
static Color textField_color2 = const Color(0x42000000).withOpacity(0.05);
Expand Down Expand Up @@ -275,12 +281,14 @@ class SignUpScreenState extends State<SignUpScreen> {
child: TextButton(
onPressed: () async {
if (_formkey.currentState.validate()) {

dynamic result = await _auth
.registerWithEmailAndPassword(_email, _password);
if (result != null) {
Navigator.of(context).pushNamedAndRemoveUntil(
RouteConstants.LOGIN_SCREEN,
(route) => false,
final uid = await _auth.getuid();

db.collection('User Data').doc(uid).set({'Email':_email});
Navigator.of(context).push(MaterialPageRoute(builder: (context)=> UserDetailsScreen(uid: uid,email: _email,))
);
showDialog(
context: context,
Expand Down Expand Up @@ -316,6 +324,7 @@ class SignUpScreenState extends State<SignUpScreen> {
}
}
},

style: TextButton.styleFrom(
primary: primary_color,
backgroundColor: secondary_color,
Expand Down
142 changes: 95 additions & 47 deletions lib/UI/user_details_screen.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import 'package:batua/Services/authentication_service.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:batua/utils/constants.dart' as constants;

class UserDetailsScreen extends StatefulWidget {
final String uid;
final String email;
const UserDetailsScreen({Key key,this.uid,this.email}): super(key: key);

@override
State<StatefulWidget> createState() {
return _UserDetailsScreenState();
return _UserDetailsScreenState(uid: uid,email:email);
}
}

class _UserDetailsScreenState extends State<UserDetailsScreen> {
String uid;
String email;
_UserDetailsScreenState({this.uid,this.email});

final TextEditingController _nameController = TextEditingController();
final TextEditingController _emailController = TextEditingController();
final TextEditingController _phoneController = TextEditingController();


String _name = '';
String _phone = '';
String _email = '';
final db = FirebaseFirestore.instance;
final AuthenticationService _auth = AuthenticationService();
final _formkey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
final MediaQueryData _mediaQuery = MediaQuery.of(context);
Expand All @@ -22,46 +38,49 @@ class _UserDetailsScreenState extends State<UserDetailsScreen> {
return Scaffold(
body: ListView(
children: [
Stack(
children: [
// Profile picture
Container(
margin: const EdgeInsets.only(top: 10),
height: _height * 0.2,
decoration: const BoxDecoration(
color: Colors.grey,
shape: BoxShape.circle,
),
child: const Center(
child: Icon(
Icons.person,
color: Colors.white54,
size: 100,
),
),
),

// Plus button
Positioned(
right: _width * 0.35,
top: _height * 0.16,
child: Container(
height: _height * 0.05,
width: _height * 0.05,
Form(
key: _formkey,
child: Stack(
children: [
// Profile picture
Container(
margin: const EdgeInsets.only(top: 10),
height: _height * 0.2,
decoration: const BoxDecoration(
color: Color(0xff00B0FF),
color: Colors.grey,
shape: BoxShape.circle,
),
child: const Center(
child: Icon(
Icons.add,
color: Colors.white,
size: 20,
Icons.person,
color: Colors.white54,
size: 100,
),
),
),
)
],

// Plus button
Positioned(
right: _width * 0.35,
top: _height * 0.16,
child: Container(
height: _height * 0.05,
width: _height * 0.05,
decoration: const BoxDecoration(
color: Color(0xff00B0FF),
shape: BoxShape.circle,
),
child: const Center(
child: Icon(
Icons.add,
color: Colors.white,
size: 20,
),
),
),
)
],
),
),

// Name text
Expand All @@ -84,6 +103,12 @@ class _UserDetailsScreenState extends State<UserDetailsScreen> {
child: Container(
height: _height * 0.1,
child: TextFormField(
onChanged: (val){
setState((){
val =_name ;
});

},
validator: (name) {
if (name.isEmpty) {
return 'Required';
Expand Down Expand Up @@ -116,13 +141,16 @@ class _UserDetailsScreenState extends State<UserDetailsScreen> {
padding: const EdgeInsets.only(left: 20.0, right: 20, bottom: 22),
// ignore: sized_box_for_whitespace
child: Container(
height: MediaQuery.of(context).size.height * 0.1,
child: TextFormField(
controller: _emailController,
onChanged: (value) {},
decoration: constants.inputDecoration.copyWith(
hintText: 'Email(to be autofilled and disabled)',
),

height: MediaQuery.of(context).size.height * 0.08,
decoration: BoxDecoration(
color: constants.textField_color2,
border: Border.all(),
borderRadius: BorderRadius.circular(20.0),
),
child: Padding(
padding: const EdgeInsets.only(left:10.0,top: 15),
child: Text(email,style: const TextStyle(fontSize: 16,),),
),
),
),
Expand All @@ -146,8 +174,18 @@ class _UserDetailsScreenState extends State<UserDetailsScreen> {
child: Container(
height: MediaQuery.of(context).size.height * 0.1,
child: TextFormField(
validator: (val){
if(val.length < 10){
return "Enter valid phone number";
}
},
controller: _phoneController,
onChanged: (value) {},
onChanged: (value) {
setState(() {
value = _phone;
});

},
decoration: constants.inputDecoration.copyWith(
hintText: '(Optional)',
),
Expand All @@ -163,13 +201,23 @@ class _UserDetailsScreenState extends State<UserDetailsScreen> {
height: MediaQuery.of(context).size.height * 0.08,
// ignore: deprecated_member_use
child: RaisedButton(
onPressed: () {
print(_nameController.text);
print(_emailController.text);
print(_phoneController.text);
onPressed: ()async{
if(_formkey.currentState.validate()){
db.collection('User Data').doc(uid).set({
'Name': _nameController.text,
'Email':email,
'Mobile Number': _phoneController.text,
});
Navigator.of(context).pushNamed(
constants.RouteConstants.HOME_SCREEN,
constants.RouteConstants.LOGIN_SCREEN,
);
}


// print(_nameController.text);
//print(email);
// print(_phoneController.text);

},
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
Expand Down

0 comments on commit 662b20a

Please sign in to comment.