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

Overriding BatThemeData #10

Closed
Mastersam07 opened this issue Apr 23, 2023 · 0 comments · Fixed by #11
Closed

Overriding BatThemeData #10

Mastersam07 opened this issue Apr 23, 2023 · 0 comments · Fixed by #11
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Mastersam07
Copy link
Owner

Overview

With the regular theme instance, we are able to provide our own ThemeData to material app in the format:

theme: ThemeData(),
darkTheme: ThemeData()

Similarly, we can provide the BatThemeData to the Batcave in the format:

theme: BatThemeData(),
darkTheme: BatThemeData()

However, since all properties of BatThemeData are required, one has to provide them. The ideal way is to keep these properties null and copy them with defaults internally. However, this means one has to do a null check while calling properties from BatThemeData which isn't desirable. While the defaults might be returned, there should be no null checks. The flutter framework achieves this by doing:

  static ThemeData of(BuildContext context) {
    final _InheritedTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<_InheritedTheme>();
    final MaterialLocalizations? localizations = Localizations.of<MaterialLocalizations>(context, MaterialLocalizations);
    final ScriptCategory category = localizations?.scriptCategory ?? ScriptCategory.englishLike;
    final ThemeData theme = inheritedTheme?.theme.data ?? _kFallbackTheme;
    return ThemeData.localize(theme, theme.typography.geometryThemeFor(category));
  }

which will always return a ThemeData instance. For us in the BatCave, we have done:

static BatThemeData of(BuildContext context) =>
      Theme.of(context).extension<BatThemeData>()!;

This means no null checks in calling the extensions; however, that doesn't remove the null check on the properties.

Expected behaviour

We should be able to define the theme in the form:

theme: BatThemeData(),
darkTheme: BatThemeData()

We should be able to call properties in the form BatThemeData.of(context).colors.primary as we currently do meaning no breaking change should be expected.

@Mastersam07 Mastersam07 added enhancement New feature or request help wanted Extra attention is needed labels Apr 23, 2023
@Mastersam07 Mastersam07 pinned this issue Apr 23, 2023
@Mastersam07 Mastersam07 linked a pull request Apr 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant