Skip to content

[flutter_adaptive_scaffold] Change selectedIndex on standardNavigationRail to allow null value. #3088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/flutter_adaptive_scaffold/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class AdaptiveScaffold extends StatefulWidget {
final List<NavigationDestination> 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.
Expand Down Expand Up @@ -251,7 +251,7 @@ class AdaptiveScaffold extends StatefulWidget {
static Builder standardNavigationRail({
required List<NavigationRailDestination> destinations,
double width = 72,
int selectedIndex = 0,
int? selectedIndex,
bool extended = false,
Color backgroundColor = Colors.transparent,
EdgeInsetsGeometry padding = const EdgeInsets.all(8.0),
Expand Down Expand Up @@ -305,14 +305,15 @@ class AdaptiveScaffold extends StatefulWidget {
/// a list of [NavigationDestination]s.
static Builder standardBottomNavigationBar({
required List<NavigationDestination> destinations,
int currentIndex = 0,
int? currentIndex,
double iconSize = 24,
ValueChanged<int>? onDestinationSelected,
}) {
currentIndex ??= 0;
return Builder(
builder: (_) {
return BottomNavigationBar(
currentIndex: currentIndex,
currentIndex: currentIndex ?? 0,
iconSize: iconSize,
items: destinations
.map((NavigationDestination e) => _toBottomNavItem(e))
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.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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter_adaptive_scaffold/test/simulated_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestScaffold extends StatefulWidget {
this.isAnimated = true,
});

final int initialIndex;
final int? initialIndex;
final bool isAnimated;

static const List<NavigationDestination> destinations =
Expand All @@ -63,7 +63,7 @@ class TestScaffold extends StatefulWidget {
}

class TestScaffoldState extends State<TestScaffold> {
late int index = widget.initialIndex;
late int? index = widget.initialIndex;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -110,7 +110,7 @@ enum SimulatedLayout {
Size get size => Size(_width, _height);

MaterialApp app({
int initialIndex = 0,
int? initialIndex,
bool animations = true,
}) {
return MaterialApp(
Expand Down