【Flutter】Scaffoldの中でFormを使いたい

https://pub.dev/packages/form_field_validator

1
2
3
4
5
6
7
8
@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
    title: Text(widget.title),
    ),
    body: Form (
        key: _formKey,

Widget build(BuildContext context)は複数記述できないので、body: Formと書く

そうすると、TextFormFieldが使えるようになる

1
2
3
4
5
6
7
8
9
10
11
12
Padding(
  padding: EdgeInsets.all(10.0),
  child: TextFormField(
    controller: _id_controller,
    style: TextStyle(
        fontSize: 28.0,
        color: const Color(0xffFF0000),
        fontWeight: FontWeight.w400,
        fontFamily:"Roboto"),
    validator: idValidator,
  ),
),