Skip to content

Commit 7cc7e31

Browse files
authored
[adaptive_scaffold] : 🐛 : #110902 : Assertion added when try with less that 2 destinations. (#6360)
*Issue : flutter/flutter#110902 Changes included in PR are listed as follows - As `NavigationRail` & `NavigationBar` etc has assertion which won't allow less than 2 destinations, Similar assertion added in "AdaptiveScaffold" to acknowledge users regarding the same with a user friendly message. - CHANGELOG.md file updated. - Updated to v0.1.10
1 parent b7fbe68 commit 7cc7e31

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

packages/flutter_adaptive_scaffold/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.10
2+
3+
* FIX : Assertion added when tried with less than 2 destinations - [flutter/flutter#110902](https://github.com/flutter/flutter/issues/110902)
4+
15
## 0.1.9
26

37
* FIX : Drawer stays open even on destination tap - [flutter/flutter#141938](https://github.com/flutter/flutter/issues/141938)

packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class AdaptiveScaffold extends StatefulWidget {
103103
this.navigationRailWidth = 72,
104104
this.extendedNavigationRailWidth = 192,
105105
this.appBarBreakpoint,
106-
});
106+
}) : assert(
107+
destinations.length >= 2,
108+
'At least two destinations are required',
109+
);
107110

108111
/// The destinations to be used in navigation items. These are converted to
109112
/// [NavigationRailDestination]s and [BottomNavigationBarItem]s and inserted

packages/flutter_adaptive_scaffold/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_adaptive_scaffold
22
description: Widgets to easily build adaptive layouts, including navigation elements.
3-
version: 0.1.9
3+
version: 0.1.10
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22
55
repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold
66

packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ void main() {
257257
];
258258

259259
await tester.pumpWidget(
260-
const MaterialApp(
260+
MaterialApp(
261261
home: MediaQuery(
262-
data: MediaQueryData(size: Size(700, 900)),
262+
data: const MediaQueryData(size: Size(700, 900)),
263263
child: AdaptiveScaffold(
264264
destinations: destinations,
265265
),
@@ -717,6 +717,33 @@ void main() {
717717
expect(appBar, findsOneWidget);
718718
},
719719
);
720+
721+
testWidgets(
722+
'When only one destination passed, shall throw assertion error',
723+
(WidgetTester tester) async {
724+
const List<NavigationDestination> destinations = <NavigationDestination>[
725+
NavigationDestination(
726+
icon: Icon(Icons.inbox_outlined),
727+
selectedIcon: Icon(Icons.inbox),
728+
label: 'Inbox',
729+
),
730+
];
731+
732+
expect(
733+
() => tester.pumpWidget(
734+
MaterialApp(
735+
home: MediaQuery(
736+
data: const MediaQueryData(size: Size(700, 900)),
737+
child: AdaptiveScaffold(
738+
destinations: destinations,
739+
),
740+
),
741+
),
742+
),
743+
throwsA(isA<AssertionError>()),
744+
);
745+
},
746+
);
720747
}
721748

722749
/// An empty widget that implements [PreferredSizeWidget] to ensure that

0 commit comments

Comments
 (0)