Skip to content

Commit 6b39fda

Browse files
authored
Add onReset to form fields (#696)
* Add `onReset` to form fields * Prepare Forui for review --------- Co-authored-by: Pante <[email protected]>
1 parent 0e80daf commit 6b39fda

34 files changed

+162
-12
lines changed

docs/app/docs/form/autocomplete/page.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ FAutocomplete(
5959
hint: 'Type to search countries',
6060
onChange: (value) => print('Selected country: $value'),
6161
onSaved: (value) => print('Saved country: $value'),
62+
onReset: () => print('Reset'),
6263
autovalidateMode: AutovalidateMode.onUserInteraction,
6364
builder: (context, styles, child) => child!,
6465
prefixBuilder: (context, style, states) => Icon(FIcons.globe),
@@ -97,6 +98,7 @@ FAutocomplete.builder(
9798
hint: 'Type to search countries',
9899
onChange: (value) => print('Selected country: $value'),
99100
onSaved: (value) => print('Saved country: $value'),
101+
onReset: () => print('Reset'),
100102
autovalidateMode: AutovalidateMode.onUserInteraction,
101103
builder: (context, styles, child) => child!,
102104
prefixBuilder: (context, style, states) => Icon(FIcons.globe),

docs/app/docs/form/date-field/page.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ FDateField(
8989
enabled: true,
9090
onChange: (date) => print('Date changed: $date'),
9191
onSaved: (date) => print('Date saved: $date'),
92+
onReset: () => print('Reset'),
9293
autovalidateMode: AutovalidateMode.onUnfocus,
9394
forceErrorText: null,
9495
errorBuilder: (context, error) => Text(error, style: TextStyle(color: Colors.red)),

docs/app/docs/form/multi-select/page.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ FMultiSelect<Locale>(
8686
sort: (a, b) => a.compareTo(b),
8787
onChange: (value) => print('Selected country: $value'),
8888
onSaved: (value) => print('Saved country: $value'),
89+
onReset: () => print('Reset'),
8990
autovalidateMode: AutovalidateMode.onUserInteraction,
9091
prefixBuilder: (context, styles) => Icon(FIcons.globe),
9192
suffixBuilder: (context, styles) => Icon(FIcons.arrowDown),
@@ -113,6 +114,7 @@ FMultiSelect<String>.rich(
113114
sort: (a, b) => a.compareTo(b),
114115
onChange: (value) => print('Selected country: $value'),
115116
onSaved: (value) => print('Saved country: $value'),
117+
onReset: () => print('Reset'),
116118
autovalidateMode: AutovalidateMode.onUserInteraction,
117119
prefixBuilder: (context, styles) => Icon(FIcons.globe),
118120
suffixBuilder: (context, styles) => Icon(FIcons.arrowDown),

docs/app/docs/form/select/page.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ FSelect<Locale>(
8484
format: (value) => value.toUpperCase(),
8585
onChange: (value) => print('Selected country: $value'),
8686
onSaved: (value) => print('Saved country: $value'),
87+
onReset: () => print('Reset'),
8788
autovalidateMode: AutovalidateMode.onUserInteraction,
8889
builder: (context, style, state, child) => child,
8990
prefixBuilder: (context, style, states) => Icon(FIcons.globe),
@@ -106,6 +107,7 @@ FSelect<String>.rich(
106107
format: (value) => value.toUpperCase(),
107108
onChange: (value) => print('Selected country: $value'),
108109
onSaved: (value) => print('Saved country: $value'),
110+
onReset: () => print('Reset'),
109111
autovalidateMode: AutovalidateMode.onUserInteraction,
110112
builder: (context, style, state, child) => child,
111113
prefixBuilder: (context, style, states) => Icon(FIcons.globe),

docs/app/docs/form/text-form-field/page.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ FTextFormField(
105105
clearable: (value) => value.text.isNotEmpty,
106106
enabled: true,
107107
onSaved: (value) {},
108+
onReset: () => print('Reset'),
108109
validator: (value) => true,
109110
label: const Text('Email'),
110111
@@ -125,6 +126,7 @@ FTextFormField.email(
125126
clearable: (value) => value.text.isNotEmpty,
126127
enabled: true,
127128
onSaved: (value) {},
129+
onReset: () => print('Reset'),
128130
validator: (value) => true,
129131
label: const Text('Email'),
130132
@@ -145,6 +147,7 @@ FTextFormField.password(
145147
clearable: (value) => value.text.isNotEmpty,
146148
enabled: true,
147149
onSaved: (value) {},
150+
onReset: () => print('Reset'),
148151
validator: (value) => true,
149152
label: const Text('Password'),
150153
hint: 'Enter password',
@@ -166,6 +169,7 @@ FTextFormField.multiline(
166169
clearable: (value) => value.text.isNotEmpty,
167170
enabled: true,
168171
onSaved: (value) {},
172+
onReset: () => print('Reset'),
169173
validator: (value) => true,
170174
label: const Text('Description'),
171175
hint: 'Enter description',

docs/app/docs/form/time-field/page.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ FTimeField(
9797
enabled: true,
9898
onChange: (time) => print('Time changed: $time'),
9999
onSaved: (time) => print('Time saved: $time'),
100+
onReset: () => print('Reset'),
100101
autovalidateMode: AutovalidateMode.onUnfocus,
101102
);
102103
```

docs/app/docs/themes/page.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,32 @@ class FAccordionStyle {
7676
+FAccordionStyle(...)
7777
+FAccordionStyle.inherit(colors, typography, style)
7878
}
79+
80+
class FAccordionMotion {
81+
+FAccordionMotion(...)
82+
}
83+
7984
note for FAccordionStyle "Each Forui widget has a corresponding style.\nWe use FAccordionStyle here as an example."
8085
86+
note for FAccordionMotion "Some Forui widgets have a motion which controls its animation
87+
properties. We use FAccordionMotion here as an example."
88+
8189
FAnimatedTheme --> FThemeData
8290
FThemeData --> FColors
8391
FThemeData --> FTypography
8492
FThemeData --> FStyle
8593
FThemeData --> FAccordionStyle
8694
```
8795

88-
There are **5** core components in Forui's theming system.
96+
There are **6** core components in Forui's theming system.
8997

9098
- **[`FAnimatedTheme`](https://pub.dev/documentation/forui/latest/forui.theme/FAnimatedTheme-class.html)**: The root widget that provides the theme data to all widgets in the subtree.
9199
- **[`FThemeData`](https://pub.dev/documentation/forui/latest/forui.theme/FThemeData-class.html)**: Main class that holds:
92100
- **[`FColors`](https://pub.dev/documentation/forui/latest/forui.theme/FColors-class.html)**: Color scheme including primary, foreground, and background colors.
93101
- **[`FTypography`](https://pub.dev/documentation/forui/latest/forui.theme/FTypography-class.html)**: Typography settings including font family and text styles.
94102
- **[`FStyle`](https://pub.dev/documentation/forui/latest/forui.theme/FStyle-class.html)**: Misc. options such as border radius and icon size.
95-
- **Individual widget styles**.
103+
- Individual widget styles.
104+
- Individual widget motions.
96105

97106

98107
The included `BuildContext` extension allows `FThemeData` can be accessed via [`context.theme`](https://pub.dev/documentation/forui/latest/forui.theme/FThemeBuildContext.html):

forui/CHANGELOG.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ We've improved the styles' generated documentation. They should be much easier t
66

77

88
### `FAccordion`
9-
109
* Add `FAccordionMotion`.
10+
1111
* **Breaking** Move animation related fields from `FAccordionStyle` to `FAccordionMoton`.
1212

1313

1414
### `FAutocomplete`
15-
15+
* Add `FAutocomplete.onReset`.
1616
* Add `FAutocompletController(popoverMotion: ...)`.
17+
1718
* **Breaking** Change `FAutocompleteContentStyle.loadingIndicatorStyle` to `FAutocompleteContentStyle.progressStyle`.
1819

1920

2021
### `FDateField`
22+
* Add `FDateField.onReset`.
2123

2224
* **Breaking** Replace `FDateFieldController(animationDuration: ...)` with `FDateFieldController(popoverMotion: ...)`.
2325

@@ -32,9 +34,14 @@ We've improved the styles' generated documentation. They should be much easier t
3234
* **Breaking** Move animation related fields from `FDialogStyle` to `FDialogMotion`.
3335

3436

35-
### `FPopover` & `FPopoverMenu`
37+
### `FFormField`
38+
* **Breaking** Add `FFormField(onReset: ...)`.
39+
* **Breaking** Add `FFormFieldProperties(onReset: ...)`.
40+
3641

42+
### `FPopover` & `FPopoverMenu`
3743
* Add `FPopoverMotion`.
44+
3845
* Change default animations to be more subtle.
3946
* **Breaking** Replace `FPopoverController(animationDuration: ...)` with `FPopoverController(motion: ...)`.
4047
* **Breaking** Change `FPopoverMenu.hideRegion`'s default value from `FHidePopoverRegion.anywhere` to `FHidePopoverRegion.excludeChild`.
@@ -48,19 +55,33 @@ We've reworked `FProgress` to be more customizable and easier to use.
4855
* Add `FInheritedCircularProgressStyle`.
4956
* Add `FDeterminateProgress` which represents determinate linear progress.
5057
* Add `FDeterminateProgressStyle`.
58+
5159
* **Breaking** Change `FProgress` to represent indeterminate linear progress.
5260
* **Breaking** Remove `FProgressStyles`.
5361

5462

5563
### `FSelect` & `FMultiSelect`
64+
* Add `FSelect.onReset`.
65+
* Add `FMultiSelect.onReset`.
5666

5767
* **Breaking** Rename `FSelectSearchStyle.loadingIndicatorStyle` to `FSelectSearchStyle.progressStyle`.
5868
* **Breaking** Replace `FSelectController(animationDuration: ...)` with `FSelectController(popoverMotion: ...)`.
5969
* **Breaking** Replace `FMultiSelectController(animationDuration: ...)` with `FMultiSelectController(popoverMotion: ...)`.
6070

6171

62-
### `FSheet`
72+
### `FSelectGroup`
73+
* Add `FSelectGroup.onReset`.
74+
75+
76+
### `FSelectMenuTile`
77+
* Add `FSelectMenuTile.onReset`.
78+
79+
80+
### `FSelectTileGroup`
81+
* Add `FSelectTileGroup.onReset`.
82+
6383

84+
### `FSheet`
6485
* Add `FModalSheetStyle`.
6586
* Add `FPersistentSheetStyle`.
6687
* Add `FSheetMotion`.
@@ -74,25 +95,24 @@ We've reworked `FProgress` to be more customizable and easier to use.
7495

7596

7697
### `FSidebar`
77-
7898
* Add `FSidebarItemMotion`.
99+
79100
* **Breaking** Move animation related fields from `FSiderbarItemStyle` to `FSiderbarItemMotion`.
80101

81102

82103
### `FSlider`
83-
104+
* Add `FSlider.onReset`.
84105
* Add `FSliderStyle.tooltipMotion`.
85106

86107

87108
### `FTab`
88-
89109
* Add `FTabMotion`.
90110
* **Breaking** Replace `FTabController(animationDuration: ...)` with `FTabController(motion: ...)`.
91111

92112

93113
### `FTappable`
94-
95114
* Add `FTappableMotion`.
115+
96116
* **Breaking** Move animation related fields from `FTappableStyle` to `FTappableMotion`.
97117

98118

@@ -101,22 +121,24 @@ We've added a password visibility toggle to password fields.
101121

102122
* Add password visibility toggle to `FTextField.password(...)`.
103123
* Add password visibility toggle to `FTextFormField.password(...)`.
124+
* Add `FTextFormField.onReset`.
104125

105126

106127
### `FThemeData`
107128
We've added support for animated theme transitions. This should make transitions between themes gradual instead of abrupt.
108129

109130
* Add `FThemeData.lerp(...)`.
131+
110132
* Change `FThemeData.copyWith(...)` to accept style builder functions.
111133

112134

113135
### `FTimeField`
136+
* Add `FTimeField.onReset`.
114137

115138
* **Breaking** Replace `FTimeFieldController(animationDuration: ...)` with `FTimeFieldController(popoverMotion: ...)`.
116139

117140

118141
### `FToast`
119-
120142
* Add `FToastMotion`.
121143
* Add `FToasterMotion`.
122144

@@ -128,8 +150,8 @@ We've added support for animated theme transitions. This should make transitions
128150

129151

130152
### `FTooltip`
131-
132153
* Add `FTooltipMotion`.
154+
133155
* **Breaking** Replace `FTooltipController(animationDuration: ...)` with `FTooltipController(motion: ...)`.
134156

135157

@@ -143,12 +165,14 @@ We've added support for animated theme transitions. This should make transitions
143165

144166
### `FToaster`
145167
* Add `FToaster.of(...)`.
168+
146169
* Make `FToasterState.show(context: ...)` optional.
147170

148171

149172
## Others
150173
* Add `FImmutableTween`.
151174
* Add `FLabel.expands`.
175+
152176
* Fix `FTextField.expands` causing a render error.
153177

154178

forui/lib/src/foundation/form_field.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Field<T> extends FormField<T> {
1111
required super.autovalidateMode,
1212
required super.forceErrorText,
1313
required super.onSaved,
14+
required super.onReset,
1415
required super.validator,
1516
required T? initialValue,
1617
required super.builder,

forui/lib/src/foundation/form_field_properties.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ mixin FFormFieldProperties<T> {
3131
/// {@endtemplate}
3232
FormFieldSetter<T>? get onSaved;
3333

34+
/// {@template forui.foundation.form_field_properties.onReset}
35+
/// An optional method to call when the form field is reset via [FormFieldState.reset].
36+
/// {@endtemplate}
37+
VoidCallback? get onReset;
38+
3439
/// {@template forui.foundation.form_field_properties.validator}
3540
/// An optional method that validates an input. Returns an error string to
3641
/// display if the input is invalid, or null otherwise.

0 commit comments

Comments
 (0)