Commit 9abce96e authored by Michael Beckler's avatar Michael Beckler Committed by Todd Volkert

BottomNavigationBar: bug fix for dealing with animations with shifting tabs (#22264)

Should fix #22226.

Code introduced in #20890 caused a regression that broke color flooding animations in a BottomNavigationBar that has BottomNavigationBarType.shifting.

The original issue (#19653) dealt with background color changes not occurring until another tab was selected. The result is that the background color instantly changes whenever the state changes and when the widget changes, instead of allowing a new widget to animate the background color change.
parent 094f93df
dd723e291a7997ce6b551b910447b64b3fe9ba7e
8c478bbaf27447f3d612959705b305e7d1293526
......@@ -153,9 +153,6 @@ class _BottomNavigationDemoState extends State<BottomNavigationDemo>
)
];
for (NavigationIconView view in _navigationViews)
view.controller.addListener(_rebuild);
_navigationViews[_currentIndex].controller.value = 1.0;
}
......@@ -166,12 +163,6 @@ class _BottomNavigationDemoState extends State<BottomNavigationDemo>
super.dispose();
}
void _rebuild() {
setState(() {
// Rebuild in order to animate views.
});
}
Widget _buildTransitionsStack() {
final List<FadeTransition> transitions = <FadeTransition>[];
......
......@@ -473,11 +473,11 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
}
_controllers[oldWidget.currentIndex].reverse();
_controllers[widget.currentIndex].forward();
}
} else {
if (_backgroundColor != widget.items[widget.currentIndex].backgroundColor)
_backgroundColor = widget.items[widget.currentIndex].backgroundColor;
}
}
List<Widget> _createTiles() {
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'dart:ui';
import 'package:flutter/material.dart';
......@@ -782,6 +783,56 @@ void main() {
expect(tester.widget<Material>(backgroundMaterial).color, Colors.green);
});
testWidgets('BottomNavigationBar shifting backgroundColor with transition', (WidgetTester tester) async {
// Regression test for: https://github.com/flutter/flutter/issues/22226
int _currentIndex = 0;
await tester.pumpWidget(
MaterialApp(
home: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Scaffold(
bottomNavigationBar: RepaintBoundary(
child: BottomNavigationBar(
type: BottomNavigationBarType.shifting,
currentIndex: _currentIndex,
onTap: (int index) {
setState(() {
_currentIndex = index;
});
},
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
title: Text('Red'),
backgroundColor: Colors.red,
icon: Icon(Icons.dashboard),
),
BottomNavigationBarItem(
title: Text('Green'),
backgroundColor: Colors.green,
icon: Icon(Icons.menu),
),
],
),
),
);
},
),
),
);
await tester.tap(find.text('Green'));
for (int pump = 0; pump < 8; pump++) {
await tester.pump(const Duration(milliseconds: 30));
await expectLater(
find.byType(BottomNavigationBar),
matchesGoldenFile('bottom_navigation_bar.shifting_transition.$pump.png'),
skip: !Platform.isLinux,
);
}
});
testWidgets('BottomNavigationBar item title should not be nullable',
(WidgetTester tester) async {
expect(() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment