Update BottomNavigationBar.didUpdateWidget() (#20890)
BottomNavigationBar's state needs to update _backgroundColor when its configuration changes.
This commit is contained in:
parent
94f9604a96
commit
18e7549bc8
@ -415,6 +415,9 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
|
||||
_controllers[oldWidget.currentIndex].reverse();
|
||||
_controllers[widget.currentIndex].forward();
|
||||
}
|
||||
|
||||
if (_backgroundColor != widget.items[widget.currentIndex].backgroundColor)
|
||||
_backgroundColor = widget.items[widget.currentIndex].backgroundColor;
|
||||
}
|
||||
|
||||
List<Widget> _createTiles() {
|
||||
|
@ -712,6 +712,64 @@ void main() {
|
||||
expect(find.text('item 2'), 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 }) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user