Skip to content

Commit

Permalink
YaruMasterDetailThemeData: implement ThemeExtension interface (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Dec 4, 2022
1 parent a1bade0 commit 959c1c6
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/src/layouts/yaru_master_detail_theme.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:yaru/yaru.dart';
Expand All @@ -6,7 +8,8 @@ import '../constants.dart';

/// Holds theme data for [YaruMasterDetailTheme].
@immutable
class YaruMasterDetailThemeData with Diagnosticable {
class YaruMasterDetailThemeData
extends ThemeExtension<YaruMasterDetailThemeData> with Diagnosticable {
const YaruMasterDetailThemeData({
this.breakpoint,
this.tileSpacing,
Expand Down Expand Up @@ -43,6 +46,7 @@ class YaruMasterDetailThemeData with Diagnosticable {

/// Creates a copy of this object but with the given fields replaced with the
/// new values.
@override
YaruMasterDetailThemeData copyWith({
double? breakpoint,
double? tileSpacing,
Expand All @@ -59,6 +63,23 @@ class YaruMasterDetailThemeData with Diagnosticable {
);
}

@override
ThemeExtension<YaruMasterDetailThemeData> lerp(
ThemeExtension<YaruMasterDetailThemeData>? other,
double t,
) {
final o = other as YaruMasterDetailThemeData?;
return YaruMasterDetailThemeData(
breakpoint: lerpDouble(breakpoint, o?.breakpoint, t),
tileSpacing: lerpDouble(tileSpacing, o?.tileSpacing, t),
listPadding: EdgeInsetsGeometry.lerp(listPadding, o?.listPadding, t),
portraitTransitions:
t < 0.5 ? portraitTransitions : o?.portraitTransitions,
landscapeTransitions:
t < 0.5 ? landscapeTransitions : o?.landscapeTransitions,
);
}

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

@override
Expand Down

0 comments on commit 959c1c6

Please sign in to comment.