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

YaruMasterDetailThemeData: implement ThemeExtension interface #450

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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