|
| 1 | +import 'package:firebase_app_web/pages/HomePage.dart'; |
| 2 | +import 'package:firebase_app_web/pages/SignInPage.dart'; |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter_svg/flutter_svg.dart'; |
| 5 | +import 'package:firebase_auth/firebase_auth.dart' as firebase_auth; |
| 6 | + |
| 7 | +class SignUpPage extends StatefulWidget { |
| 8 | + SignUpPage({Key key}) : super(key: key); |
| 9 | + |
| 10 | + @override |
| 11 | + _SignUpPageState createState() => _SignUpPageState(); |
| 12 | +} |
| 13 | + |
| 14 | +class _SignUpPageState extends State<SignUpPage> { |
| 15 | + firebase_auth.FirebaseAuth firebaseAuth = firebase_auth.FirebaseAuth.instance; |
| 16 | + TextEditingController _emailController = TextEditingController(); |
| 17 | + TextEditingController _pwdController = TextEditingController(); |
| 18 | + bool circular = false; |
| 19 | + |
| 20 | + @override |
| 21 | + Widget build(BuildContext context) { |
| 22 | + return Scaffold( |
| 23 | + body: SingleChildScrollView( |
| 24 | + child: Container( |
| 25 | + height: MediaQuery.of(context).size.height, |
| 26 | + width: MediaQuery.of(context).size.width, |
| 27 | + color: Colors.black, |
| 28 | + child: Column( |
| 29 | + mainAxisAlignment: MainAxisAlignment.center, |
| 30 | + children: [ |
| 31 | + Text( |
| 32 | + "Sign Up", |
| 33 | + style: TextStyle( |
| 34 | + fontSize: 35, |
| 35 | + color: Colors.white, |
| 36 | + fontWeight: FontWeight.bold, |
| 37 | + ), |
| 38 | + ), |
| 39 | + SizedBox( |
| 40 | + height: 20, |
| 41 | + ), |
| 42 | + buttonItem("assets/google.svg", "Continue with Google", 25), |
| 43 | + SizedBox( |
| 44 | + height: 15, |
| 45 | + ), |
| 46 | + buttonItem("assets/phone.svg", "Continue with Mobile", 30), |
| 47 | + SizedBox( |
| 48 | + height: 18, |
| 49 | + ), |
| 50 | + Text( |
| 51 | + "Or", |
| 52 | + style: TextStyle(color: Colors.white, fontSize: 18), |
| 53 | + ), |
| 54 | + SizedBox( |
| 55 | + height: 18, |
| 56 | + ), |
| 57 | + textItem("Email....", _emailController, false), |
| 58 | + SizedBox( |
| 59 | + height: 15, |
| 60 | + ), |
| 61 | + textItem("Password...", _pwdController, true), |
| 62 | + SizedBox( |
| 63 | + height: 40, |
| 64 | + ), |
| 65 | + colorButton(), |
| 66 | + SizedBox( |
| 67 | + height: 20, |
| 68 | + ), |
| 69 | + Row( |
| 70 | + mainAxisAlignment: MainAxisAlignment.center, |
| 71 | + children: [ |
| 72 | + Text( |
| 73 | + "If you alredy have an Account? ", |
| 74 | + style: TextStyle( |
| 75 | + color: Colors.white, |
| 76 | + fontSize: 16, |
| 77 | + ), |
| 78 | + ), |
| 79 | + InkWell( |
| 80 | + onTap: () { |
| 81 | + Navigator.pushAndRemoveUntil( |
| 82 | + context, |
| 83 | + MaterialPageRoute(builder: (builder) => SignInPage()), |
| 84 | + (route) => false); |
| 85 | + }, |
| 86 | + child: Text( |
| 87 | + "Login", |
| 88 | + style: TextStyle( |
| 89 | + color: Colors.white, |
| 90 | + fontSize: 16, |
| 91 | + fontWeight: FontWeight.w600, |
| 92 | + ), |
| 93 | + ), |
| 94 | + ), |
| 95 | + ], |
| 96 | + ), |
| 97 | + ], |
| 98 | + ), |
| 99 | + ), |
| 100 | + ), |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | + Widget colorButton() { |
| 105 | + return InkWell( |
| 106 | + onTap: () async { |
| 107 | + setState(() { |
| 108 | + circular = true; |
| 109 | + }); |
| 110 | + try { |
| 111 | + firebase_auth.UserCredential userCredential = |
| 112 | + await firebaseAuth.createUserWithEmailAndPassword( |
| 113 | + email: _emailController.text, password: _pwdController.text); |
| 114 | + print(userCredential.user.email); |
| 115 | + setState(() { |
| 116 | + circular = false; |
| 117 | + }); |
| 118 | + Navigator.pushAndRemoveUntil( |
| 119 | + context, |
| 120 | + MaterialPageRoute(builder: (builder) => HomePage()), |
| 121 | + (route) => false); |
| 122 | + } catch (e) { |
| 123 | + final snackbar = SnackBar(content: Text(e.toString())); |
| 124 | + ScaffoldMessenger.of(context).showSnackBar(snackbar); |
| 125 | + setState(() { |
| 126 | + circular = false; |
| 127 | + }); |
| 128 | + } |
| 129 | + }, |
| 130 | + child: Container( |
| 131 | + width: MediaQuery.of(context).size.width - 100, |
| 132 | + height: 60, |
| 133 | + decoration: BoxDecoration( |
| 134 | + borderRadius: BorderRadius.circular(20), |
| 135 | + gradient: LinearGradient(colors: [ |
| 136 | + Color(0xfffd746c), |
| 137 | + Color(0xffff9068), |
| 138 | + Color(0xfffd746c) |
| 139 | + ]), |
| 140 | + ), |
| 141 | + child: Center( |
| 142 | + child: circular |
| 143 | + ? CircularProgressIndicator() |
| 144 | + : Text( |
| 145 | + "Sign Up", |
| 146 | + style: TextStyle( |
| 147 | + color: Colors.white, |
| 148 | + fontSize: 20, |
| 149 | + ), |
| 150 | + ), |
| 151 | + ), |
| 152 | + ), |
| 153 | + ); |
| 154 | + } |
| 155 | + |
| 156 | + Widget buttonItem(String imagepath, String buttonName, double size) { |
| 157 | + return Container( |
| 158 | + width: MediaQuery.of(context).size.width - 60, |
| 159 | + height: 60, |
| 160 | + child: Card( |
| 161 | + color: Colors.black, |
| 162 | + elevation: 8, |
| 163 | + shape: RoundedRectangleBorder( |
| 164 | + borderRadius: BorderRadius.circular(15), |
| 165 | + side: BorderSide( |
| 166 | + width: 1, |
| 167 | + color: Colors.grey, |
| 168 | + ), |
| 169 | + ), |
| 170 | + child: Row( |
| 171 | + mainAxisAlignment: MainAxisAlignment.center, |
| 172 | + children: [ |
| 173 | + SvgPicture.asset( |
| 174 | + imagepath, |
| 175 | + height: size, |
| 176 | + width: size, |
| 177 | + ), |
| 178 | + SizedBox( |
| 179 | + width: 15, |
| 180 | + ), |
| 181 | + Text( |
| 182 | + buttonName, |
| 183 | + style: TextStyle( |
| 184 | + color: Colors.white, |
| 185 | + fontSize: 17, |
| 186 | + ), |
| 187 | + ), |
| 188 | + ], |
| 189 | + ), |
| 190 | + ), |
| 191 | + ); |
| 192 | + } |
| 193 | + |
| 194 | + Widget textItem( |
| 195 | + String labeltext, TextEditingController controller, bool obscureText) { |
| 196 | + return Container( |
| 197 | + width: MediaQuery.of(context).size.width - 70, |
| 198 | + height: 55, |
| 199 | + child: TextFormField( |
| 200 | + controller: controller, |
| 201 | + obscureText: obscureText, |
| 202 | + style: TextStyle( |
| 203 | + fontSize: 17, |
| 204 | + color: Colors.white, |
| 205 | + ), |
| 206 | + decoration: InputDecoration( |
| 207 | + labelText: labeltext, |
| 208 | + labelStyle: TextStyle( |
| 209 | + fontSize: 17, |
| 210 | + color: Colors.white, |
| 211 | + ), |
| 212 | + focusedBorder: OutlineInputBorder( |
| 213 | + borderRadius: BorderRadius.circular(15), |
| 214 | + borderSide: BorderSide( |
| 215 | + width: 1.5, |
| 216 | + color: Colors.amber, |
| 217 | + ), |
| 218 | + ), |
| 219 | + enabledBorder: OutlineInputBorder( |
| 220 | + borderRadius: BorderRadius.circular(15), |
| 221 | + borderSide: BorderSide( |
| 222 | + width: 1, |
| 223 | + color: Colors.grey, |
| 224 | + ), |
| 225 | + ), |
| 226 | + ), |
| 227 | + ), |
| 228 | + ); |
| 229 | + } |
| 230 | +} |
0 commit comments