Skip to content

Commit

Permalink
ADD appBarBreakpoint (#4434)
Browse files Browse the repository at this point in the history
Thsi PR add the ability to display an AppBar on any desired Breakpoint.  It can be usefull to display an AppBar even on a desktop application. 

related to : flutter/flutter#130117
  • Loading branch information
wer-mathurin committed Jul 12, 2023
1 parent a5cfa60 commit 2508714
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_adaptive_scaffold/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.6

* Added support for displaying an AppBar on any Breakpoint by introducing appBarBreakpoint

## 0.1.5

* Added support for Right-to-left (RTL) directionality.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class AdaptiveScaffold extends StatefulWidget {
this.appBar,
this.navigationRailWidth = 72,
this.extendedNavigationRailWidth = 192,
this.appBarBreakpoint,
});

/// The destinations to be used in navigation items. These are converted to
Expand Down Expand Up @@ -215,6 +216,13 @@ class AdaptiveScaffold extends StatefulWidget {
/// Defaults to [Breakpoints.smallDesktop].
final Breakpoint drawerBreakpoint;

/// An optional [Breakpoint] which overrides the [appBar] breakpoint to display
/// an [AppBar] without depending on the drawer visibility.
///
/// By default, an [AppBar] will show on [Breakpoints.smallDesktop] if [useDrawer] is set
/// to true.
final Breakpoint? appBarBreakpoint;

/// Option to override the default [AppBar] when using drawer in desktop
/// small.
final PreferredSizeWidget? appBar;
Expand Down Expand Up @@ -489,7 +497,8 @@ class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
Theme.of(context).navigationRailTheme;

return Scaffold(
appBar: widget.drawerBreakpoint.isActive(context) && widget.useDrawer
appBar: widget.drawerBreakpoint.isActive(context) && widget.useDrawer ||
(widget.appBarBreakpoint?.isActive(context) ?? false)
? widget.appBar ?? AppBar()
: null,
drawer: widget.drawerBreakpoint.isActive(context) && widget.useDrawer
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_adaptive_scaffold/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_adaptive_scaffold
description: Widgets to easily build adaptive layouts, including navigation elements.
version: 0.1.5
version: 0.1.6
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22
repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,29 @@ void main() {
expect(dir, TextDirection.rtl);
},
);

testWidgets(
'when appBarBreakpoint is provided validate an AppBar is showing without Drawer on larger than mobile',
(WidgetTester tester) async {
await tester.binding.setSurfaceSize(SimulatedLayout.medium.size);
await tester.pumpWidget(SimulatedLayout.medium
.app(appBarBreakpoint: AppBarAlwaysOnBreakpoint()));
await tester.pumpAndSettle();

final Finder appBar = find.byType(AppBar);
final Finder drawer = find.byType(Drawer);
expect(appBar, findsOneWidget);
expect(drawer, findsNothing);

await tester.binding.setSurfaceSize(SimulatedLayout.large.size);
await tester.pumpWidget(SimulatedLayout.large
.app(appBarBreakpoint: AppBarAlwaysOnBreakpoint()));
expect(drawer, findsNothing);
await tester.pumpAndSettle();

expect(appBar, findsOneWidget);
},
);
}

/// An empty widget that implements [PreferredSizeWidget] to ensure that
Expand Down
5 changes: 5 additions & 0 deletions packages/flutter_adaptive_scaffold/test/simulated_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ class TestScaffold extends StatefulWidget {
super.key,
this.initialIndex = 0,
this.isAnimated = true,
this.appBarBreakpoint,
});

final int? initialIndex;
final bool isAnimated;
final Breakpoint? appBarBreakpoint;

static const List<NavigationDestination> destinations =
<NavigationDestination>[
Expand Down Expand Up @@ -75,6 +77,7 @@ class TestScaffoldState extends State<TestScaffold> {
});
},
drawerBreakpoint: NeverOnBreakpoint(),
appBarBreakpoint: widget.appBarBreakpoint,
internalAnimations: widget.isAnimated,
smallBreakpoint: TestBreakpoint0(),
mediumBreakpoint: TestBreakpoint800(),
Expand Down Expand Up @@ -122,6 +125,7 @@ enum SimulatedLayout {
MaterialApp app({
int? initialIndex,
bool animations = true,
Breakpoint? appBarBreakpoint,
}) {
return MaterialApp(
theme: ThemeData.light().copyWith(
Expand All @@ -136,6 +140,7 @@ enum SimulatedLayout {
child: TestScaffold(
initialIndex: initialIndex,
isAnimated: animations,
appBarBreakpoint: appBarBreakpoint,
),
),
);
Expand Down
7 changes: 7 additions & 0 deletions packages/flutter_adaptive_scaffold/test/test_breakpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ class NeverOnBreakpoint extends Breakpoint {
return false;
}
}

class AppBarAlwaysOnBreakpoint extends Breakpoint {
@override
bool isActive(BuildContext context) {
return true;
}
}

0 comments on commit 2508714

Please sign in to comment.