forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathregister_page.dart
More file actions
99 lines (94 loc) · 2.85 KB
/
register_page.dart
File metadata and controls
99 lines (94 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
final FirebaseAuth _auth = FirebaseAuth.instance;
class RegisterPage extends StatefulWidget {
final String title = 'Registration';
@override
State<StatefulWidget> createState() => RegisterPageState();
}
class RegisterPageState extends State<RegisterPage> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
bool _success;
String _userEmail;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
controller: _emailController,
decoration: InputDecoration(labelText: 'Email'),
validator: (String value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
TextFormField(
controller: _passwordController,
decoration: InputDecoration(labelText: 'Password'),
validator: (String value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
Container(
padding: const EdgeInsets.symmetric(vertical: 16.0),
alignment: Alignment.center,
child: RaisedButton(
onPressed: () async {
if (_formKey.currentState.validate()) {
_register();
}
},
child: const Text('Submit'),
),
),
Container(
alignment: Alignment.center,
child: Text(_success == null
? ''
: (_success
? 'Successfully registered ' + _userEmail
: 'Registration failed')),
)
],
),
),
);
}
@override
void dispose() {
// Clean up the controller when the Widget is disposed
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
// Example code for registration.
void _register() async {
final FirebaseUser user = (await _auth.createUserWithEmailAndPassword(
email: _emailController.text,
password: _passwordController.text,
))
.user;
if (user != null) {
setState(() {
_success = true;
_userEmail = user.email;
});
} else {
_success = false;
}
}
}