Skip to content

Commit

Permalink
Register ui and functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaaelgendy committed Dec 16, 2020
1 parent f5c2355 commit d29caad
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 9 deletions.
17 changes: 17 additions & 0 deletions lib/core/view_model/auth_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,21 @@ class AuthViewModel extends GetxController {
);
}
}

void createAccountWithEmailAndPassword() async {
try {
await _auth.createUserWithEmailAndPassword(
email: email, password: password);

Get.offAll(HomeView());
} catch (e) {
print(e.message);
Get.snackbar(
'Error login account',
e.message,
colorText: Colors.black,
snackPosition: SnackPosition.BOTTOM,
);
}
}
}
16 changes: 11 additions & 5 deletions lib/view/auth/login_screen.dart → lib/view/auth/login_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:ecommerce_app/core/view_model/auth_view_model.dart';
import 'package:ecommerce_app/view/auth/register_view.dart';
import 'package:ecommerce_app/view/widgets/custom_buttom.dart';
import 'package:ecommerce_app/view/widgets/custom_button_social.dart';
import 'package:ecommerce_app/view/widgets/custom_text.dart';
Expand All @@ -8,7 +9,7 @@ import 'package:get/get.dart';

import '../../constance.dart';

class LoginScreen extends GetWidget<AuthViewModel> {
class LoginView extends GetWidget<AuthViewModel> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

@override
Expand Down Expand Up @@ -36,10 +37,15 @@ class LoginScreen extends GetWidget<AuthViewModel> {
text: "Welcome,",
fontSize: 30,
),
CustomText(
text: "Sign Up",
color: primaryColor,
fontSize: 18,
GestureDetector(
onTap: () {
Get.to(RegisterView());
},
child: CustomText(
text: "Sign Up",
color: primaryColor,
fontSize: 18,
),
),
],
),
Expand Down
109 changes: 109 additions & 0 deletions lib/view/auth/register_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import 'package:ecommerce_app/core/view_model/auth_view_model.dart';
import 'package:ecommerce_app/view/auth/login_view.dart';
import 'package:ecommerce_app/view/widgets/custom_buttom.dart';
import 'package:ecommerce_app/view/widgets/custom_text.dart';
import 'package:ecommerce_app/view/widgets/custom_text_form_field.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class RegisterView extends GetWidget<AuthViewModel> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0.0,
leading: GestureDetector(
onTap: () {
Get.off(LoginView());
},
child: Icon(
Icons.arrow_back,
color: Colors.black,
)),
),
body: Padding(
padding: const EdgeInsets.only(
top: 50,
right: 20,
left: 20,
),
child: Form(
key: _formKey,
child: Column(
children: [
CustomText(
text: "Sign Up,",
fontSize: 30,
),
SizedBox(
height: 30,
),
CustomTextFormField(
text: 'Name',
hint: 'Pesa',
onSave: (value) {
controller.name = value;
},
validator: (value) {
if (value == null) {
print("ERROR");
}
},
),
SizedBox(
height: 30,
),
CustomTextFormField(
text: 'Email',
hint: '[email protected]',
onSave: (value) {
controller.email = value;
},
validator: (value) {
if (value == null) {
print("ERROR");
}
},
),
SizedBox(
height: 40,
),
CustomTextFormField(
text: 'Password',
hint: '**********',
onSave: (value) {
controller.password = value;
},
validator: (value) {
if (value == null) {
print('error');
}
},
),
SizedBox(
height: 15,
),
CustomButton(
onPress: () {
_formKey.currentState.save();

if (_formKey.currentState.validate()) {
controller.createAccountWithEmailAndPassword();
}
},
text: 'SIGN Up',
),
SizedBox(
height: 40,
),
],
),
),
),
);
}
}
4 changes: 2 additions & 2 deletions lib/view/control_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:ecommerce_app/core/view_model/auth_view_model.dart';
import 'package:ecommerce_app/view/auth/login_screen.dart';
import 'package:ecommerce_app/view/auth/login_view.dart';
import 'package:ecommerce_app/view/home_view.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand All @@ -10,7 +10,7 @@ class ControlView extends GetWidget<AuthViewModel> {
return Obx(() {
return (Get.find<AuthViewModel>().user != null)
? HomeView()
: LoginScreen();
: LoginView();
});
}
}
4 changes: 2 additions & 2 deletions lib/view/home_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:ecommerce_app/view/auth/login_screen.dart';
import 'package:ecommerce_app/view/auth/login_view.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand All @@ -17,7 +17,7 @@ class HomeView extends StatelessWidget {
child: Text("Logout"),
onPressed: () {
_auth.signOut();
Get.offAll(LoginScreen());
Get.offAll(LoginView());
},
),
),
Expand Down

0 comments on commit d29caad

Please sign in to comment.