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

Allow overwriting the NavigationAppBar Layout #709

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## next

- The `NavigationAppBar` now allows custom layouts by providing a `builder`. ([#709](https://github.com/bdlukaa/fluent_ui/pull/709))

## 4.2.0

- Flyouts rework ([#690](https://github.com/bdlukaa/fluent_ui/pull/690)):
Expand Down
83 changes: 48 additions & 35 deletions lib/src/controls/navigation/navigation_view/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ class NavigationAppBar with Diagnosticable {
/// The background color of this app bar.
final Color? backgroundColor;

/// An alternative builder, that can be used to override the default AppBar style.
final NavigationAppBarBuilder? builder;

/// Creates a fluent-styled app bar.
const NavigationAppBar({
this.key,
Expand All @@ -767,6 +770,7 @@ class NavigationAppBar with Diagnosticable {
this.automaticallyImplyLeading = true,
this.height = _kDefaultAppBarHeight,
this.backgroundColor,
this.builder,
});

@override
Expand Down Expand Up @@ -842,6 +846,9 @@ class NavigationAppBar with Diagnosticable {
}
}

typedef NavigationAppBarBuilder = Widget Function(BuildContext context,
Widget leading, Widget? additionalLeading, Widget title, Widget? actions);

class _NavigationAppBar extends StatelessWidget {
const _NavigationAppBar({
Key? key,
Expand Down Expand Up @@ -886,42 +893,48 @@ class _NavigationAppBar extends StatelessWidget {
}
}();
late Widget result;
switch (displayMode) {
case PaneDisplayMode.top:
result = Row(children: [
leading,
if (additionalLeading != null) additionalLeading!,
title,
if (appBar.actions != null) Expanded(child: appBar.actions!)
]);
break;
case PaneDisplayMode.minimal:
case PaneDisplayMode.open:
case PaneDisplayMode.compact:
result = Stack(children: [
Align(
alignment: AlignmentDirectional.centerStart,
child: Row(mainAxisSize: MainAxisSize.min, children: [
leading,
if (additionalLeading != null) additionalLeading!,
Flexible(child: title),
]),
),
if (appBar.actions != null)
PositionedDirectional(
start: 0,
end: 0.0,
top: 0.0,
bottom: 0.0,
child: Align(
alignment: AlignmentDirectional.topEnd,
child: appBar.actions!,
),

if (appBar.builder != null) {
result = appBar.builder!(
context, leading, additionalLeading, title, appBar.actions);
} else {
switch (displayMode) {
case PaneDisplayMode.top:
result = Row(children: [
leading,
if (additionalLeading != null) additionalLeading!,
title,
if (appBar.actions != null) Expanded(child: appBar.actions!)
]);
break;
case PaneDisplayMode.minimal:
case PaneDisplayMode.open:
case PaneDisplayMode.compact:
result = Stack(children: [
Align(
alignment: AlignmentDirectional.centerStart,
child: Row(mainAxisSize: MainAxisSize.min, children: [
leading,
if (additionalLeading != null) additionalLeading!,
Flexible(child: title),
]),
),
]);
break;
default:
return const SizedBox.shrink();
if (appBar.actions != null)
PositionedDirectional(
start: 0,
end: 0.0,
top: 0.0,
bottom: 0.0,
child: Align(
alignment: AlignmentDirectional.topEnd,
child: appBar.actions!,
),
),
]);
break;
default:
return const SizedBox.shrink();
}
}
final topPadding = mediaQuery.viewPadding.top;

Expand Down