diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-12-20 19:40:11 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-12-20 19:40:11 +0200 |
| commit | b84fe9a9c4c18a3f4e957f76ead34403c4316f76 (patch) | |
| tree | 14e4b37ae137ed538eaa14af4228c41033facac8 /lib/signup.dart | |
| parent | 953b5ce3ad7e933c6f008202346fe5bf2985bf9e (diff) | |
| download | carpool-b84fe9a9c4c18a3f4e957f76ead34403c4316f76.tar.xz carpool-b84fe9a9c4c18a3f4e957f76ead34403c4316f76.zip | |
Added a simple Login and SignUp page for the web driver app
Diffstat (limited to 'lib/signup.dart')
| -rw-r--r-- | lib/signup.dart | 200 |
1 files changed, 0 insertions, 200 deletions
diff --git a/lib/signup.dart b/lib/signup.dart deleted file mode 100644 index 18a27ad..0000000 --- a/lib/signup.dart +++ /dev/null @@ -1,200 +0,0 @@ -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; - - @override - Widget build(BuildContext context) { - return Scaffold( - 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, - ), - Text( - "Welcome ", - style: Theme.of(context).textTheme.headlineMedium, - ), - Text( - "Create your account", - style: Theme.of(context).textTheme.bodySmall, - ), - 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; - }, - ), - 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; - }, - ), - 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"), - ), - ], - ), - ], - ), - ], - ), - ), - ), - ); - } - - @override - void dispose() { - _focusNodePassword.dispose(); - _controllerUsername.dispose(); - _controllerPassword.dispose(); - _corfirmPassword.dispose(); - super.dispose(); - } -} |
