11import 'package:flash_chat_flutter_firebase/constants.dart' ;
22import 'package:flutter/material.dart' ;
33
4+ import '../components/rounded_button.dart' ;
5+
6+ import 'package:firebase_auth/firebase_auth.dart' ;
7+
8+ import 'chat_screen.dart' ;
9+
410class RegistrationScreen extends StatefulWidget {
511 static const String id = 'registration_screen' ;
612 @override
713 _RegistrationScreenState createState () => _RegistrationScreenState ();
814}
915
1016class _RegistrationScreenState extends State <RegistrationScreen > {
17+ final _auth = FirebaseAuth .instance;
18+ String ? email;
19+ String ? password;
1120 @override
1221 Widget build (BuildContext context) {
1322 return Scaffold (
@@ -25,46 +34,45 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
2534 child: Image .asset ('images/logo.png' ),
2635 ),
2736 ),
28- SizedBox (
37+ const SizedBox (
2938 height: 48.0 ,
3039 ),
3140 TextField (
41+ keyboardType: TextInputType .emailAddress,
42+ textAlign: TextAlign .center,
3243 onChanged: (value) {
33- //Do something with the user input.
44+ email = value;
3445 },
3546 decoration: kInputDecoration.copyWith (hintText: "Enter your Email" ),
3647 ),
37- SizedBox (
48+ const SizedBox (
3849 height: 8.0 ,
3950 ),
4051 TextField (
52+ keyboardType: TextInputType .visiblePassword,
53+ textAlign: TextAlign .center,
54+ obscureText: true ,
4155 onChanged: (value) {
42- //Do something with the user input.
56+ password = value;
4357 },
4458 decoration: kInputDecoration.copyWith (hintText: "Enter your password" ),
4559 ),
46- SizedBox (
60+ const SizedBox (
4761 height: 24.0 ,
4862 ),
49- Padding (
50- padding: EdgeInsets .symmetric (vertical: 16.0 ),
51- child: Material (
52- color: Colors .blueAccent,
53- borderRadius: BorderRadius .all (Radius .circular (30.0 )),
54- elevation: 5.0 ,
55- child: MaterialButton (
56- onPressed: () {
57- //Implement registration functionality.
58- },
59- minWidth: 200.0 ,
60- height: 42.0 ,
61- child: Text (
62- 'Register' ,
63- style: TextStyle (color: Colors .white),
64- ),
65- ),
66- ),
67- ),
63+ RoundButton (title: 'Register' , color: Colors .blueAccent, onPressed: ()async {
64+ try {
65+ final newUser = await _auth.createUserWithEmailAndPassword (
66+ email: email! , password: password! );
67+ if (newUser != null ){
68+ Navigator .pushNamed (context, ChatScreen .id);
69+ }
70+ }on Error catch (e){
71+ print (e);
72+ }
73+ // print(email);
74+ // print(password);
75+ },),
6876 ],
6977 ),
7078 ),
0 commit comments