Skip to content

Commit 1555609

Browse files
authored
Fix expanded text field (#680)
* Fix expanded text field * Fix lychee * Prepare Forui for review --------- Co-authored-by: Pante <Pante@users.noreply.github.com>
1 parent 7b70eb7 commit 1555609

File tree

7 files changed

+54
-6
lines changed

7 files changed

+54
-6
lines changed

forui/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ We've added support for animated theme transitions. This should make transitions
2020
* Add `FWidgetStateMap.lerpWhere(...)`.
2121

2222

23+
## Others
24+
* Add `FLabel.expands`.
25+
* Fix `FTextField.expands` causing a render error.
26+
27+
2328
## 0.15.1
2429
* Fix CLI generating incorrect icon mappings.
2530
* Fix CLI generating theme that references private constant.

forui/lib/src/theme/colors.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ final class FColors with Diagnosticable {
155155
this.hoverLighten = 0.075,
156156
this.hoverDarken = 0.05,
157157
this.disabledOpacity = 0.5,
158-
}) : assert(0.0 <= hoverLighten && hoverLighten <= 1.0, 'The hoverLighten must be between 0 and 1.'),
159-
assert(0.0 <= hoverDarken && hoverDarken <= 1.0, 'The hoverDarken must be between 0 and 1.'),
160-
assert(0 <= disabledOpacity && disabledOpacity <= 1, 'The disabledOpacity must be between 0 and 1.');
158+
}) : assert(0.0 <= hoverLighten && hoverLighten <= 1.0, 'hoverLighten must be between 0 and 1.'),
159+
assert(0.0 <= hoverDarken && hoverDarken <= 1.0, 'hoverDarken must be between 0 and 1.'),
160+
assert(0 <= disabledOpacity && disabledOpacity <= 1, 'disabledOpacity must be between 0 and 1.');
161161

162162
/// Creates a linear interpolation between two [FColors] using the given factor [t].
163163
factory FColors.lerp(FColors a, FColors b, double t) => FColors(

forui/lib/src/widgets/label.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ class FLabel extends StatelessWidget {
5656
/// The axis that determines the layout direction.
5757
final Axis axis;
5858

59+
/// Whether the child should expand to fill the available space. Defaults to false.
60+
///
61+
/// ## Contract
62+
/// Only applicable when [axis] is [Axis.vertical].
63+
final bool expands;
64+
5965
/// The label's states.
6066
final Set<WidgetState> states;
6167

@@ -70,9 +76,10 @@ class FLabel extends StatelessWidget {
7076
this.label,
7177
this.description,
7278
this.error,
79+
this.expands = false,
7380
this.states = const {},
7481
super.key,
75-
});
82+
}) : assert(axis == Axis.vertical || !expands, 'expands can only be true when axis is vertical');
7683

7784
@override
7885
Widget build(BuildContext context) {
@@ -100,6 +107,7 @@ class FLabel extends StatelessWidget {
100107
label: label,
101108
description: description,
102109
error: error,
110+
expands: expands,
103111
states: states,
104112
child: child,
105113
),
@@ -111,6 +119,7 @@ class FLabel extends StatelessWidget {
111119
super.debugFillProperties(properties);
112120
properties
113121
..add(EnumProperty('axis', axis))
122+
..add(FlagProperty('expands', value: expands, ifTrue: 'expands'))
114123
..add(IterableProperty('states', states));
115124
}
116125
}
@@ -206,6 +215,7 @@ class _FVerticalLabel extends StatelessWidget {
206215
final Widget? label;
207216
final Widget? description;
208217
final Widget? error;
218+
final bool expands;
209219
final Set<WidgetState> states;
210220
final Widget child;
211221

@@ -214,6 +224,7 @@ class _FVerticalLabel extends StatelessWidget {
214224
required this.label,
215225
required this.description,
216226
required this.error,
227+
required this.expands,
217228
required this.states,
218229
required this.child,
219230
});
@@ -232,7 +243,12 @@ class _FVerticalLabel extends StatelessWidget {
232243
child: label!,
233244
),
234245
),
235-
Padding(padding: style.childPadding, child: child),
246+
if (expands)
247+
Expanded(
248+
child: Padding(padding: style.childPadding, child: child),
249+
)
250+
else
251+
Padding(padding: style.childPadding, child: child),
236252
if (description != null)
237253
Padding(
238254
padding: style.descriptionPadding,
@@ -259,6 +275,7 @@ class _FVerticalLabel extends StatelessWidget {
259275
super.debugFillProperties(properties);
260276
properties
261277
..add(StringProperty('style', style.toString()))
278+
..add(FlagProperty('expands', value: expands, ifTrue: 'expands'))
262279
..add(IterableProperty('states', states));
263280
}
264281
}

forui/lib/src/widgets/text_field/text_field.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ class _State extends State<FTextField> {
11881188
// Error should never be null as doing so causes the widget tree to change. This causes overlays attached to
11891189
// the textfield to fail as it is not smart enough to track the new location of the textfield in the widget tree.
11901190
error: widget.error ?? const SizedBox(),
1191+
expands: widget.expands,
11911192
child: widget.builder(context, style, states, textfield),
11921193
);
11931194

forui/test/src/widgets/label/label_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ import 'package:forui/forui.dart';
66
import '../../test_scaffold.dart';
77

88
void main() {
9+
testWidgets('vertical and expands', (tester) async {
10+
expect(
11+
() => TestScaffold(
12+
child: const FLabel(axis: Axis.vertical, expands: true, child: Text('Child')),
13+
),
14+
returnsNormally,
15+
);
16+
});
17+
18+
testWidgets('horizontal and expands', (tester) async {
19+
expect(
20+
() => TestScaffold(
21+
child: FLabel(axis: Axis.horizontal, expands: true, child: const Text('Child')),
22+
),
23+
throwsAssertionError,
24+
);
25+
});
26+
927
testWidgets('renders child only when label, description, and error are null', (tester) async {
1028
await tester.pumpWidget(
1129
TestScaffold(

forui/test/src/widgets/text_field/text_field_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ void main() {
123123
});
124124
});
125125

126+
testWidgets('expands', (tester) async {
127+
await tester.pumpWidget(TestScaffold.app(child: const FTextField(maxLines: null, expands: true)));
128+
129+
expect(tester.takeException(), null);
130+
});
131+
126132
testWidgets('height does not change due to visual density on different platforms', (tester) async {
127133
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
128134
await tester.pumpWidget(TestScaffold.app(theme: FThemes.zinc.light, child: const FTextField()));

lychee.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ exclude_path = [
1414
]
1515

1616
exclude = [
17-
"https://ux.stackexchange.com/questions/105024/why-dont-button-html-elements-have-a-css-cursor-pointer-by-default"
17+
"https://ux.stackexchange.com/questions/105024/why-dont-button-html-elements-have-a-css-cursor-pointer-by-default",
18+
"https://lucide.dev/icons/"
1819
]

0 commit comments

Comments
 (0)