Skip to content

Commit

Permalink
feat: Added ZetaProvider.base to allow for better developer experience
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Jul 2, 2024
1 parent 913662d commit 3cf4719
Show file tree
Hide file tree
Showing 7 changed files with 752 additions and 602 deletions.
42 changes: 42 additions & 0 deletions example/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Set up

To use Zeta components in you app, first the whole app must be wrapped with `ZetaProvider`. The easiest way to do this is with the custom builder `ZetaProvider.custom`.
You can provide initial values for `ThemeData`, `ThemeMode`, `contrast` and `ZetaThemeData`.

* `initialThemeData` allows you to extend an existing Flutter themeData to use alongside the `Zeta` theme.
* `initialThemeMode` sets whether the app starts in light or dark mode, or uses the device default.
* `initialContrast` sets whether the app starts with standard (WCAG AA) contrast, or if it attempts to use the more accessible contrast (WCAG AAA).
* `initialZetaThemeData` allows you to override the Zeta theme with a custom theme.

```dart
return ZetaProvider.base(
initialThemeData: initialThemeData,
initialThemeMode: initialThemeMode,
initialContrast: initialContrast,
initialZetaThemeData: initialZetaThemeData,
initialRounded: initialRounded,
builder: (context, lightTheme, darkTheme, themeMode) {
return MaterialApp.router(
routerConfig: router,
themeMode: themeMode,
theme: lightTheme,
darkTheme: darkTheme,
);
},
);
```

## Using the components

Once Zeta is configured, Zeta components can be used as any other componenent, and will inherit theme and other information from `Zeta`.

```dart
Column(
children:[
ZetaButton(label: 'Button', onPressed: (){}),
ZetaAvatar(),
ZetaStatusLabel(),
// etc...
]
)
```
36 changes: 13 additions & 23 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() async {
runApp(
ZetaExample(
themeService: themeService,
initialThemeData: themePreferences.$1 ?? ZetaThemeData(),
initialZetaThemeData: themePreferences.$1 ?? ZetaThemeData(),
initialThemeMode: themePreferences.$2 ?? ThemeMode.system,
initialContrast: themePreferences.$3 ?? ZetaContrast.aa,
),
Expand All @@ -27,41 +27,31 @@ class ZetaExample extends StatelessWidget {
required this.themeService,
required this.initialContrast,
required this.initialThemeMode,
required this.initialThemeData,
required this.initialZetaThemeData,
});

final ZetaThemeService themeService;
final ZetaContrast initialContrast;
final ThemeMode initialThemeMode;
final ZetaThemeData initialThemeData;
final ZetaThemeData initialZetaThemeData;

@override
Widget build(BuildContext context) {
return ZetaProvider(
themeService: themeService,
final initialThemeData = null;
final initialRounded = true;

return ZetaProvider.base(
initialZetaThemeData: initialZetaThemeData,
initialThemeMode: initialThemeMode,
initialContrast: initialContrast,
initialThemeData: initialThemeData,
initialThemeMode: initialThemeMode,
builder: (context, themeData, themeMode) {
final dark = themeData.colorsDark.toScheme();
final light = themeData.colorsLight.toScheme();
initialRounded: initialRounded,
builder: (context, lightTheme, darkTheme, themeMode) {
return MaterialApp.router(
routerConfig: router,
themeMode: themeMode,
theme: ThemeData(
useMaterial3: true,
fontFamily: themeData.fontFamily,
scaffoldBackgroundColor: light.surfaceTertiary,
colorScheme: light,
textTheme: zetaTextTheme,
),
darkTheme: ThemeData(
useMaterial3: true,
fontFamily: themeData.fontFamily,
scaffoldBackgroundColor: dark.surfaceTertiary,
colorScheme: dark,
textTheme: zetaTextTheme,
),
theme: lightTheme,
darkTheme: darkTheme,
);
},
);
Expand Down
Loading

0 comments on commit 3cf4719

Please sign in to comment.