-
-
Notifications
You must be signed in to change notification settings - Fork 562
Expand file tree
/
Copy pathminimal_code_example.dart
More file actions
77 lines (70 loc) · 2.19 KB
/
minimal_code_example.dart
File metadata and controls
77 lines (70 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter FormBuilder Example',
debugShowCheckedModeBanner: false,
home: const _ExamplePage(),
);
}
}
class _ExamplePage extends StatefulWidget {
const _ExamplePage();
@override
State<_ExamplePage> createState() => _ExamplePageState();
}
class _ExamplePageState extends State<_ExamplePage> {
final _formKey = GlobalKey<FormBuilderState>();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
FormBuilder(
key: _formKey,
child: Column(
children: [
FormBuilderTextField(
name: 'full_name',
decoration: const InputDecoration(labelText: 'Full Name'),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your full name';
}
return null;
},
),
Builder(
builder: (innerContext) {
return Text(
FormBuilder.of(innerContext).isValid
? 'OK Valid'
: 'X Invalid',
);
},
),
const SizedBox(height: 10),
Builder(builder: (innerContext) {
return ElevatedButton(
onPressed: () {
FormBuilder.of(innerContext).saveAndValidate();
debugPrint(
FormBuilder.of(innerContext).value.toString());
},
child: const Text('Print'),
);
}),
],
),
),
],
),
),
);
}
}