Skip to content

Commit

Permalink
Update theme (bdlukaa#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored May 22, 2021
2 parents c1778c9 + 12aa4e5 commit 3429ce2
Show file tree
Hide file tree
Showing 48 changed files with 2,212 additions and 890 deletions.
35 changes: 34 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
Date format: DD/MM/YYYY

## [next]

- Reworked the theme api ([#39](https://github.com/bdlukaa/fluent_ui/pull/39)):
- Removed the theme extension (`context.theme`). Use `FluentTheme.of(context)` instead
- `ButtonState` is now a class that can receive a value. It now allows lerping between values, making `AnimatedFluentTheme` possible.

Here's an example of how to migrate your code:

*Before*: `cursor: (_) => SystemMouseCursors.click,`\
*Now*: `cursor: ButtonState.all(SystemMouseCursors.click),`

- All theme datas and `AccentColor` have now a lerp method, in order to make `AnimatedFluentTheme` possible.
- Implemented `AnimatedFluentTheme`, in order to replace `AnimateContainer`s all around the library
- Dedicated theme for each theme data ([#37](https://github.com/bdlukaa/fluent_ui/issues/37)):
- IconTheme
- ButtonTheme
- RadioButtonTheme
- CheckboxTheme
- FocusTheme
- SplitButtonTheme
- ToggleButtonTheme
- ToggleSwitchTheme
- NavigationPaneTheme
- InfoBarTheme
- TooltipTheme
- DividerTheme
- ScrollbarTheme
- `DividerThemeData` now has `verticalMargin` and `horizontalMargin` instead of an axis callback.
- Updated button colors.
- Removed `animationDuration` and `animationCurve` from theme datas (except from `NavigationPaneThemeData`).
- Renamed `copyWith` to `merge` on theme datas (except from `ThemeData`)
- Fixed typo `standart` -> `standard`

## [2.0.1] - [21/05/2021]

- Minimal flutter version is now 2.2
Expand Down Expand Up @@ -294,7 +327,7 @@ This version provides the fix for [#5](https://github.com/bdlukaa/fluent_ui/issu
- **NEW** `Style.fastAnimationDuration` (Defaults to 150ms)
- **NEW** `Style.mediumAnimationDuration` (Defaults to 300ms)
- **NEW** `Style.slowAnimationDuration` (Defaults to 500ms)
- Default `animationCurve` is now `Curves.easeInOut` (standart) instead of `Curves.linear`
- Default `animationCurve` is now `Curves.easeInOut` (standard) instead of `Curves.linear`
- **BREAKING** Removed `Style.animationDuration`
- Refactored Navigation Panel

Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,11 @@ focusTheme: FocusStyle(
),
```

To customize it to a single widget, wrap the widget in a `FluentTheme` widget, and change the options you want:
To customize it to a single widget, wrap the widget in a `FocusTheme` widget, and change the options you want:

```dart
FluentTheme(
theme: context.theme?.copyWith(ThemeData(
focusStyle: ..., // set your FocusStyle here
)),
FocusTheme(
data: FocusThemeData(...),
child: Button(
text: Text('Custom Focus Button'),
onPressed: () {},
Expand Down Expand Up @@ -577,7 +575,7 @@ SplitButtonBar(
text: Container(
height: 24,
width: 24,
color: context.theme.accentColor,
color: FluentTheme.of(context).accentColor,
),
onPressed: () {},
),
Expand Down
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ class WindowButtons extends StatelessWidget {
iconNormal: theme.inactiveColor,
iconMouseDown: theme.inactiveColor,
iconMouseOver: theme.inactiveColor,
mouseOver: ButtonThemeData.buttonColor(theme, [ButtonStates.hovering]),
mouseDown: ButtonThemeData.buttonColor(theme, [ButtonStates.pressing]),
mouseOver: ButtonThemeData.buttonColor(theme, {ButtonStates.hovering}),
mouseDown: ButtonThemeData.buttonColor(theme, {ButtonStates.pressing}),
);
final closeButtonColors = WindowButtonColors(
mouseOver: Colors.red,
Expand Down
12 changes: 8 additions & 4 deletions example/lib/screens/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class ColorsPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
const Divider divider = const Divider(
style: const DividerThemeData(
verticalMargin: const EdgeInsets.all(10),
horizontalMargin: const EdgeInsets.all(10),
),
);
return ScaffoldPage(
header: PageHeader(title: Text('Colors Showcase')),
content: ListView(
Expand All @@ -41,8 +47,7 @@ class ColorsPage extends StatelessWidget {
}).toList(),
),
),
Divider(
style: DividerThemeData(margin: (axis) => EdgeInsets.all(10))),
divider,
InfoLabel(
label: 'Info Colors',
child: Wrap(
Expand All @@ -59,8 +64,7 @@ class ColorsPage extends StatelessWidget {
],
),
),
Divider(
style: DividerThemeData(margin: (axis) => EdgeInsets.all(10))),
divider,
InfoLabel(
label: 'All Shades',
child:
Expand Down
10 changes: 3 additions & 7 deletions example/lib/screens/inputs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ class _InputsPageState extends State<InputsPage> {
actions: [
Button(
child: Text('Delete'),
autofocus: true,
onPressed: () {
// Delete file here
},
),
Button(
child: Text('Cancel'),
autofocus: true,
onPressed: () => Navigator.pop(context),
),
],
Expand All @@ -161,7 +161,7 @@ class _InputsPageState extends State<InputsPage> {
child: Container(
color: states.isDisabled
? FluentTheme.of(context).accentColor.darker
: context.theme.accentColor,
: FluentTheme.of(context).accentColor,
height: 24,
width: 24,
),
Expand All @@ -172,11 +172,7 @@ class _InputsPageState extends State<InputsPage> {
Button(
child: SizedBox(
height: splitButtonHeight,
child: Icon(
Icons.keyboard_arrow_down,
color:
disabled ? FluentTheme.of(context).disabledColor : null,
),
child: Icon(Icons.keyboard_arrow_down),
),
onPressed: disabled ? null : () {},
style: ButtonThemeData(padding: EdgeInsets.all(6)),
Expand Down
6 changes: 4 additions & 2 deletions example/lib/screens/others.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class _OthersState extends State<Others> {
opacity: 1.0,
elevation: 4.0,
child: Column(children: [
Text('Surfaces', style: context.theme.typography.subtitle),
Text('Surfaces',
style: FluentTheme.of(context).typography.subtitle),
Wrap(spacing: 10, runSpacing: 10, children: [
Tooltip(
message: 'This is a tooltip',
Expand Down Expand Up @@ -181,7 +182,8 @@ class _OthersState extends State<Others> {
Container(
height: 400,
decoration: BoxDecoration(
border: Border.all(color: context.theme.accentColor, width: 1.0),
border: Border.all(
color: FluentTheme.of(context).accentColor, width: 1.0),
),
child: TabView(
currentIndex: currentIndex,
Expand Down
12 changes: 7 additions & 5 deletions example/lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Settings extends StatelessWidget {
),
];
final border = Border.all(color: Colors.grey[100], width: 0.5);
if (context.theme.brightness == Brightness.light) {
if (FluentTheme.of(context).brightness == Brightness.light) {
return BoxDecoration(
color: Colors.white,
borderRadius: radius,
Expand All @@ -60,7 +60,8 @@ class Settings extends StatelessWidget {
),
controller: controller,
children: [
Text('Theme mode', style: context.theme.typography.subtitle),
Text('Theme mode',
style: FluentTheme.of(context).typography.subtitle),
...List.generate(ThemeMode.values.length, (index) {
final mode = ThemeMode.values[index];
return RadioListTile(
Expand All @@ -82,12 +83,12 @@ class Settings extends StatelessWidget {
Text(
'ThemeMode.system may not work because MediaQuery.of(context).brightness is not implemented on windows yet.'
'\nWe must wait until Flutter Desktop stable release',
style: context.theme.typography.caption,
style: FluentTheme.of(context).typography.caption,
),

Text(
'Navigation Pane Display Mode',
style: context.theme.typography.subtitle,
style: FluentTheme.of(context).typography.subtitle,
),
...List.generate(PaneDisplayMode.values.length, (index) {
final mode = PaneDisplayMode.values[index];
Expand All @@ -104,7 +105,8 @@ class Settings extends StatelessWidget {
),
);
}),
Text('Accent Color', style: context.theme.typography.subtitle),
Text('Accent Color',
style: FluentTheme.of(context).typography.subtitle),
Wrap(children: [
Tooltip(
style: tooltipThemeData,
Expand Down
7 changes: 3 additions & 4 deletions lib/fluent_ui.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
library fluent_ui;

export 'package:flutter/widgets.dart'
hide Icon, IconTheme, TextBox, IconThemeData;
export 'package:flutter/widgets.dart' hide TextBox;
export 'package:flutter/material.dart'
show
Brightness,
Expand All @@ -17,7 +16,8 @@ export 'package:flutter/material.dart'
SelectableDayPredicate,
DatePickerMode,
ReorderableListView,
ReorderableDragStartListener;
ReorderableDragStartListener,
kThemeAnimationDuration;

export 'src/app.dart';
export 'src/localization.dart';
Expand Down Expand Up @@ -49,7 +49,6 @@ export 'src/controls/surfaces/list_tile.dart';
export 'src/controls/surfaces/progress_indicators.dart';
export 'src/controls/surfaces/tooltip.dart';

export 'src/controls/utils/icon.dart';
export 'src/controls/utils/divider.dart';
export 'src/controls/utils/scrollbar.dart';

Expand Down
5 changes: 2 additions & 3 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,8 @@ class _FluentAppState extends State<FluentApp> {

Widget _builder(BuildContext context, Widget? child) {
if (child == null) return SizedBox();
final theme = this.theme(context);
return FluentTheme(
data: theme,
return AnimatedFluentTheme(
data: theme(context),
child: child,
);
}
Expand Down
11 changes: 6 additions & 5 deletions lib/src/controls/form/auto_suggest_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ class _AutoSuggestBoxState<T> extends State<AutoSuggestBox<T>> {
widget.onSelected?.call(value);
focusNode.unfocus();
},
title: Text('$value', style: context.maybeTheme?.typography.body),
title:
Text('$value', style: FluentTheme.maybeOf(context)?.typography.body),
);
}

Expand All @@ -180,12 +181,12 @@ class _AutoSuggestBoxState<T> extends State<AutoSuggestBox<T>> {
child: Acrylic(
width: box.size.width,
decoration: BoxDecoration(
color: context.theme.acrylicBackgroundColor,
color: FluentTheme.of(context).acrylicBackgroundColor,
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(4.0),
),
border: Border.all(
color: context.theme.scaffoldBackgroundColor,
color: FluentTheme.of(context).scaffoldBackgroundColor,
width: 0.8,
),
),
Expand All @@ -206,8 +207,8 @@ class _AutoSuggestBoxState<T> extends State<AutoSuggestBox<T>> {
);
}
return AnimatedSwitcher(
duration: context.theme.fastAnimationDuration,
switchInCurve: context.theme.animationCurve,
duration: FluentTheme.of(context).fastAnimationDuration,
switchInCurve: FluentTheme.of(context).animationCurve,
transitionBuilder: (child, animation) {
if (child is ListView) {
return child;
Expand Down
15 changes: 5 additions & 10 deletions lib/src/controls/form/combo_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'pickers/pickers.dart';

const Duration _kComboboxMenuDuration = Duration(milliseconds: 300);
const double _kMenuItemHeight = kPickerHeight;
const EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 16.0);
const EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 12.0);
const EdgeInsetsGeometry _kAlignedButtonPadding = EdgeInsets.only(
top: 4.0,
bottom: 4.0,
Expand Down Expand Up @@ -1364,13 +1364,8 @@ class _ComboboxState<T> extends State<Combobox<T>> with WidgetsBindingObserver {
Expanded(child: innerItemsWidget)
else
innerItemsWidget,
FluentTheme(
data: context.theme.copyWith(
iconTheme: IconThemeData(
color: _iconColor,
size: widget.iconSize,
),
),
IconTheme(
data: IconThemeData(color: _iconColor, size: widget.iconSize),
child: widget.icon ?? defaultIcon,
),
],
Expand All @@ -1390,8 +1385,8 @@ class _ComboboxState<T> extends State<Combobox<T>> with WidgetsBindingObserver {
return Container(
decoration: kPickerDecorationBuilder(context, () {
if (_showHighlight)
return [ButtonStates.focused];
else if (states.isFocused) return <ButtonStates>[];
return {ButtonStates.focused};
else if (states.isFocused) return <ButtonStates>{};
return states;
}()),
child: result,
Expand Down
26 changes: 18 additions & 8 deletions lib/src/controls/form/pickers/date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class _DatePickerState extends State<DatePicker> {
Widget picker = HoverButton(
autofocus: widget.autofocus,
focusNode: widget.focusNode,
cursor: (_) => widget.cursor,
cursor: ButtonState.all(widget.cursor),
onPressed: () async {
await popupKey.currentState?.openPopup();
_monthController?.dispose();
Expand All @@ -192,17 +192,18 @@ class _DatePickerState extends State<DatePicker> {
initControllers();
},
builder: (context, state) {
if (state.isDisabled) state = <ButtonStates>[];
if (state.isDisabled) state = <ButtonStates>{};
final divider = Divider(
direction: Axis.vertical,
style: DividerThemeData(
margin: (_) => EdgeInsets.zero,
verticalMargin: EdgeInsets.zero,
horizontalMargin: EdgeInsets.zero,
thickness: 0.6,
),
);
return AnimatedContainer(
duration: context.theme.fastAnimationDuration,
curve: context.theme.animationCurve,
duration: FluentTheme.of(context).fastAnimationDuration,
curve: FluentTheme.of(context).animationCurve,
height: kPickerHeight,
decoration: kPickerDecorationBuilder(context, state),
child: Row(children: [
Expand Down Expand Up @@ -333,7 +334,10 @@ class __DatePickerContentPopUpState extends State<_DatePickerContentPopUp> {
assert(debugCheckHasFluentTheme(context));
final divider = Divider(
direction: Axis.vertical,
style: DividerThemeData(margin: (_) => EdgeInsets.zero),
style: DividerThemeData(
verticalMargin: EdgeInsets.zero,
horizontalMargin: EdgeInsets.zero,
),
);
return Acrylic(
height: widget.height,
Expand All @@ -350,7 +354,8 @@ class __DatePickerContentPopUpState extends State<_DatePickerContentPopUp> {
alignment: Alignment.center,
height: kOneLineTileHeight,
child: ListTile(
tileColor: context.theme.accentColor.resolveFrom(context),
tileColor:
FluentTheme.of(context).accentColor.resolveFrom(context),
),
),
),
Expand Down Expand Up @@ -538,7 +543,12 @@ class __DatePickerContentPopUpState extends State<_DatePickerContentPopUp> {
]),
]),
),
Divider(style: DividerThemeData(margin: (_) => EdgeInsets.zero)),
Divider(
style: DividerThemeData(
verticalMargin: EdgeInsets.zero,
horizontalMargin: EdgeInsets.zero,
),
),
YesNoPickerControl(
onChanged: () {
Navigator.pop(context);
Expand Down
Loading

0 comments on commit 3429ce2

Please sign in to comment.