|
| 1 | +// test_fixes/fix_test.dart |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_form_builder/flutter_form_builder.dart'; |
| 4 | + |
| 5 | +void main() => runApp(const MyApp()); |
| 6 | + |
| 7 | +class MyApp extends StatelessWidget { |
| 8 | + const MyApp({super.key}); |
| 9 | + |
| 10 | + @override |
| 11 | + Widget build(BuildContext context) { |
| 12 | + return MaterialApp( |
| 13 | + title: 'Flutter FormBuilder Example', |
| 14 | + debugShowCheckedModeBanner: false, |
| 15 | + home: const _ExamplePage(), |
| 16 | + ); |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +class _ExamplePage extends StatefulWidget { |
| 21 | + const _ExamplePage(); |
| 22 | + |
| 23 | + @override |
| 24 | + State<_ExamplePage> createState() => _ExamplePageState(); |
| 25 | +} |
| 26 | + |
| 27 | +class _ExamplePageState extends State<_ExamplePage> { |
| 28 | + final _formKey = GlobalKey<FormBuilderState>(); |
| 29 | + |
| 30 | + @override |
| 31 | + Widget build(BuildContext context) { |
| 32 | + return Scaffold( |
| 33 | + appBar: AppBar(title: const Text('Minimal code example')), |
| 34 | + body: Padding( |
| 35 | + padding: const EdgeInsets.all(16), |
| 36 | + child: FormBuilder( |
| 37 | + key: _formKey, |
| 38 | + onPopInvoked: (p0) {}, |
| 39 | + child: Column( |
| 40 | + children: [ |
| 41 | + FormBuilderDateTimePicker( |
| 42 | + name: 'date', |
| 43 | + resetIcon: const Icon(Icons.clear), |
| 44 | + ), |
| 45 | + FormBuilderChoiceChip<String>( |
| 46 | + name: 'choice_chip', |
| 47 | + options: const [ |
| 48 | + 'Option 1', |
| 49 | + 'Option 2', |
| 50 | + 'Option 3', |
| 51 | + ].map((e) => FormBuilderChipOption(value: e)).toList(), |
| 52 | + ), |
| 53 | + FormBuilderFilterChip( |
| 54 | + maxChips: 2, |
| 55 | + decoration: const InputDecoration( |
| 56 | + labelText: 'The language of my people', |
| 57 | + enabled: false, |
| 58 | + ), |
| 59 | + name: 'languages_filter', |
| 60 | + selectedColor: Colors.red, |
| 61 | + options: const [ |
| 62 | + FormBuilderChipOption( |
| 63 | + value: 'Dart', |
| 64 | + avatar: CircleAvatar(child: Text('D')), |
| 65 | + ), |
| 66 | + FormBuilderChipOption( |
| 67 | + value: 'Kotlin', |
| 68 | + avatar: CircleAvatar(child: Text('K')), |
| 69 | + ), |
| 70 | + FormBuilderChipOption( |
| 71 | + value: 'Java', |
| 72 | + avatar: CircleAvatar(child: Text('J')), |
| 73 | + ), |
| 74 | + FormBuilderChipOption( |
| 75 | + value: 'Swift', |
| 76 | + avatar: CircleAvatar(child: Text('S')), |
| 77 | + ), |
| 78 | + FormBuilderChipOption( |
| 79 | + value: 'Objective-C', |
| 80 | + avatar: CircleAvatar(child: Text('O')), |
| 81 | + ), |
| 82 | + ], |
| 83 | + ), |
| 84 | + const SizedBox(height: 10), |
| 85 | + ElevatedButton( |
| 86 | + onPressed: () { |
| 87 | + _formKey.currentState?.saveAndValidate(); |
| 88 | + debugPrint(_formKey.currentState?.value.toString()); |
| 89 | + }, |
| 90 | + child: const Text('Print'), |
| 91 | + ) |
| 92 | + ], |
| 93 | + ), |
| 94 | + ), |
| 95 | + ), |
| 96 | + ); |
| 97 | + } |
| 98 | +} |
0 commit comments