Skip to content

Instantly share code, notes, and snippets.

View rapPayne's full-sized avatar
:octocat:
Working from home

Rap Payne rapPayne

:octocat:
Working from home
View GitHub Profile
// Say goReadAFile() is slow and returns a Future
Future myFuture = goReadAFile();
@rapPayne
rapPayne / PersonUpsert.dart
Last active October 16, 2019 20:25
Flutter/Firebase person upsert form
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>();
@rapPayne
rapPayne / Register.dart
Last active September 24, 2020 17:31
Medium - Flutter Forms Ultimate Guide 1 adding a form
@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,
@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>[
@rapPayne
rapPayne / Register.dart
Created September 24, 2020 17:54
Before adding a GlobalKey
// TODO 2: Add a GlobalKey
@override
Widget build(BuildContext context) {
@rapPayne
rapPayne / Register.dart
Last active September 24, 2020 17:58
Adding a GlobalKey for the Form
// TODO 2: Add a GlobalKey declaration
GlobalKey<FormState> _key = GlobalKey<FormState>();
@rapPayne
rapPayne / Register.dart
Created September 24, 2020 18:02
Adding the key to the Form widget
body: Form(
key: _key, // ← Add this line
child: Container(
@rapPayne
rapPayne / WhyUseAForm.csv
Last active October 21, 2020 18:48
Why use a form?
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
@rapPayne
rapPayne / Register.dart
Created October 21, 2020 19:15
_doRegister before saving
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']}'
""");
}
@rapPayne
rapPayne / Register.dart
Created October 21, 2020 21:16
_doRegister after saving
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']}'