Skip to content

Commit

Permalink
Fix select group not applying correct style (#216)
Browse files Browse the repository at this point in the history
* Fix select group not applying correct style

* Commit from GitHub Actions (Forui Presubmit)

* Fix PR issues

* Update forui/lib/src/widgets/select_group/select_group.dart

Co-authored-by: Joe Kawai <[email protected]>

---------

Co-authored-by: Pante <[email protected]>
Co-authored-by: Joe Kawai <[email protected]>
  • Loading branch information
3 people authored Oct 6, 2024
1 parent e9abded commit 3cbcfbf
Show file tree
Hide file tree
Showing 10 changed files with 358 additions and 156 deletions.
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,31 @@ Golden images are generated in the `test/golden` directory instead of relative t

Only the `Inter` font is loaded by default.

### Blue Screen Test

All widgets should have a blue screen test. This uses a special theme that is all blue. It allows us to verify
that custom/inherited themes are being applied correctly. The resultant image should be completely blue if applied
correctly, hence the name.

Example
```dart
testWidgets('blue screen', (tester) async {
await tester.pumpWidget(
TestScaffold.blue( // (1) Always use the TestScaffold.blue(...) constructor.
child: FSelectGroup(
style: TestScaffold.blueScreen.selectGroupStyle, // (2) Always use the TestScaffold.blueScreen theme.
children: [
FSelectGroupItem.checkbox(value: 1),
],
),
),
);
// (3) Always match against blue-screen.png.
await expectLater(find.byType(TestScaffold), matchesGoldenFile('blue-screen.png'));
});
```

### Configuring Golden Test Threshold

By default, `matchesGoldenFile(...)` has a 0.5% threshold. In other words, images that differ by 0.5% or less will be
Expand Down
4 changes: 4 additions & 0 deletions forui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

* **Breaking** Change `FHeaderAction.icon` from `SvgAsset` to `Widget` - wrap the asset in ` FIcon` instead.

* **Breaking** Change `FSelectGroup.builder` parameters.

### Fixes

* Fix `FBottomNavigationBar` items hit region being smaller than intended.
Expand All @@ -66,6 +68,8 @@

* Fix `FCheckbox`, `FRadio`, `FSelectGroup`, `FSwitch` and `FTextField` styles causing the widget inspector to crash.

* Fix `FSelectGroup` not applying correct style if a custom widget-specific style is given.


## 0.5.1

Expand Down
27 changes: 15 additions & 12 deletions forui/lib/src/widgets/select_group/select_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';

import 'package:forui/forui.dart';
import 'package:forui/src/widgets/select_group/select_group_item.dart';

/// A set of items that are treated as a single selection.
///
Expand All @@ -15,7 +16,7 @@ import 'package:forui/forui.dart';
/// * https://forui.dev/docs/select-group for working examples.
/// * [FSelectGroupStyle] for customizing a select group's appearance.
class FSelectGroup<T> extends FormField<Set<T>> {
static Widget _defaultErrorBuilder(BuildContext context, String error) => Text(error);
static Widget _errorBuilder(BuildContext context, String error) => Text(error);

/// The controller.
///
Expand Down Expand Up @@ -46,7 +47,7 @@ class FSelectGroup<T> extends FormField<Set<T>> {
this.style,
this.label,
this.description,
this.errorBuilder = _defaultErrorBuilder,
this.errorBuilder = _errorBuilder,
super.onSaved,
super.validator,
super.initialValue,
Expand All @@ -59,10 +60,10 @@ class FSelectGroup<T> extends FormField<Set<T>> {
builder: (field) {
final state = field as _State;
final groupStyle = style ?? state.context.theme.selectGroupStyle;
final labelState = switch (state) {
_ when !enabled => FLabelState.disabled,
_ when state.errorText != null => FLabelState.error,
_ => FLabelState.enabled,
final (labelState, error) = switch (state.errorText) {
_ when !enabled => (FLabelState.disabled, null),
final text? => (FLabelState.error, errorBuilder(state.context, text)),
null => (FLabelState.enabled, null),
};

return FLabel(
Expand All @@ -71,14 +72,15 @@ class FSelectGroup<T> extends FormField<Set<T>> {
style: groupStyle.labelStyle,
label: label,
description: description,
error: labelState == FLabelState.error ? errorBuilder(state.context, state.errorText!) : null,
error: error,
child: Column(
children: [
for (final item in items)
item.builder(
state.context,
controller.select,
controller.contains(item.value),
for (final child in items)
FSelectGroupItemData<T>(
controller: controller,
style: groupStyle,
selected: controller.contains(child.value),
child: child,
),
],
),
Expand All @@ -96,6 +98,7 @@ class FSelectGroup<T> extends FormField<Set<T>> {
..add(DiagnosticsProperty('style', style))
..add(DiagnosticsProperty('controller', controller))
..add(ObjectFlagProperty.has('errorBuilder', errorBuilder))
..add(DiagnosticsProperty('testing', (1, 2, 3)))
..add(IterableProperty('items', items));
}
}
Expand Down
Loading

0 comments on commit 3cbcfbf

Please sign in to comment.