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

YaruDetailPage: allow specifying the hero tag #553

Merged
merged 4 commits into from
Jan 20, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/src/layouts/yaru_detail_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';

const _kYaruDetailPageHeroTag = '<YaruDetailPageHeroTag>';

/// Provides the recommended layout for [YaruMasterDetailPage.pageBuilder].
///
/// This widget is similar to [Scaffold] with the exception that it wraps the
Expand All @@ -19,6 +21,7 @@ class YaruDetailPage extends StatelessWidget {
this.backgroundColor,
this.extendBody = false,
this.extendBodyBehindAppBar = false,
this.heroTag = _kYaruDetailPageHeroTag,
});

/// See [Scaffold.extendBody].
Expand Down Expand Up @@ -57,13 +60,23 @@ class YaruDetailPage extends StatelessWidget {
/// See [Scaffold.bottomSheet].
final Widget? bottomSheet;

/// The tag to use for the [Hero] wrapping the [appBar].
///
/// By default, a unique tag is used to ensure that the [appBar] stays in
/// place during page transitions. If set to `null`, no [Hero] will be used.
final Object? heroTag;

PreferredSizeWidget? _buildAppBar(BuildContext context) {
if (appBar == null) return null;
if (appBar == null ||
heroTag == null ||
context.findAncestorWidgetOfExactType<Hero>() != null) {
return appBar;
}

return PreferredSize(
preferredSize: appBar!.preferredSize,
child: Hero(
tag: '<YaruDetailPage Hero tag - $appBar>',
tag: heroTag!,
child: appBar!,
),
);
Expand Down