Skip to content

Commit

Permalink
NavigationPageThemeData: implement ThemeExtension (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Dec 4, 2022
1 parent 0d6898c commit 6928eaf
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/src/layouts/yaru_navigation_page_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import 'package:flutter/material.dart';
import 'package:yaru/yaru.dart';

@immutable
class NavigationPageThemeData with Diagnosticable {
class NavigationPageThemeData extends ThemeExtension<NavigationPageThemeData>
with Diagnosticable {
/// Creates a theme that can be used with [YaruNavigationPage].
const NavigationPageThemeData({
this.pageTransitions,
Expand All @@ -20,6 +21,7 @@ class NavigationPageThemeData with Diagnosticable {

/// Creates a copy of this object but with the given fields replaced with the
/// new values.
@override
NavigationPageThemeData copyWith({
PageTransitionsTheme? pageTransitions,
}) {
Expand All @@ -28,6 +30,17 @@ class NavigationPageThemeData with Diagnosticable {
);
}

@override
ThemeExtension<NavigationPageThemeData> lerp(
ThemeExtension<NavigationPageThemeData>? other,
double t,
) {
final o = other as NavigationPageThemeData?;
return NavigationPageThemeData(
pageTransitions: t < 0.5 ? pageTransitions : o?.pageTransitions,
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down Expand Up @@ -61,7 +74,9 @@ class YaruNavigationPageTheme extends InheritedTheme {
static NavigationPageThemeData of(BuildContext context) {
final theme =
context.dependOnInheritedWidgetOfExactType<YaruNavigationPageTheme>();
return theme?.data ?? NavigationPageThemeData.fallback();
return theme?.data ??
Theme.of(context).extension<NavigationPageThemeData>() ??
NavigationPageThemeData.fallback();
}

@override
Expand Down

0 comments on commit 6928eaf

Please sign in to comment.