Skip to content

Commit

Permalink
[adaptive_scaffold] : 🐛 : #110902 : Assertion added when try with les…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
aliasgar4558 committed Mar 21, 2024
1 parent b7fbe68 commit 7cc7e31
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 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.10

* FIX : Assertion added when tried with less than 2 destinations - [flutter/flutter#110902](https://github.com/flutter/flutter/issues/110902)

## 0.1.9

* FIX : Drawer stays open even on destination tap - [flutter/flutter#141938](https://github.com/flutter/flutter/issues/141938)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ class AdaptiveScaffold extends StatefulWidget {
this.navigationRailWidth = 72,
this.extendedNavigationRailWidth = 192,
this.appBarBreakpoint,
});
}) : assert(
destinations.length >= 2,
'At least two destinations are required',
);

/// The destinations to be used in navigation items. These are converted to
/// [NavigationRailDestination]s and [BottomNavigationBarItem]s and inserted
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.9
version: 0.1.10
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 @@ -257,9 +257,9 @@ void main() {
];

await tester.pumpWidget(
const MaterialApp(
MaterialApp(
home: MediaQuery(
data: MediaQueryData(size: Size(700, 900)),
data: const MediaQueryData(size: Size(700, 900)),
child: AdaptiveScaffold(
destinations: destinations,
),
Expand Down Expand Up @@ -717,6 +717,33 @@ void main() {
expect(appBar, findsOneWidget);
},
);

testWidgets(
'When only one destination passed, shall throw assertion error',
(WidgetTester tester) async {
const List<NavigationDestination> destinations = <NavigationDestination>[
NavigationDestination(
icon: Icon(Icons.inbox_outlined),
selectedIcon: Icon(Icons.inbox),
label: 'Inbox',
),
];

expect(
() => tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(size: Size(700, 900)),
child: AdaptiveScaffold(
destinations: destinations,
),
),
),
),
throwsA(isA<AssertionError>()),
);
},
);
}

/// An empty widget that implements [PreferredSizeWidget] to ensure that
Expand Down

0 comments on commit 7cc7e31

Please sign in to comment.