Skip to content

Instantly share code, notes, and snippets.

@stegrams
Created May 17, 2020 10:55
Show Gist options
  • Save stegrams/f6da091f75fb0705ebe0b1b459b93b48 to your computer and use it in GitHub Desktop.
Save stegrams/f6da091f75fb0705ebe0b1b459b93b48 to your computer and use it in GitHub Desktop.
A minimal form sample with adjustable number of fields.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Form Demo',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Form Demo'),
),
body: SafeArea(
child: Form(
key: _formKey,
autovalidate: true,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
...List.generate(
5,
(i) => TextFormField(
decoration: InputDecoration(
icon: const Icon(Icons.calendar_today),
hintText: 'Please enter something to Field $i',
labelText: 'Field $i',
),
),
),
Container(
constraints: BoxConstraints.expand(height: 55),
margin: const EdgeInsets.all(40.0),
child: RaisedButton(
child: const Text('Submit'),
onPressed: null,
))
],
)))));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment