Unverified Commit 18e7549b authored by Hans Muller's avatar Hans Muller Committed by GitHub

Update BottomNavigationBar.didUpdateWidget() (#20890)

BottomNavigationBar's state needs to update _backgroundColor when its configuration changes.
parent 94f9604a
...@@ -415,6 +415,9 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr ...@@ -415,6 +415,9 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
_controllers[oldWidget.currentIndex].reverse(); _controllers[oldWidget.currentIndex].reverse();
_controllers[widget.currentIndex].forward(); _controllers[widget.currentIndex].forward();
} }
if (_backgroundColor != widget.items[widget.currentIndex].backgroundColor)
_backgroundColor = widget.items[widget.currentIndex].backgroundColor;
} }
List<Widget> _createTiles() { List<Widget> _createTiles() {
......
...@@ -712,6 +712,64 @@ void main() { ...@@ -712,6 +712,64 @@ void main() {
expect(find.text('item 2'), findsNothing); expect(find.text('item 2'), findsNothing);
expect(find.text('item 3'), findsNothing); expect(find.text('item 3'), findsNothing);
}); });
testWidgets('BottomNavigationBar change backgroundColor test', (WidgetTester tester) async {
// Regression test for: https://github.com/flutter/flutter/issues/19653
Color _backgroundColor = Colors.red;
await tester.pumpWidget(
new MaterialApp(
home: new StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return new Scaffold(
body: new Center(
child: new RaisedButton(
child: const Text('green'),
onPressed: () {
setState(() {
_backgroundColor = Colors.green;
});
},
),
),
bottomNavigationBar: new BottomNavigationBar(
type: BottomNavigationBarType.shifting,
items: <BottomNavigationBarItem>[
new BottomNavigationBarItem(
title: const Text('Page 1'),
backgroundColor: _backgroundColor,
icon: const Icon(Icons.dashboard),
),
new BottomNavigationBarItem(
title: const Text('Page 2'),
backgroundColor: _backgroundColor,
icon: const Icon(Icons.menu),
),
],
),
);
},
),
),
);
final Finder backgroundMaterial = find.descendant(
of: find.byType(BottomNavigationBar),
matching: find.byWidgetPredicate((Widget w) {
if (w is Material)
return w.type == MaterialType.canvas;
return false;
}),
);
expect(_backgroundColor, Colors.red);
expect(tester.widget<Material>(backgroundMaterial).color, Colors.red);
await tester.tap(find.text('green'));
await tester.pumpAndSettle();
expect(_backgroundColor, Colors.green);
expect(tester.widget<Material>(backgroundMaterial).color, Colors.green);
});
} }
Widget boilerplate({ Widget bottomNavigationBar, @required TextDirection textDirection }) { Widget boilerplate({ Widget bottomNavigationBar, @required TextDirection textDirection }) {
......
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