Skip to content

[101-2] Making the login page stateful #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions MDC-101/complete/lib/login.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import 'package:flutter/material.dart';

class LoginPage extends StatelessWidget {
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => new _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
final _usernameController = new TextEditingController();
final _passwordController = new TextEditingController();

@override
Widget build(BuildContext context) {
return new Scaffold(
Expand All @@ -17,14 +25,16 @@ class LoginPage extends StatelessWidget {
],
),
const SizedBox(height: 120.0),
const TextField(
new TextField(
controller: _usernameController,
decoration: const InputDecoration(
filled: true,
labelText: 'Username',
),
),
const SizedBox(height: 12.0),
const TextField(
new TextField(
controller: _passwordController,
decoration: const InputDecoration(
filled: true,
labelText: 'Password',
Expand All @@ -35,7 +45,10 @@ class LoginPage extends StatelessWidget {
children: <Widget>[
new FlatButton(
child: const Text('CANCEL'),
onPressed: null,
onPressed: () {
_usernameController.clear();
_passwordController.clear();
},
),
new RaisedButton(
child: const Text('NEXT'),
Expand Down
21 changes: 17 additions & 4 deletions MDC-102/complete/lib/login.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import 'package:flutter/material.dart';

class LoginPage extends StatelessWidget {
class LoginPage extends StatefulWidget {
@override
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is boilerplate and the conventional boilerplate is:

_LoginPageState createState => new _LoginPageState();

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

_LoginPageState createState() => new _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
final _usernameController = new TextEditingController();
final _passwordController = new TextEditingController();

@override
Widget build(BuildContext context) {
return new Scaffold(
Expand All @@ -17,14 +25,16 @@ class LoginPage extends StatelessWidget {
],
),
const SizedBox(height: 120.0),
const TextField(
new TextField(
controller: _usernameController,
decoration: const InputDecoration(
filled: true,
labelText: 'Username',
),
),
const SizedBox(height: 12.0),
const TextField(
new TextField(
controller: _passwordController,
decoration: const InputDecoration(
filled: true,
labelText: 'Password',
Expand All @@ -35,7 +45,10 @@ class LoginPage extends StatelessWidget {
children: <Widget>[
new FlatButton(
child: const Text('CANCEL'),
onPressed: null,
onPressed: () {
_usernameController.clear();
_passwordController.clear();
},
),
new RaisedButton(
child: const Text('NEXT'),
Expand Down