Skip to content

Commit

Permalink
Implemented SignUp Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
zubair-khanzada committed Oct 22, 2019
1 parent 3d79909 commit f06b87d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
27 changes: 22 additions & 5 deletions lib/auth/signup.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_scaffold/models/user.dart';

class SignUp extends StatefulWidget {
@override
Expand All @@ -7,7 +8,7 @@ class SignUp extends StatefulWidget {

class _SignUpState extends State<SignUp> {
final _formKey = GlobalKey<FormState>();

final User user = User();
@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -27,6 +28,11 @@ class _SignUpState extends State<SignUp> {
}
return null;
},
onSaved: (value) {
setState(() {
user.username = value;
});
},
decoration: InputDecoration(
hintText: 'Enter Username',
labelText: 'Username',
Expand All @@ -42,6 +48,11 @@ class _SignUpState extends State<SignUp> {
}
return null;
},
onSaved: (value) {
setState(() {
user.email = value;
});
},
decoration: InputDecoration(
hintText: 'Enter Email',
labelText: 'Email',
Expand All @@ -57,10 +68,15 @@ class _SignUpState extends State<SignUp> {
}
return null;
},
decoration: InputDecoration(
hintText: 'Enter Password',
labelText: 'Password',
),
onSaved: (value) {
setState(() {
user.password = value;
});
},
decoration: InputDecoration(
hintText: 'Enter Password',
labelText: 'Password',
),
obscureText: true
),
),
Expand Down Expand Up @@ -90,6 +106,7 @@ class _SignUpState extends State<SignUp> {
if (_formKey.currentState.validate()) {
// If the form is valid, display a snackbar. In the real world,
// you'd often call a server or save the information in a database.
print(user);
}
},
),
Expand Down
8 changes: 5 additions & 3 deletions lib/models/user.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class User {
String name;
String username;
User({this.name, this.username});
String email;
String password;
User({this.username, this.email, this.password});
factory User.fromJson(Map<String, dynamic> json) {
return User(
name: json['name'],
username: json['username'],
email: json['email'],
password: json['password']
);
}
}
Expand Down

0 comments on commit f06b87d

Please sign in to comment.