Skip to content

Commit

Permalink
BottomNavigationBar: bug fix for dealing with animations with shiftin…
Browse files Browse the repository at this point in the history
…g tabs (flutter#22264)

Should fix flutter#22226.

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

The original issue (flutter#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.
  • Loading branch information
beckler authored and tvolkert committed Nov 7, 2018
1 parent 094f93d commit 9abce96
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bin/internal/goldens.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dd723e291a7997ce6b551b910447b64b3fe9ba7e
8c478bbaf27447f3d612959705b305e7d1293526
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ class _BottomNavigationDemoState extends State<BottomNavigationDemo>
)
];

for (NavigationIconView view in _navigationViews)
view.controller.addListener(_rebuild);

_navigationViews[_currentIndex].controller.value = 1.0;
}

Expand All @@ -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>[];

Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/material/bottom_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,10 @@ 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;
}

if (_backgroundColor != widget.items[widget.currentIndex].backgroundColor)
_backgroundColor = widget.items[widget.currentIndex].backgroundColor;
}

List<Widget> _createTiles() {
Expand Down
51 changes: 51 additions & 0 deletions packages/flutter/test/material/bottom_navigation_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(() {
Expand Down

0 comments on commit 9abce96

Please sign in to comment.