Skip to content

Commit

Permalink
initial draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Daviiddoo committed Jun 30, 2024
1 parent 64b3aa4 commit e8a6343
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions forui/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class _ExampleWidgetState extends State<ExampleWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
const FProgress(
value: 0.5,
),
Expanded(
child: FTabs(
tabs: [
Expand Down
1 change: 1 addition & 0 deletions forui/lib/forui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export 'src/widgets/dialog/dialog.dart' hide FDialogContent, FHorizontalDialogCo
export 'src/widgets/header/header.dart';
export 'src/widgets/tabs/tabs.dart';
export 'src/widgets/text_field/text_field.dart';
export 'src/widgets/progress.dart';
export 'src/widgets/scaffold.dart';
export 'src/widgets/separator.dart';
export 'src/widgets/switch.dart';
12 changes: 12 additions & 0 deletions forui/lib/src/theme/theme_data.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:forui/src/widgets/progress.dart';

import 'package:meta/meta.dart';

Expand Down Expand Up @@ -40,6 +41,9 @@ final class FThemeData with Diagnosticable {
/// The header styles.
final FHeaderStyle headerStyle;

/// The progress styles.
final FProgressStyle progressStyle;

/// The tabs styles.
final FTabsStyle tabsStyle;

Expand Down Expand Up @@ -68,6 +72,7 @@ final class FThemeData with Diagnosticable {
required this.cardStyle,
required this.dialogStyle,
required this.headerStyle,
required this.progressStyle,
required this.tabsStyle,
required this.textFieldStyle,
required this.scaffoldStyle,
Expand All @@ -94,6 +99,7 @@ final class FThemeData with Diagnosticable {
cardStyle: FCardStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
dialogStyle: FDialogStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
headerStyle: FHeaderStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
progressStyle: FProgressStyle.inherit(colorScheme: colorScheme),
tabsStyle: FTabsStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
textFieldStyle: FTextFieldStyle.inherit(colorScheme: colorScheme, typography: typography, style: style),
scaffoldStyle: FScaffoldStyle.inherit(colorScheme: colorScheme, style: style),
Expand Down Expand Up @@ -128,6 +134,7 @@ final class FThemeData with Diagnosticable {
FCardStyle? cardStyle,
FDialogStyle? dialogStyle,
FHeaderStyle? headerStyle,
FProgressStyle? progressStyle,
FTabsStyle? tabsStyle,
FTextFieldStyle? textFieldStyle,
FScaffoldStyle? scaffoldStyle,
Expand All @@ -143,6 +150,7 @@ final class FThemeData with Diagnosticable {
cardStyle: cardStyle ?? this.cardStyle,
dialogStyle: dialogStyle ?? this.dialogStyle,
headerStyle: headerStyle ?? this.headerStyle,
progressStyle: progressStyle ?? this.progressStyle,
tabsStyle: tabsStyle ?? this.tabsStyle,
textFieldStyle: textFieldStyle ?? this.textFieldStyle,
scaffoldStyle: scaffoldStyle ?? this.scaffoldStyle,
Expand All @@ -162,11 +170,13 @@ final class FThemeData with Diagnosticable {
..add(DiagnosticsProperty('cardStyle', cardStyle, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('dialogStyle', dialogStyle, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('headerStyle', headerStyle, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty<FProgressStyle>('progressStyle', progressStyle))
..add(DiagnosticsProperty('tabsStyle', tabsStyle, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('textFieldStyle', textFieldStyle, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('scaffoldStyle', scaffoldStyle, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('separatorStyles', separatorStyles, level: DiagnosticLevel.debug))
..add(DiagnosticsProperty('switchStyle', switchStyle, level: DiagnosticLevel.debug));

}

@override
Expand All @@ -182,6 +192,7 @@ final class FThemeData with Diagnosticable {
cardStyle == other.cardStyle &&
dialogStyle == other.dialogStyle &&
headerStyle == other.headerStyle &&
progressStyle == other.progressStyle &&
tabsStyle == other.tabsStyle &&
textFieldStyle == other.textFieldStyle &&
scaffoldStyle == other.scaffoldStyle &&
Expand All @@ -198,6 +209,7 @@ final class FThemeData with Diagnosticable {
cardStyle.hashCode ^
dialogStyle.hashCode ^
headerStyle.hashCode ^
progressStyle.hashCode ^
tabsStyle.hashCode ^
textFieldStyle.hashCode ^
scaffoldStyle.hashCode ^
Expand Down
106 changes: 106 additions & 0 deletions forui/lib/src/widgets/progress.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import 'package:meta/meta.dart';

import 'package:forui/forui.dart';

/// A widget that shows progress along a line.
class FProgress extends StatelessWidget {
/// The style. Defaults to [FThemeData.progressStyle].
final FProgressStyle? style;

/// duration of the animation in milliseconds.
final double? value;

/// Creates a [FProgress].
const FProgress({
this.style,
this.value,
super.key,
});

@override
Widget build(BuildContext context) {
final style = this.style ?? context.theme.progressStyle;
return LinearProgressIndicator(
semanticsLabel: 'Linear FProgress',
semanticsValue: '$value',
backgroundColor: style.backgroundColor,
valueColor: AlwaysStoppedAnimation<Color>(style.progressColor),
value: value,
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties..add(DiagnosticsProperty('style', style))
..add(DoubleProperty('value', value));
}
}

/// [FSwitch]'s style.
final class FProgressStyle with Diagnosticable {
/// The background's color.
final Color backgroundColor;

/// The progress's color.
final Color progressColor;

/// Creates a [FProgressStyle].
const FProgressStyle({
required this.backgroundColor,
required this.progressColor,
});

/// Creates a [FSwitchStyle] that inherits its properties from [colorScheme].
FProgressStyle.inherit({required FColorScheme colorScheme})
: backgroundColor = colorScheme.secondary,
progressColor = colorScheme.primary;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(ColorProperty('backgroundColor', backgroundColor))
..add(ColorProperty('progressColor', progressColor));
}

/// Returns a copy of this [FSwitchStyle] with the given properties replaced.
///
/// ```dart
/// final style = FSwitch(
/// 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
FProgressStyle copyWith({
Color? backgroundColor,
Color? progressColor,
}) =>
FProgressStyle(
backgroundColor: backgroundColor ?? this.backgroundColor,
progressColor: progressColor ?? this.progressColor,
);

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is FProgressStyle &&
runtimeType == other.runtimeType &&
backgroundColor == other.backgroundColor &&
progressColor == other.progressColor;

@override
int get hashCode => backgroundColor.hashCode ^ progressColor.hashCode;
}

0 comments on commit e8a6343

Please sign in to comment.