Skip to content

Commit

Permalink
Fix tabs (#165)
Browse files Browse the repository at this point in the history
* Fix tabs

* Refactor textfield

* Refactor remaining widgets

* Commit from GitHub Actions (Forui Samples Presubmit)

* Fix failing tests

* Commit from GitHub Actions (Forui Presubmit)

---------

Co-authored-by: Pante <[email protected]>
  • Loading branch information
Pante and Pante authored Aug 21, 2024
1 parent f2c5f02 commit 3d66d2d
Show file tree
Hide file tree
Showing 22 changed files with 214 additions and 250 deletions.
6 changes: 3 additions & 3 deletions docs/pages/docs/divider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ Visually or semantically separates content.
'Blog',
style: typography.sm.copyWith(color: colorScheme.foreground),
),
const FDivider(vertical: true),
const FDivider(axis : Axis.vertical),
Text(
'Docs',
style: typography.sm.copyWith(color: colorScheme.foreground),
),
const FDivider(vertical: true),
const FDivider(axis : Axis.vertical),
Text(
'Source',
style: typography.sm.copyWith(color: colorScheme.foreground),
Expand All @@ -71,5 +71,5 @@ Visually or semantically separates content.
### `FDivider(...)`

```dart
FDivider(vertical: true);
const FDivider(axis : Axis.vertical);
```
6 changes: 6 additions & 0 deletions forui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

* **Breaking:** Rename `FButtonIconStyle.height` to `FButtonIconStyle.size`.

* **Breaking:** Change `FDivider.vertical` to `FDivider.axis`.

* Change `FResizable` to resize by `FResizable.resizePercentage` when using a keyboard.

* **Breaking:** Change `FResiableDividerStyle.thickness` to `FResizableDividerStyle.width`.
Expand All @@ -44,6 +46,8 @@

* **Breaking:** Remove `FTextField.error` - use `FTextField.forceErrorText` instead.

* Change `FTabController` to implement `ChangeNotifier` instead of `Listenable`.

### Fixes

* Fix `FResizable` not rendering properly in an expanded widget when its crossAxisExtent is null.
Expand All @@ -54,6 +58,8 @@

* Fix `FCheckboxStyle.inherit(...)` icon color inheriting from the wrong color.

* Fix `FTabs` not handling indexes properly.


## 0.4.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class FBottomNavigationBar extends StatelessWidget {
}
}

/// AFBottomNavigationBar]'s data.
/// A FBottomNavigationBar]'s data.
class FBottomNavigationBarData extends InheritedWidget {
/// Returns the [FBottomNavigationBarItemStyle] and currently selected index of the [FBottomNavigationBar] in the
/// given [context].
Expand Down
44 changes: 5 additions & 39 deletions forui/lib/src/widgets/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class FCheckbox extends FFormField<bool> {
@override
Widget builder(BuildContext context, FormFieldState<bool> state) {
final style = this.style ?? context.theme.checkboxStyle;
final stateStyle = switch ((enabled, state.hasError)) {
(true, false) => style.enabledStyle,
(false, false) => style.disabledStyle,
(_, true) => style.errorStyle,
final (labelState, stateStyle) = switch ((enabled, state.hasError)) {
(true, false) => (FLabelState.enabled, style.enabledStyle),
(false, false) => (FLabelState.disabled, style.disabledStyle),
(_, true) => (FLabelState.error, style.errorStyle),
};
final value = state.value ?? initialValue;

Expand All @@ -92,11 +92,7 @@ class FCheckbox extends FFormField<bool> {
: null,
child: FLabel(
axis: Axis.horizontal,
state: switch ((enabled, state.hasError)) {
(true, false) => FLabelState.enabled,
(false, false) => FLabelState.disabled,
(_, true) => FLabelState.error,
},
state: labelState,
label: label,
description: description,
error: Text(state.errorText ?? ''),
Expand Down Expand Up @@ -206,21 +202,6 @@ final class FCheckboxStyle with Diagnosticable {
);

/// Returns a copy of this [FCheckboxStyle] with the given properties replaced.
///
/// ```dart
/// final style = FCheckboxStyle(
/// animationDuration: const Duration(minutes: 1),
/// curve: Curves.linear,
/// // Other arguments omitted for brevity.
/// );
///
/// final copy = style.copyWith(
/// curve: Curves.bounceIn,
/// );
///
/// print(style.animationDuration); // const Duration(minutes: 1)
/// print(copy.curve); // Curves.bounceIn
/// ```
@useResult
FCheckboxStyle copyWith({
Duration? animationDuration,
Expand Down Expand Up @@ -296,21 +277,6 @@ final class FCheckboxStateStyle with Diagnosticable {
});

/// Returns a copy of this [FCheckboxStateStyle] with the given properties replaced.
///
/// ```dart
/// final style = FCheckBoxStateStyle(
/// iconColor: ...,
/// checkedBackgroundColor: ...,
/// // Other arguments omitted for brevity.
/// );
///
/// final copy = style.copyWith(
/// checkedBackgroundColor: ...,
/// );
///
/// print(style.iconColor == copy.iconColor); // true
/// print(style.checkedBackgroundColor == copy.checkedBackgroundColor); // false
/// ```
@useResult
FCheckboxStateStyle copyWith({
Color? borderColor,
Expand Down
24 changes: 13 additions & 11 deletions forui/lib/src/widgets/divider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@ final class FDivider extends StatelessWidget {
/// The divider's style. Defaults to the appropriate style in [FThemeData.dividerStyles].
final FDividerStyle? style;

/// True if this divider is vertical. Defaults to false (horizontal).
final bool vertical;
/// The axis. Defaults to horizontal.
final Axis axis;

/// Creates a [FDivider].
const FDivider({this.style, this.vertical = false, super.key});
const FDivider({this.style, this.axis = Axis.horizontal, super.key});

@override
Widget build(BuildContext context) {
final style =
this.style ?? (vertical ? context.theme.dividerStyles.vertical : context.theme.dividerStyles.horizontal);
final (height, width) = vertical ? (null, style.width) : (style.width, null);
final style = this.style ??
switch (axis) {
Axis.horizontal => context.theme.dividerStyles.horizontal,
Axis.vertical => context.theme.dividerStyles.vertical,
};

return Container(
margin: style.padding,
color: style.color,
height: height,
width: width,
height: axis == Axis.horizontal ? style.width : null,
width: axis == Axis.horizontal ? null : style.width,
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(FlagProperty('vertical', value: vertical, defaultValue: false, ifTrue: 'vertical'))
..add(DiagnosticsProperty('style', style));
..add(DiagnosticsProperty('style', style))
..add(EnumProperty('axis', axis));
}
}

Expand Down Expand Up @@ -110,7 +112,7 @@ final class FDividerStyle with Diagnosticable {
/// The padding surrounding the separating line. Defaults to the appropriate padding in [defaultPadding].
final EdgeInsetsGeometry padding;

/// The width of the separating line. Defaults to 1.
/// The width (thickness) of the separating line. Defaults to 1.
///
/// ## Contract
/// Throws [AssertionError] if:
Expand Down
51 changes: 19 additions & 32 deletions forui/lib/src/widgets/progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@ import 'package:forui/forui.dart';
/// * https://forui.dev/docs/progress for working examples.
/// * [FProgressStyle] for customizing a progress's appearance.
class FProgress extends StatelessWidget {
/// The style. Defaults to [FThemeData.progressStyle].
final FProgressStyle? style;

/// If non-null, the value of this progress indicator.
///
/// A value of 0.0 means no progress and 1.0 means that progress is complete.
/// The value will be clamped to be in the range 0.0-1.0.
/// The value will be clamped to be in the range, `[0.0, 1.0]`.
///
/// ## Contract
/// Throws [AssertionError] if:
/// * [value] is NaN
/// Throws [AssertionError] if [value] is NaN
final double value;

/// The style. Defaults to [FThemeData.progressStyle].
final FProgressStyle? style;

/// Creates a [FProgress].
FProgress({
required this.value,
this.style,
super.key,
}) : assert(!value.isNaN, 'Cannot provide a NaN value');
}) : assert(!value.isNaN, 'Cannot provide a NaN value.');

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -68,8 +67,8 @@ class FProgress extends StatelessWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DoubleProperty('value', value))
..add(DiagnosticsProperty('style', style));
..add(DiagnosticsProperty('style', style))
..add(DoubleProperty('value', value));
}
}

Expand Down Expand Up @@ -113,30 +112,7 @@ final class FProgressStyle with Diagnosticable {
animationDuration = const Duration(milliseconds: 500),
curve = Curves.ease;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('progressDecoration', progressDecoration))
..add(DiagnosticsProperty('backgroundDecoration', backgroundDecoration))
..add(DiagnosticsProperty('constraints', constraints))
..add(DiagnosticsProperty('animationDuration', animationDuration))
..add(DiagnosticsProperty('curve', curve));
}

/// Returns a copy of this [FProgressStyle] with the given properties replaced.
///
/// ```dart
/// final style = FProgressStyle(
/// backgroundDecoration: ...,
/// progressDecoration: ...,
/// );
///
/// final copy = style.copyWith(progressDecoration: ...);
///
/// print(style.backgroundDecoration == copy.backgroundDecoration); // true
/// print(style.progressDecoration == copy.progressDecoration); // false
/// ```
@useResult
FProgressStyle copyWith({
BoxDecoration? backgroundDecoration,
Expand All @@ -153,6 +129,17 @@ final class FProgressStyle with Diagnosticable {
curve: curve ?? this.curve,
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('progressDecoration', progressDecoration))
..add(DiagnosticsProperty('backgroundDecoration', backgroundDecoration))
..add(DiagnosticsProperty('constraints', constraints))
..add(DiagnosticsProperty('animationDuration', animationDuration))
..add(DiagnosticsProperty('curve', curve));
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
Expand Down
21 changes: 19 additions & 2 deletions forui/lib/src/widgets/scaffold.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import 'package:meta/meta.dart';

import 'package:forui/forui.dart';

/// A scaffold.
Expand Down Expand Up @@ -62,8 +64,8 @@ class FScaffold extends StatelessWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(FlagProperty('pad', value: contentPad, defaultValue: true, ifTrue: 'pad'))
..add(DiagnosticsProperty('style', style));
..add(DiagnosticsProperty('style', style))
..add(FlagProperty('contentPad', value: contentPad, defaultValue: true, ifTrue: 'pad'));
}
}

Expand Down Expand Up @@ -103,6 +105,21 @@ final class FScaffoldStyle with Diagnosticable {
),
);

/// Returns a copy of this style with the provided properties replaced.
@useResult
FScaffoldStyle copyWith({
Color? backgroundColor,
EdgeInsets? contentPadding,
BoxDecoration? headerDecoration,
BoxDecoration? footerDecoration,
}) =>
FScaffoldStyle(
backgroundColor: backgroundColor ?? this.backgroundColor,
contentPadding: contentPadding ?? this.contentPadding,
headerDecoration: headerDecoration ?? this.headerDecoration,
footerDecoration: footerDecoration ?? this.footerDecoration,
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down
37 changes: 12 additions & 25 deletions forui/lib/src/widgets/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ class FSwitch extends StatelessWidget {
..add(StringProperty('semanticLabel', semanticLabel))
..add(FlagProperty('autofocus', value: autofocus, defaultValue: false, ifTrue: 'autofocus'))
..add(EnumProperty('dragStartBehavior', dragStartBehavior, defaultValue: DragStartBehavior.start))
..add(DiagnosticsProperty('onChange', onChange))
..add(ObjectFlagProperty.has('onChange', onChange))
..add(DiagnosticsProperty('focusNode', focusNode))
..add(DiagnosticsProperty('onFocusChange', onFocusChange))
..add(ObjectFlagProperty.has('onFocusChange', onFocusChange))
..add(ObjectFlagProperty.has('onSave', onSave))
..add(ObjectFlagProperty.has('validator', validator))
..add(DiagnosticsProperty('initialValue', initialValue))
Expand Down Expand Up @@ -203,30 +203,7 @@ final class FSwitchStyle with Diagnosticable {
thumbColor = colorScheme.background,
focusColor = colorScheme.primary;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(ColorProperty('checkedColor', checkedColor))
..add(ColorProperty('uncheckedColor', uncheckedColor))
..add(ColorProperty('thumbColor', thumbColor))
..add(ColorProperty('focusColor', focusColor));
}

/// Returns a copy of this [FSwitchStyle] with the given properties replaced.
///
/// ```dart
/// final style = FSwitchStyle(
/// checkedColor: Colors.black,
/// uncheckedColor: Colors.white,
/// // Other arguments omitted for brevity
/// );
///
/// final copy = style.copyWith(uncheckedColor: Colors.blue);
///
/// print(copy.checkedColor); // black
/// print(copy.uncheckedColor); // blue
/// ```
@useResult
FSwitchStyle copyWith({
Color? checkedColor,
Expand All @@ -241,6 +218,16 @@ final class FSwitchStyle with Diagnosticable {
focusColor: focusColor ?? this.focusColor,
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(ColorProperty('checkedColor', checkedColor))
..add(ColorProperty('uncheckedColor', uncheckedColor))
..add(ColorProperty('thumbColor', thumbColor))
..add(ColorProperty('focusColor', focusColor));
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
Expand Down
Loading

0 comments on commit 3d66d2d

Please sign in to comment.