-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a458122
commit 98a5f27
Showing
9 changed files
with
184 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,59 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:widgetbook/widgetbook.dart'; | ||
import 'package:widgetbook_annotation/widgetbook_annotation.dart'; | ||
|
||
class BrightnessAddon extends WidgetbookAddon<Brightness> { | ||
final Brightness initialBrightness; | ||
class WidgetBookBrightness { | ||
static const light = 'light'; | ||
static const dark = 'dark'; | ||
} | ||
|
||
class BrightnessAddon extends WidgetbookAddon<String> { | ||
final String initialBrightness; | ||
|
||
BrightnessAddon({ | ||
this.initialBrightness = Brightness.light, | ||
}) : super(name: 'Brightness'); | ||
this.initialBrightness = WidgetBookBrightness.light, | ||
}) : super(name: 'brightness'); | ||
|
||
@override | ||
Widget buildUseCase( | ||
BuildContext context, | ||
Widget child, | ||
Brightness setting, | ||
String setting, | ||
) { | ||
return Theme( | ||
data: ThemeData( | ||
brightness: setting, | ||
return MediaQuery( | ||
data: MediaQueryData( | ||
platformBrightness: setting == WidgetBookBrightness.light | ||
? Brightness.light | ||
: Brightness.dark, | ||
), | ||
child: child, | ||
); | ||
} | ||
|
||
@override | ||
List<Field<Brightness>> get fields { | ||
List<Field<String>> get fields { | ||
return [ | ||
ListField<Brightness>( | ||
ListField<String>( | ||
name: 'brightness', | ||
initialValue: initialBrightness, | ||
values: [ | ||
Brightness.light, | ||
Brightness.dark, | ||
WidgetBookBrightness.light, | ||
WidgetBookBrightness.dark, | ||
], | ||
) | ||
]; | ||
} | ||
|
||
@override | ||
Brightness valueFromQueryGroup(Map<String, String> group) { | ||
return valueOf<Brightness>('brightness', group)!; | ||
String valueFromQueryGroup(Map<String, String> group) { | ||
return valueOf<String>('brightness', group)!; | ||
} | ||
} | ||
|
||
class BrightnessAddonConfig extends AddonConfig { | ||
const BrightnessAddonConfig(String value) | ||
: super( | ||
'brightness', | ||
'brightness:$value', | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:remix/remix.dart'; | ||
import 'package:remix/themes/fortaleza.dart'; | ||
import 'package:widgetbook/widgetbook.dart'; | ||
import 'package:widgetbook_annotation/widgetbook_annotation.dart'; | ||
|
||
typedef ThemeMultiBrightness = ({RemixThemeData light, RemixThemeData dark}); | ||
|
||
final Map<String, ThemeMultiBrightness> themes = { | ||
'fortaleza': ( | ||
light: FortalezaThemeData.light(), | ||
dark: FortalezaThemeData.dark(), | ||
), | ||
'base': ( | ||
light: RemixThemeData.baseLight(), | ||
dark: RemixThemeData.baseDark(), | ||
), | ||
}; | ||
|
||
class ComponentTheme { | ||
static const fortaleza = 'fortaleza'; | ||
static const base = 'base'; | ||
} | ||
|
||
class ComponentThemeAddon extends WidgetbookAddon<String> { | ||
final String initialBrightness; | ||
|
||
ComponentThemeAddon({ | ||
this.initialBrightness = ComponentTheme.fortaleza, | ||
}) : super(name: 'component theme'); | ||
|
||
@override | ||
Widget buildUseCase( | ||
BuildContext context, | ||
Widget child, | ||
String setting, | ||
) { | ||
final theme = themes[setting]; | ||
return RemixApp( | ||
debugShowCheckedModeBanner: false, | ||
darkTheme: theme!.dark, | ||
theme: theme.light, | ||
home: child, | ||
); | ||
} | ||
|
||
@override | ||
List<Field<String>> get fields { | ||
return [ | ||
ListField<String>( | ||
name: 'brightness', | ||
initialValue: initialBrightness, | ||
values: [ | ||
ComponentTheme.fortaleza, | ||
ComponentTheme.base, | ||
], | ||
) | ||
]; | ||
} | ||
|
||
@override | ||
String valueFromQueryGroup(Map<String, String> group) { | ||
return valueOf<String>('brightness', group)!; | ||
} | ||
} | ||
|
||
class ComponentThemeAddonConfig extends AddonConfig { | ||
const ComponentThemeAddonConfig(String value) | ||
: super('component theme', 'component theme:$value'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.