diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-12-04 23:16:08 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-12-04 23:16:08 +0200 |
| commit | 19709e296aec10d2cd24f904a87243216a454d5f (patch) | |
| tree | e18982e7ee2d0f550c36601286a6371486de619e /lib | |
| parent | d7946d6a76f6f04de0feea1e97aeb80031c15efc (diff) | |
| download | carpool-19709e296aec10d2cd24f904a87243216a454d5f.tar.xz carpool-19709e296aec10d2cd24f904a87243216a454d5f.zip | |
Added auth to signup page + some UI refactoring
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/credit_card_payment.dart | 2 | ||||
| -rw-r--r-- | lib/main.dart | 6 | ||||
| -rw-r--r-- | lib/signup.dart | 243 |
3 files changed, 190 insertions, 61 deletions
diff --git a/lib/credit_card_payment.dart b/lib/credit_card_payment.dart index 0e73e6d..ef1d737 100644 --- a/lib/credit_card_payment.dart +++ b/lib/credit_card_payment.dart @@ -52,7 +52,7 @@ class CreditCardDetailsPage extends StatelessWidget { const SizedBox(height: 24.0), ElevatedButton( onPressed: () { - // TODO + // TODO: // Implement payment processing logic here print('Payment processed for Order ID: $orderID'); Navigator.pop( diff --git a/lib/main.dart b/lib/main.dart index 594be4d..63bbac7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,6 @@ +import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; +import 'firebase_options.dart'; import 'routes.dart'; import 'login.dart'; import 'cart.dart'; @@ -6,7 +8,9 @@ import 'payement_order.dart'; import 'signup.dart'; import 'order_history.dart'; -void main() { +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); runApp(MyApp()); } diff --git a/lib/signup.dart b/lib/signup.dart index ecb8ec0..18a27ad 100644 --- a/lib/signup.dart +++ b/lib/signup.dart @@ -1,75 +1,200 @@ import 'package:flutter/material.dart'; +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +class SignUpPage extends StatefulWidget { + const SignUpPage({ + Key? key, + }) : super(key: key); + + @override + State<SignUpPage> createState() => _SignUpPageState(); +} + +class _SignUpPageState extends State<SignUpPage> { + final GlobalKey<FormState> _formKey = GlobalKey(); + + final FocusNode _focusNodePassword = FocusNode(); + final FocusNode _focusNodeConfirmPassword = FocusNode(); + final TextEditingController _controllerUsername = TextEditingController(); + final TextEditingController _controllerPassword = TextEditingController(); + final TextEditingController _corfirmPassword = TextEditingController(); + + bool _obscurePassword = true; -class SignUpPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: const Text('Sign Up'), - ), - body: Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextFormField( - decoration: const InputDecoration( - labelText: 'First Name', - hintText: 'Enter your first name', + backgroundColor: Colors.grey[300], + body: Form( + key: _formKey, + child: SingleChildScrollView( + padding: const EdgeInsets.all(30.0), + child: Column( + children: [ + const SizedBox(height: 20), + Image.asset( + "assets/logo.png", + height: 190, ), - ), - const SizedBox(height: 16.0), - TextFormField( - decoration: const InputDecoration( - labelText: 'Last Name', - hintText: 'Enter your last name', + Text( + "Welcome ", + style: Theme.of(context).textTheme.headlineMedium, ), - ), - const SizedBox(height: 16.0), - TextFormField( - decoration: const InputDecoration( - labelText: 'Email', - hintText: 'Enter your email', + Text( + "Create your account", + style: Theme.of(context).textTheme.bodySmall, ), - keyboardType: TextInputType.emailAddress, - ), - const SizedBox(height: 16.0), - TextFormField( - decoration: const InputDecoration( - labelText: 'Password', - hintText: 'Enter your password', + const SizedBox(height: 40), + TextFormField( + controller: _controllerUsername, + keyboardType: TextInputType.name, + decoration: InputDecoration( + labelText: "Email", + prefixIcon: const Icon(Icons.email_outlined), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + onEditingComplete: () => _focusNodePassword.requestFocus(), + validator: (String? value) { + if (value == null || value.isEmpty) { + return "Please enter username."; + } + + return null; + }, + ), + const SizedBox(height: 10), + TextFormField( + controller: _controllerPassword, + focusNode: _focusNodePassword, + obscureText: _obscurePassword, + keyboardType: TextInputType.visiblePassword, + decoration: InputDecoration( + labelText: "Password", + prefixIcon: const Icon(Icons.password_outlined), + suffixIcon: IconButton( + onPressed: () { + setState(() { + _obscurePassword = !_obscurePassword; + }); + }, + icon: _obscurePassword + ? const Icon(Icons.visibility_outlined) + : const Icon(Icons.visibility_off_outlined)), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + validator: (String? value) { + if (value == null || value.isEmpty) { + return "Please enter password."; + } + + return null; + }, ), - obscureText: true, - ), - const SizedBox(height: 16.0), - TextFormField( - decoration: const InputDecoration( - labelText: 'Confirm password', - hintText: 'Re enter your password', + const SizedBox(height: 10), + TextFormField( + controller: _corfirmPassword, + focusNode: _focusNodeConfirmPassword, + obscureText: _obscurePassword, + keyboardType: TextInputType.visiblePassword, + decoration: InputDecoration( + labelText: "Confirm Password", + prefixIcon: const Icon(Icons.password_outlined), + suffixIcon: IconButton( + onPressed: () { + setState(() { + _obscurePassword = !_obscurePassword; + }); + }, + icon: _obscurePassword + ? const Icon(Icons.visibility_outlined) + : const Icon(Icons.visibility_off_outlined)), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + ), + ), + validator: (String? value) { + if (value == null || value.isEmpty) { + return "Please enter password."; + } else if (_controllerPassword.text.trim() != + _corfirmPassword.text.trim()) { + return "Password Must match"; + } + + return null; + }, ), - obscureText: true, - ), - const SizedBox(height: 16.0), - TextFormField( - decoration: const InputDecoration( - labelText: 'Phone Number', - hintText: 'Enter your phone number', + const SizedBox(height: 60), + Column( + children: [ + ElevatedButton( + style: ElevatedButton.styleFrom( + minimumSize: const Size.fromHeight(50), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + backgroundColor: Color(0xFF355291), + ), + onPressed: () async { + if (_formKey.currentState?.validate() ?? false) { + try { + await FirebaseAuth.instance + .createUserWithEmailAndPassword( + email: _controllerUsername.text.trim(), + password: _controllerPassword.text.trim()) + .then((value) => + Navigator.pushNamedAndRemoveUntil( + context, "/", (route) => false)); + } on FirebaseAuthException catch (e) { + Fluttertoast.showToast( + msg: e.message.toString(), + gravity: ToastGravity.SNACKBAR); + } + } + }, + child: const Text("Sign Up"), + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text("Already have an account?"), + TextButton( + onPressed: () { + _formKey.currentState?.reset(); + Navigator.pushReplacementNamed(context, "/login"); + }, + child: const Text("Login"), + ), + ], + ), + ], ), - keyboardType: TextInputType.phone, - ), - const SizedBox(height: 24.0), - ElevatedButton( - onPressed: () { - // TODO - // Implement sign-up logic here - Navigator.pushNamed(context, '/home'); - }, - child: const Text('Sign Up'), - ), - ], + ], + ), ), ), ); } + + @override + void dispose() { + _focusNodePassword.dispose(); + _controllerUsername.dispose(); + _controllerPassword.dispose(); + _corfirmPassword.dispose(); + super.dispose(); + } } |
