Skip to content

Commit aa92c59

Browse files
committed
demonstrate orientation horizontal and vertical
1 parent b32fb7b commit aa92c59

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed

example/lib/main.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ class MyApp extends StatelessWidget {
1818

1919
@override
2020
Widget build(BuildContext context) {
21-
return const MaterialApp(
21+
return MaterialApp(
2222
title: 'Flutter FormBuilder Demo',
2323
debugShowCheckedModeBanner: false,
24-
localizationsDelegates: [
24+
localizationsDelegates: const [
2525
FormBuilderLocalizations.delegate,
2626
...GlobalMaterialLocalizations.delegates,
2727
GlobalWidgetsLocalizations.delegate,
2828
],
2929
supportedLocales: FormBuilderLocalizations.supportedLocales,
30-
home: _HomePage(),
30+
theme: ThemeData.light().copyWith(
31+
appBarTheme: const AppBarTheme()
32+
.copyWith(backgroundColor: Colors.blue.shade200)),
33+
home: const _HomePage(),
3134
);
3235
}
3336
}

example/lib/sources/decorated_radio_checkbox.dart

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import 'dart:ui';
2+
13
import 'package:flutter/material.dart';
24
import 'package:flutter_form_builder/flutter_form_builder.dart';
35

6+
/// Demonstrates the use of itemDecorators to wrap a box around selection items
47
class DecoratedRadioCheckbox extends StatefulWidget {
58
const DecoratedRadioCheckbox({Key? key}) : super(key: key);
69

@@ -14,76 +17,114 @@ class _DecoratedRadioCheckboxState extends State<DecoratedRadioCheckbox> {
1417

1518
@override
1619
Widget build(BuildContext context) {
17-
return FormBuilder(
20+
return SingleChildScrollView(
21+
child: FormBuilder(
1822
key: _formKey,
1923
child: Column(
2024
children: <Widget>[
2125
const SizedBox(height: 20),
2226
// this text appears correctly if the textScaler <> 1.0
2327
const Text(
24-
'Checkboxes: control leading - with itemDecoration- label area is a column of Widgets - wrapSpacing 5.0',
28+
'With itemDecoration- label is a column of Widgets - orientation: wrap - wrapSpacing 5.0',
2529
textScaler: TextScaler.linear(1.01)),
2630
FormBuilderCheckboxGroup(
27-
name: 'aCheckboxGroup',
31+
name: 'aCheckboxGroup1',
2832
options: getDemoOptionsWidgets(),
2933
wrapSpacing: 5.0,
3034
itemDecoration: BoxDecoration(
31-
border: Border.all(color: Colors.blueAccent),
35+
color: Colors.orange.shade200,
36+
border: Border.all(color: Colors.blue),
3237
borderRadius: BorderRadius.circular(5.0)),
3338
),
3439
const SizedBox(height: 20),
3540
const Text(
36-
'Checkboxes: control trailing - with itemDecoration - label area is a column of Widgets - wrapSpacing 5.0',
41+
'With itemDecoration - label is a column of Widgets - orientation: wrap - wrapSpacing 5.0',
3742
textScaler: TextScaler.linear(1.01)),
3843
FormBuilderCheckboxGroup(
39-
name: 'aCheckboxGroup',
44+
name: 'aCheckboxGroup2',
4045
options: getDemoOptionsWidgets(),
4146
wrapSpacing: 5.0,
4247
controlAffinity: ControlAffinity.trailing,
4348
itemDecoration: BoxDecoration(
49+
color: Colors.amber.shade200,
4450
border: Border.all(color: Colors.blueAccent),
4551
borderRadius: BorderRadius.circular(5.0)),
4652
),
4753
const SizedBox(height: 20),
4854
const Text(
49-
'Radio: control leading - with itemDecoration - label area is a column of Widgets - wrapSpacing 5.0',
55+
'With itemDecoration - label is a column of Widgets - orientation: wrap - wrapSpacing 5.0',
5056
textScaler: TextScaler.linear(1.01)),
5157
FormBuilderRadioGroup(
52-
name: 'aRadioGroup',
58+
name: 'aRadioGroup1',
5359
options: getDemoOptionsWidgets(),
5460
wrapSpacing: 5.0,
5561
itemDecoration: BoxDecoration(
62+
color: Colors.green.shade200,
5663
border: Border.all(color: Colors.blueAccent),
5764
borderRadius: BorderRadius.circular(5.0)),
5865
),
5966
const SizedBox(height: 20),
6067
const Text(
61-
'Radio: control leading - with itemDecoration - label area just the value - wrapSpacing 10.0',
68+
'With itemDecoration - label is the value - orientation: wrap - wrapSpacing 10.0',
6269
textScaler: TextScaler.linear(1.01)),
6370
FormBuilderRadioGroup(
6471
name: 'aRadioGroup2',
6572
options: getDemoOptions(),
6673
wrapSpacing: 10.0,
6774
itemDecoration: BoxDecoration(
75+
color: Colors.blueGrey.shade200,
6876
border: Border.all(color: Colors.blueAccent),
6977
borderRadius: BorderRadius.circular(5.0)),
7078
),
7179
const SizedBox(height: 20),
7280
const Text(
73-
'Radio: control leading - no itemDecoration - label area just the value - wrapSpacing 10.0',
81+
'No itemDecoration - label is the value - orientation: wrap - wrapSpacing 10.0',
7482
textScaler: TextScaler.linear(1.01)),
75-
7683
FormBuilderRadioGroup(
77-
name: 'aRadioGroup2',
84+
name: 'aRadioGroup3',
7885
options: getDemoOptions(),
7986
wrapSpacing: 10.0,
8087
),
8188
const SizedBox(height: 20),
89+
const SizedBox(height: 20),
90+
const Text(
91+
'With itemDecoration - orientation:horizontal - orientation: horiz - wrapSpacing 5.0',
92+
textScaler: TextScaler.linear(1.01)),
93+
FormBuilderCheckboxGroup(
94+
name: 'aCheckboxGroup3',
95+
options: getDemoOptionsWidgets(),
96+
wrapSpacing: 5.0,
97+
orientation: OptionsOrientation.horizontal,
98+
itemDecoration: BoxDecoration(
99+
gradient:
100+
const LinearGradient(colors: [Colors.red, Colors.white]),
101+
border: Border.all(color: Colors.blueAccent),
102+
borderRadius: BorderRadius.circular(5.0)),
103+
),
104+
const SizedBox(height: 20),
105+
const Text(
106+
'With itemDecoration - orientation:vertical - orientation: vert - wrapSpacing 5.0',
107+
textScaler: TextScaler.linear(1.01)),
108+
FormBuilderCheckboxGroup(
109+
name: 'aCheckboxGroup3',
110+
options: getDemoOptionsWidgets(),
111+
wrapSpacing: 5.0,
112+
orientation: OptionsOrientation.vertical,
113+
itemDecoration: BoxDecoration(
114+
gradient: const LinearGradient(
115+
begin: Alignment.topCenter,
116+
end: Alignment.bottomCenter,
117+
colors: [Colors.red, Colors.white]),
118+
color: Colors.red.shade100,
119+
border: Border.all(color: Colors.blueAccent),
120+
borderRadius: BorderRadius.circular(5.0)),
121+
),
82122
],
83123
),
84-
);
124+
));
85125
}
86126

127+
/// options using column of widgets for the label
87128
List<FormBuilderFieldOption> getDemoOptionsWidgets() {
88129
return const [
89130
FormBuilderFieldOption(
@@ -105,6 +146,7 @@ class _DecoratedRadioCheckboxState extends State<DecoratedRadioCheckbox> {
105146
];
106147
}
107148

149+
/// opens using just values
108150
List<FormBuilderFieldOption> getDemoOptions() {
109151
return const [
110152
FormBuilderFieldOption(

0 commit comments

Comments
 (0)