diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 857f82fa02a..e9a4b501f41 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -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. diff --git a/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart b/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart index f3485ae370b..55b77f8152b 100644 --- a/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart +++ b/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart @@ -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 @@ -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; @@ -489,7 +497,8 @@ class _AdaptiveScaffoldState extends State { 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 diff --git a/packages/flutter_adaptive_scaffold/pubspec.yaml b/packages/flutter_adaptive_scaffold/pubspec.yaml index 155e08665b4..809150415d7 100644 --- a/packages/flutter_adaptive_scaffold/pubspec.yaml +++ b/packages/flutter_adaptive_scaffold/pubspec.yaml @@ -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 diff --git a/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart b/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart index 463dd84a0b3..66fe11359ce 100644 --- a/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart +++ b/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart @@ -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 diff --git a/packages/flutter_adaptive_scaffold/test/simulated_layout.dart b/packages/flutter_adaptive_scaffold/test/simulated_layout.dart index daa4214a449..46a8f8f6e5c 100644 --- a/packages/flutter_adaptive_scaffold/test/simulated_layout.dart +++ b/packages/flutter_adaptive_scaffold/test/simulated_layout.dart @@ -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 destinations = [ @@ -75,6 +77,7 @@ class TestScaffoldState extends State { }); }, drawerBreakpoint: NeverOnBreakpoint(), + appBarBreakpoint: widget.appBarBreakpoint, internalAnimations: widget.isAnimated, smallBreakpoint: TestBreakpoint0(), mediumBreakpoint: TestBreakpoint800(), @@ -122,6 +125,7 @@ enum SimulatedLayout { MaterialApp app({ int? initialIndex, bool animations = true, + Breakpoint? appBarBreakpoint, }) { return MaterialApp( theme: ThemeData.light().copyWith( @@ -136,6 +140,7 @@ enum SimulatedLayout { child: TestScaffold( initialIndex: initialIndex, isAnimated: animations, + appBarBreakpoint: appBarBreakpoint, ), ), ); diff --git a/packages/flutter_adaptive_scaffold/test/test_breakpoints.dart b/packages/flutter_adaptive_scaffold/test/test_breakpoints.dart index 5b3c88c3ecd..2a54acd6b5c 100644 --- a/packages/flutter_adaptive_scaffold/test/test_breakpoints.dart +++ b/packages/flutter_adaptive_scaffold/test/test_breakpoints.dart @@ -41,3 +41,10 @@ class NeverOnBreakpoint extends Breakpoint { return false; } } + +class AppBarAlwaysOnBreakpoint extends Breakpoint { + @override + bool isActive(BuildContext context) { + return true; + } +}