This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Say goReadAFile() is slow and returns a Future | |
| Future myFuture = goReadAFile(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:cloud_firestore/cloud_firestore.dart'; | |
| class PeopleUpsert extends StatefulWidget { | |
| @override | |
| _PeopleUpsertState createState() => _PeopleUpsertState(); | |
| } | |
| class _PeopleUpsertState extends State<PeopleUpsert> { | |
| GlobalKey<FormState> _key = GlobalKey<FormState>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar(title: Text("Prestige Worldwide Registration")), | |
| // TODO 1: Wrap the body in a Form widget | |
| body: Container( | |
| alignment: Alignment.center, | |
| child: Column( | |
| children: <Widget>[ | |
| _buildEmailField, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar(title: Text("Prestige Worldwide Registration")), | |
| // TODO 1: Wrap the body in a Form widget | |
| body: Form( // <-- Add this widget. (Don't forget to close it!) | |
| child: Container( | |
| alignment: Alignment.center, | |
| child: Column( | |
| children: <Widget>[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TODO 2: Add a GlobalKey | |
| @override | |
| Widget build(BuildContext context) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TODO 2: Add a GlobalKey declaration | |
| GlobalKey<FormState> _key = GlobalKey<FormState>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body: Form( | |
| key: _key, // ← Add this line | |
| child: Container( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Without a Form is simpler but... | With a Form is more complex but... | |
|---|---|---|
| You have very little control over the fields | You have lots of control over the fields | |
| Fields are unaware of each other | Field data can be evaluated as a group | |
| Validations are manual so you have to write more code | Validations are easier because they're declarative |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void _doRegister() { | |
| // TODO 3: Add validation and saving here | |
| print(""" | |
| The user has registered with an email address of '${_loginObject['email']}' | |
| and a password of '${_loginObject['password']}' | |
| """); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void _doRegister() { | |
| // TODO 3: Add validation and saving here | |
| // 1 | |
| if (_key.currentState.validate()) { | |
| // Commit the field values to their variables | |
| // 2 | |
| _key.currentState.save(); | |
| // 3 | |
| print(""" | |
| The user has registered with an email address of '${_loginObject['email']}' |