mirror of
https://github.com/flutter/packages.git
synced 2025-06-29 14:18:54 +08:00
[flutter_adaptive_scaffold] Change selectedIndex
on standardNavigationRail
to allow null value. (#3088)
* changed selectedIndex on standardNavigationRail to allow null value * Update CHANGELOG.md * increase version number * Update CHANGELOG.md * Update CHANGELOG.md * change index types from int to int? * add test for slectedIndex can be set to null * Update CHANGELOG.md * index types set to int? and ensure BottomNavigationRail currentIndex isn't null * Update packages/flutter_adaptive_scaffold/CHANGELOG.md Co-authored-by: Greg Spencer <gspencergoog@users.noreply.github.com> * Update packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart Co-authored-by: Greg Spencer <gspencergoog@users.noreply.github.com> * Update packages/flutter_adaptive_scaffold/CHANGELOG.md Co-authored-by: Greg Spencer <gspencergoog@users.noreply.github.com> Co-authored-by: Greg Spencer <gspencergoog@users.noreply.github.com>
This commit is contained in:
@ -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`
|
||||
|
@ -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.
|
||||
@ -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),
|
||||
@ -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))
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 =
|
||||
@ -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) {
|
||||
@ -110,7 +110,7 @@ enum SimulatedLayout {
|
||||
Size get size => Size(_width, _height);
|
||||
|
||||
MaterialApp app({
|
||||
int initialIndex = 0,
|
||||
int? initialIndex,
|
||||
bool animations = true,
|
||||
}) {
|
||||
return MaterialApp(
|
||||
|
Reference in New Issue
Block a user