diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 88f6aa175bd..65d360cc07e 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.1.0 + +* Change the `selectedIndex` parameter on `standardNavigationRail` to allow null values to indicate "no destination". +* An explicitly null `currentIndex` parameter passed to `standardBottomNavigationBar` will also default to 0, just like implicitly null missing parameters. + + ## 0.0.9 * Fix passthrough of `leadingExtendedNavRail`, `leadingUnextendedNavRail` and `trailingNavRail` diff --git a/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart b/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart index e9ec85190c1..8a7e37e8fa0 100644 --- a/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart +++ b/packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart @@ -110,7 +110,7 @@ class AdaptiveScaffold extends StatefulWidget { final List destinations; /// The index to be used by the [NavigationRail]. - final int selectedIndex; + final int? selectedIndex; /// Option to display a leading widget at the top of the navigation rail /// at the middle breakpoint. @@ -251,7 +251,7 @@ class AdaptiveScaffold extends StatefulWidget { static Builder standardNavigationRail({ required List destinations, double width = 72, - int selectedIndex = 0, + int? selectedIndex, bool extended = false, Color backgroundColor = Colors.transparent, EdgeInsetsGeometry padding = const EdgeInsets.all(8.0), @@ -305,14 +305,15 @@ class AdaptiveScaffold extends StatefulWidget { /// a list of [NavigationDestination]s. static Builder standardBottomNavigationBar({ required List destinations, - int currentIndex = 0, + int? currentIndex, double iconSize = 24, ValueChanged? onDestinationSelected, }) { + currentIndex ??= 0; return Builder( builder: (_) { return BottomNavigationBar( - currentIndex: currentIndex, + currentIndex: currentIndex ?? 0, iconSize: iconSize, items: destinations .map((NavigationDestination e) => _toBottomNavItem(e)) diff --git a/packages/flutter_adaptive_scaffold/pubspec.yaml b/packages/flutter_adaptive_scaffold/pubspec.yaml index 33b0353283a..e3fcb67d3e1 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.0.9 +version: 0.1.0 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 36a451ca084..7e3e46b44e4 100644 --- a/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart +++ b/packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_adaptive_scaffold/src/adaptive_scaffold.dart'; import 'package:flutter_test/flutter_test.dart'; + import 'simulated_layout.dart'; import 'test_breakpoints.dart'; @@ -222,6 +223,22 @@ void main() { }); }, ); + + /// Verify that selectedIndex of [AdaptiveScaffold.standardNavigationRail] + /// and [AdaptiveScaffold] can be set to null + testWidgets( + 'adaptive scaffold selectedIndex can be set to null', + (WidgetTester tester) async { + await Future.forEach(SimulatedLayout.values, + (SimulatedLayout region) async { + int? selectedIndex; + final MaterialApp app = region.app(initialIndex: selectedIndex); + await tester.binding.setSurfaceSize(region.size); + await tester.pumpWidget(app); + await tester.pumpAndSettle(); + }); + }, + ); } /// 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 e81a5ff1aac..ae68715cc02 100644 --- a/packages/flutter_adaptive_scaffold/test/simulated_layout.dart +++ b/packages/flutter_adaptive_scaffold/test/simulated_layout.dart @@ -36,7 +36,7 @@ class TestScaffold extends StatefulWidget { this.isAnimated = true, }); - final int initialIndex; + final int? initialIndex; final bool isAnimated; static const List destinations = @@ -63,7 +63,7 @@ class TestScaffold extends StatefulWidget { } class TestScaffoldState extends State { - late int index = widget.initialIndex; + late int? index = widget.initialIndex; @override Widget build(BuildContext context) { @@ -110,7 +110,7 @@ enum SimulatedLayout { Size get size => Size(_width, _height); MaterialApp app({ - int initialIndex = 0, + int? initialIndex, bool animations = true, }) { return MaterialApp(