Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Introduce YaruTheme widget #150

Merged
merged 2 commits into from
Apr 21, 2022
Merged

Conversation

jpnurmi
Copy link
Member

@jpnurmi jpnurmi commented Apr 21, 2022

The YaruTheme widget applies the Yaru theme to its descendants.

MaterialApp(
  home: YaruTheme(
    child: ...
  ),
)

The YaruTheme widget detects the appropriate flavor and accent color from the system on Linux, and defaults to YaruFlavor.ubuntu and YaruAccent.orange on other platforms. Applications may choose a specific flavor and accent color by manually setting the accent and flavor properties, respectively.

YaruTheme(
  accent: YaruAccent.red,
  flavor: YaruFlavor.ubuntu,
  child: ...
)

The following video illustrates how the example app that has been modified to use the YaruTheme widget, follows the system accent color by default until the application explicitly overrides the accent color with a specific color chosen by the user.

inherited-theme.mp4

jpnurmi added 2 commits April 21, 2022 09:07
The `YaruTheme` widget detects the appropriate flavor and accent color
from the system, and applies the appropriate Yaru theme to its
descendants.

```dart
MaterialApp(
  home: YaruTheme(
    child: ...
  ),
)
```

Applications may choose a specific flavor and accent color by manually
setting the `accent` and `flavor` properties, respectively.

```dart
YaruTheme(
  accent: YaruAccent.red,
  flavor: YaruFlavor.ubuntu,
  child: ...
)
```
@jpnurmi
Copy link
Member Author

jpnurmi commented Apr 21, 2022

As mentioned above, YaruTheme automatically detects the appropriate flavor and accent from the system on Linux.

On other platforms, a plain YaruTheme widget with its defaults corresponds to passing yaruLight, yaruDark, yaruHighContrastLight, and yaruHighContrastDark to MaterialApp.

MaterialApp(
  home: YaruTheme(
    child: MyHomePage()
  ),
)

vs.

MaterialApp(
  theme: yaruLight,
  darkTheme: yaruDark,
  highContrastTheme: yaruHighContrastLight,
  highContrastDarkTheme: yaruHighContrastDark,
  home: MyHomePage(),
)

@jpnurmi
Copy link
Member Author

jpnurmi commented Apr 21, 2022

Web-compatible:

inherited-theme-web.mp4

@Feichtmeier
Copy link
Member

Very nice solution for all platforms! 👍 🥂

@Feichtmeier Feichtmeier merged commit 95eb716 into ubuntu:main Apr 21, 2022
@jpnurmi jpnurmi deleted the inherited-theme branch April 21, 2022 07:38
jpnurmi added a commit to jpnurmi/yaru.dart that referenced this pull request Apr 21, 2022
A last minute tweak in ubuntu#150 to check for the platform was forgotten in
tests...
Feichtmeier pushed a commit that referenced this pull request Apr 21, 2022
* Fix tests

A last minute tweak in #150 to check for the platform was forgotten in
tests...

* CI: enable tests
@Feichtmeier Feichtmeier mentioned this pull request May 9, 2022
@ebraminio
Copy link

ebraminio commented Jun 6, 2022

Hi. Sorry for being a bit off topic here, in material-foundation/material-dynamic-color-flutter#42 and material-foundation/material-dynamic-color-flutter#43 I've implemented something for material-dynamic-color that can retrieve system accent color of Windows and macOS and now for the Linux one material-foundation/flutter-packages#336 maybe you can help to make the Gtk one happen there, or maybe we can have a shared package providing basic parts of retrieving system accent color so both packages can enjoy it. Thanks!

@jpnurmi
Copy link
Member Author

jpnurmi commented Jun 6, 2022

Hi @ebraminio, sounds interesting! It might be best to implement that one in C/C++ because the plugin is not federated and it might be nice to avoid pulling in such dependencies as gsettings.dart and dbus.dart for all platforms.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants