Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(UX-144): Integrate color tokens #165

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
005f340
chore(UX-1144): Integrate color tokens
invalid-email-address Sep 2, 2024
e63fb24
removed all traces of old colors
invalid-email-address Sep 2, 2024
3ae2001
chore(automated): Lint commit and format
invalid-email-address Sep 2, 2024
a131008
first half of fix for colors
invalid-email-address Sep 4, 2024
59a2d8c
added back color switching
mikecoomber Sep 4, 2024
3b803de
docs: Add color swatch comment template
invalid-email-address Sep 4, 2024
84dd6db
fix: Example app color button
invalid-email-address Sep 4, 2024
6162205
created object for custom theme
mikecoomber Sep 9, 2024
9e0586d
fix errors
mikecoomber Sep 9, 2024
da9304b
fix: Top app bar icon color
invalid-email-address Sep 10, 2024
382b69a
test: Update test goldens
invalid-email-address Sep 11, 2024
9363641
test: start writing tests
invalid-email-address Sep 18, 2024
e59e9ef
chore(automated): Lint commit and format
invalid-email-address Sep 18, 2024
f39d550
wrote and moved tests
mikecoomber Sep 26, 2024
0d3ed25
tidy up test
mikecoomber Sep 26, 2024
110e22c
moved customThemeId to Zeta
mikecoomber Sep 26, 2024
9feb906
chore(automated): Lint commit and format
invalid-email-address Sep 26, 2024
ba6a7e8
zeta didUpdateWidget test
mikecoomber Sep 27, 2024
ba2a380
Merge branch 'UX-144-color' of https://github.com/ZebraDevs/zeta_flut…
mikecoomber Sep 27, 2024
f638b9b
custom theme docs
mikecoomber Sep 27, 2024
98d8a9b
fix: Minor bottom sheet styling problems
mikecoomber Oct 10, 2024
f73085b
color fixes
mikecoomber Oct 11, 2024
61004e6
chore(automated): Lint commit and format
invalid-email-address Oct 14, 2024
ba1c4b1
Merge branch 'main' into UX-144-color
invalid-email-address Oct 15, 2024
6ccd06a
test: Update tests
invalid-email-address Oct 15, 2024
31c07a3
chore(automated): Lint commit and format
invalid-email-address Oct 15, 2024
e21a072
Merge branch 'main' into UX-144-color
invalid-email-address Oct 29, 2024
7d123c4
Merge branch 'main' into UX-144-color
thelukewalton Dec 18, 2024
bc8293b
chore(automated): Lint commit and format
invalid-email-address Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions LICENSE-3RD-PARTY
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.



## Mike Rydstrom

Applies to:
Expand Down
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dart sdk: ">=3.2.0 <4.0.0"
flutter: ">=3.16.0"
```


## Installation

To install `zeta_flutter`, follow the instructions [here](https://pub.dev/packages/zeta_flutter/install).
Expand Down Expand Up @@ -78,7 +79,6 @@ builder: (context, themeData, themeMode) {
To tie everything together, use the `ZetaProvider` constructor. The `builder` argument is mandatory, while the others are optional but allow you to set initial values:

```dart

@override
Widget build(BuildContext context) {
return ZetaProvider(
Expand All @@ -104,6 +104,67 @@ To tie everything together, use the `ZetaProvider` constructor. The `builder` ar
}
```

### Customization

#### Creating custom themes

Custom themes can be made by creating `ZetaCustomTheme` objects. `ZetaCustomTheme` can be constructed by passing in a primary or secondary color and, optionally, their dark variants:

```dart
ZetaCustomTheme(
id: 'custom-theme-red',
primary: Colors.red,
primaryDark : // Dark variant here,
secondary: Colors.blue,
secondaryDark: // Dark variant here,
)
```

Color arguments can be of type `ZetaColorSwatch`, `MaterialColor`, or `Color`. If only a `Color` is provided, Zeta will generate a `ZetaColorSwatch`. <b>To have control over every shade of a given color, we reccomend providing either a `ZetaColorSwatch` or a `MaterialColor`.</b>

If a dark variant of a color is not provided, Zeta generate one by inverting the corresponding color swatch.

#### Adding custom themes

Once you have defined the custom themes for your app, give them to the ZetaProvider by passing them through the construtor. You can also initialize the custom theme by setting the `initialTheme` argument to the id of the desired theme.

```dart
ZetaProvider(
initialTheme: 'custom-theme-red'
customThemes: [
ZetaCustomTheme(
id: 'custom-theme-red',
primary: Colors.red,
secondary: Colors.purple
),
ZetaCustomTheme(
id: 'custom-theme-purple',
primary: Colors.purple,
secondary: Colors.green
),
]
)
```

You can also get and set the custom themes via the `ZetaProvider`:

`ZetaProvider.of(context).customThemes`
`ZetaProvider.of(context).setCustomThemes(newCustomThemes)`

#### Changing the custom theme

To change the custom theme, call the `updateCustomTheme` function on `ZetaProvider` with an id corresponding to a `ZetaCustomTheme` object:

`ZetaProvider.of(context).updateCustomTheme('custom-theme-purple')`

If the id provided does not correspond to a given theme, Zeta will fall back to its default theme.

You can fetch the id of the currently applied custom theme via the `Zeta` object:

`Zeta.of(context).customThemeId`

This will return null if no custom theme is in use.

With these configurations, Zeta makes it easy to achieve consistent theming throughout your Flutter application.

## Licensing
Expand Down
2 changes: 1 addition & 1 deletion custom_docs/components/Color/flutter.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ZetaColors has the following modifiers:
- positive, onPositive, negative, onNegative, warning, onWarning, info, onInfo
- surface, onSurface, surfaceDisabled, surfaceHover, surfaceSecondary, surfaceTertiary, surfaceSelectedHover, surfaceSelected
- background, onBackground
- textDefault, textSubtle, textDisabled, textInverse,
- mainDefault, mainSubtle, mainDisabled, textInverse,
- borderDefault, borderSubtle, borderDisabled, borderSelected,
- white, black
- link, linkVisited,
Expand Down
72 changes: 42 additions & 30 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:zeta_example/theme_service.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import 'home.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

final preferences = await SharedPreferences.getInstance();
final themeService = SharedPrefsThemeService(preferences);
final themePreferences = await themeService.loadTheme();

runApp(
ZetaExample(
themeService: themeService,
initialZetaThemeData: themePreferences.$1 ?? ZetaThemeData(),
initialThemeMode: themePreferences.$2 ?? ThemeMode.system,
initialContrast: themePreferences.$3 ?? ZetaContrast.aa,
),
);
runApp(ZetaExample());
}

class ZetaExample extends StatelessWidget {
const ZetaExample({
super.key,
required this.themeService,
required this.initialContrast,
required this.initialThemeMode,
required this.initialZetaThemeData,
});

final ZetaThemeService themeService;
final ZetaContrast initialContrast;
final ThemeMode initialThemeMode;
final ZetaThemeData initialZetaThemeData;
const ZetaExample({super.key});

@override
Widget build(BuildContext context) {
return ZetaProvider.base(
initialZetaThemeData: initialZetaThemeData,
initialThemeMode: initialThemeMode,
initialContrast: initialContrast,
return ZetaProvider(
// initialContrast: ZetaContrast.aa,
// initialThemeMode: ThemeMode.system,
customThemes: [
ZetaCustomTheme(
id: 'teal',
primary: ZetaPrimitivesLight().teal,
primaryDark: ZetaPrimitivesDark().teal,
secondary: ZetaPrimitivesLight().yellow,
secondaryDark: ZetaPrimitivesDark().yellow,
),
ZetaCustomTheme(
id: 'yellow',
primary: ZetaPrimitivesLight().yellow,
primaryDark: ZetaPrimitivesDark().yellow,
secondary: ZetaPrimitivesLight().red,
secondaryDark: ZetaPrimitivesDark().red,
),
ZetaCustomTheme(
id: 'red',
primary: ZetaPrimitivesLight().red,
primaryDark: ZetaPrimitivesDark().red,
secondary: ZetaPrimitivesLight().purple,
secondaryDark: ZetaPrimitivesDark().purple,
),
ZetaCustomTheme(
id: 'purple',
primary: ZetaPrimitivesLight().purple,
primaryDark: ZetaPrimitivesDark().purple,
secondary: ZetaPrimitivesLight().green,
secondaryDark: ZetaPrimitivesDark().green,
),
ZetaCustomTheme(
id: 'green',
primary: ZetaPrimitivesLight().green,
primaryDark: ZetaPrimitivesDark().green,
secondary: ZetaPrimitivesLight().blue,
secondaryDark: ZetaPrimitivesDark().blue,
),
],
builder: (context, lightTheme, darkTheme, themeMode) {
return MaterialApp.router(
routerConfig: router,
Expand Down
Loading