From d57f59d673fceb48a560a0b8fb494d2c38de6262 Mon Sep 17 00:00:00 2001 From: Aliasgar Vohra Date: Sat, 9 Mar 2024 11:03:36 +0530 Subject: [PATCH 1/6] [adaptive_scaffold] : FIX - Drawer stays open even on destination tap (#141938) --- .../flutter_adaptive_scaffold/CHANGELOG.md | 4 ++++ .../lib/src/adaptive_scaffold.dart | 20 ++++++++++++++++++- .../flutter_adaptive_scaffold/pubspec.yaml | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 623da45aaf86..95d306121f24 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.9 + +* FIX : Drawer stays open even on destination tap - [flutter/flutter#41938](https://github.com/flutter/flutter/issues/141938) + ## NEXT * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. diff --git a/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart b/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart index d134f73cb79f..531a088b7943 100644 --- a/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart +++ b/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart @@ -502,12 +502,16 @@ class AdaptiveScaffold extends StatefulWidget { } class _AdaptiveScaffoldState extends State { + // Global scaffold key that will help to manage drawer state. + final GlobalKey _scaffoldKey = GlobalKey(); + @override Widget build(BuildContext context) { final NavigationRailThemeData navRailTheme = Theme.of(context).navigationRailTheme; return Scaffold( + key: _scaffoldKey, appBar: widget.drawerBreakpoint.isActive(context) && widget.useDrawer || (widget.appBarBreakpoint?.isActive(context) ?? false) ? widget.appBar ?? AppBar() @@ -523,7 +527,7 @@ class _AdaptiveScaffoldState extends State { .map((NavigationDestination destination) => AdaptiveScaffold.toRailDestination(destination)) .toList(), - onDestinationSelected: widget.onSelectedIndexChange, + onDestinationSelected: _onDrawerDestinationSelected, ), ) : null, @@ -670,6 +674,20 @@ class _AdaptiveScaffoldState extends State { ), ); } + + void _onDrawerDestinationSelected(int index) { + if (widget.useDrawer) { + // If [useDrawer] is true, then retrieve the current state. + final ScaffoldState? scaffoldCurrentContext = _scaffoldKey.currentState; + if (scaffoldCurrentContext != null) { + if (scaffoldCurrentContext.isDrawerOpen) { + // If drawer is open, call [closeDrawer] to dismiss drawer as per material guidelines. + scaffoldCurrentContext.closeDrawer(); + } + } + } + widget.onSelectedIndexChange?.call(index); + } } class _BrickLayout extends StatelessWidget { diff --git a/packages/flutter_adaptive_scaffold/pubspec.yaml b/packages/flutter_adaptive_scaffold/pubspec.yaml index 6ebf6d894f92..a494b4fc6111 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.8 +version: 0.1.9 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 From ea98de7269a1e701bd04a718dc84d08f130af91e Mon Sep 17 00:00:00 2001 From: Aliasgar Vohra Date: Sat, 9 Mar 2024 11:12:47 +0530 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=9D=20:=20Bug=20Id=20Typo=20fix=20?= =?UTF-8?q?added.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/flutter_adaptive_scaffold/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 95d306121f24..1caf46957b9a 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.1.9 -* FIX : Drawer stays open even on destination tap - [flutter/flutter#41938](https://github.com/flutter/flutter/issues/141938) +* FIX : Drawer stays open even on destination tap - [flutter/flutter#141938](https://github.com/flutter/flutter/issues/141938) ## NEXT From 061b49bafeeeedd7375c6b6f5a6412597b07e6bc Mon Sep 17 00:00:00 2001 From: Aliasgar Vohra Date: Sat, 9 Mar 2024 19:58:26 +0530 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=85=20:=20Test=20case=20added=20for?= =?UTF-8?q?=20drawer=20auto=20dismissal=20upon=20destination=20tap.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/adaptive_scaffold_test.dart | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart b/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart index 3761fbfe29a0..808b03ea1389 100644 --- a/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart +++ b/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart @@ -501,6 +501,119 @@ void main() { }, ); + testWidgets( + 'when drawer item tap, it shall close the already open drawer', + (WidgetTester tester) async { + //region Keys + const ValueKey firstDestinationIconKey = ValueKey( + 'first-normal-icon', + ); + const ValueKey firstDestinationSelectedIconKey = ValueKey( + 'first-selected-icon', + ); + const ValueKey lastDestinationIconKey = ValueKey( + 'last-normal-icon', + ); + const ValueKey lastDestinationSelectedIconKey = ValueKey( + 'last-selected-icon', + ); + //endregion + + //region Finder for destinations as per its icon. + final Finder lastDestinationWithIcon = find.byKey( + lastDestinationIconKey, + ); + final Finder lastDestinationWithSelectedIcon = find.byKey( + lastDestinationSelectedIconKey, + ); + //endregion + + const List destinations = [ + NavigationDestination( + icon: Icon( + Icons.inbox_outlined, + key: firstDestinationIconKey, + ), + selectedIcon: Icon( + Icons.inbox, + key: firstDestinationSelectedIconKey, + ), + label: 'Inbox', + ), + NavigationDestination( + icon: Icon( + Icons.video_call_outlined, + key: lastDestinationIconKey, + ), + selectedIcon: Icon( + Icons.video_call, + key: lastDestinationSelectedIconKey, + ), + label: 'Video', + ), + ]; + int selectedDestination = 0; + + await tester.pumpWidget( + MaterialApp( + home: MediaQuery( + data: const MediaQueryData(size: Size(450, 900)), + child: StatefulBuilder( + builder: ( + BuildContext context, + void Function(void Function()) setState, + ) { + return AdaptiveScaffold( + destinations: destinations, + selectedIndex: selectedDestination, + smallBreakpoint: TestBreakpoint400(), + drawerBreakpoint: TestBreakpoint400(), + onSelectedIndexChange: (int value) { + setState(() { + selectedDestination = value; + }); + }, + ); + }, + ), + ), + ), + ); + + expect(selectedDestination, 0); + Finder fDrawer = find.byType(Drawer); + Finder fNavigationRail = find.descendant( + of: fDrawer, + matching: find.byType(NavigationRail), + ); + expect(fDrawer, findsNothing); + expect(fNavigationRail, findsNothing); + + final ScaffoldState state = tester.state(find.byType(Scaffold)); + state.openDrawer(); + await tester.pumpAndSettle(Durations.short4); + expect(state.isDrawerOpen, isTrue); + + // Need to find again as Scaffold's state has been updated + fDrawer = find.byType(Drawer); + fNavigationRail = find.descendant( + of: fDrawer, + matching: find.byType(NavigationRail), + ); + expect(fDrawer, findsOneWidget); + expect(fNavigationRail, findsOneWidget); + + expect(lastDestinationWithIcon, findsOneWidget); + expect(lastDestinationWithSelectedIcon, findsNothing); + + await tester.ensureVisible(lastDestinationWithIcon); + await tester.tap(lastDestinationWithIcon); + await tester.pumpAndSettle(Durations.short4); + expect(selectedDestination, 1); + expect(state.isDrawerOpen, isFalse); + }, + ); + // This test checks whether AdaptiveScaffold.standardNavigationRail function // creates a NavigationRail widget as expected with groupAlignment provided, // and checks whether the NavigationRail's groupAlignment matches the expected value. From 23c9e390bd0033492c511a79ffba47dd869af2ae Mon Sep 17 00:00:00 2001 From: Aliasgar Vohra Date: Sun, 10 Mar 2024 07:22:49 +0530 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=93=9D=20:=20Authors=20updated.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/flutter_adaptive_scaffold/AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/flutter_adaptive_scaffold/AUTHORS b/packages/flutter_adaptive_scaffold/AUTHORS index 0bbdf210f3c2..f53e3e1620fb 100644 --- a/packages/flutter_adaptive_scaffold/AUTHORS +++ b/packages/flutter_adaptive_scaffold/AUTHORS @@ -4,4 +4,5 @@ # Name/Organization Google Inc. -Jason C.H \ No newline at end of file +Jason C.H +Aliasgar Vohra \ No newline at end of file From d52457bd6e560e30ec452f039330278f854eb33a Mon Sep 17 00:00:00 2001 From: Aliasgar Vohra Date: Thu, 21 Mar 2024 21:58:49 +0530 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=94=96=20:=20Updated=20changelog.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/flutter_adaptive_scaffold/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 1caf46957b9a..9159061ba722 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -2,13 +2,13 @@ * FIX : Drawer stays open even on destination tap - [flutter/flutter#141938](https://github.com/flutter/flutter/issues/141938) -## NEXT +## 0.1.8+1 * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. ## 0.1.8 -* Adds `transitionDuration` parameter for specifying how long the animation should be. +* Adds `transitionDuration` parameter for specifying how long the animation should be. ## 0.1.7+2 From 0a33f89a7c0d6466fdb1cb17a3d4a00d1933a44c Mon Sep 17 00:00:00 2001 From: Aliasgar Vohra Date: Thu, 21 Mar 2024 22:02:35 +0530 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=94=96=20:=20Removed=20unpublished=20?= =?UTF-8?q?version=20change=20logs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/flutter_adaptive_scaffold/CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 9159061ba722..8873f7e26452 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -1,9 +1,6 @@ ## 0.1.9 * FIX : Drawer stays open even on destination tap - [flutter/flutter#141938](https://github.com/flutter/flutter/issues/141938) - -## 0.1.8+1 - * Updates minimum supported SDK version to Flutter 3.13/Dart 3.1. ## 0.1.8