Unverified Commit a5863932 authored by Markus Aksli's avatar Markus Aksli Committed by GitHub

ignore `Scaffold` drawer callbacks when value doesn't change (#92329)

parent d2cea643
......@@ -1960,17 +1960,21 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
bool get isEndDrawerOpen => _endDrawerOpened.value;
void _drawerOpenedCallback(bool isOpened) {
setState(() {
_drawerOpened.value = isOpened;
});
widget.onDrawerChanged?.call(isOpened);
if (_drawerOpened.value != isOpened) {
setState(() {
_drawerOpened.value = isOpened;
});
widget.onDrawerChanged?.call(isOpened);
}
}
void _endDrawerOpenedCallback(bool isOpened) {
setState(() {
_endDrawerOpened.value = isOpened;
});
widget.onEndDrawerChanged?.call(isOpened);
if (_endDrawerOpened.value != isOpened) {
setState(() {
_endDrawerOpened.value = isOpened;
});
widget.onEndDrawerChanged?.call(isOpened);
}
}
/// Opens the [Drawer] (if any).
......
......@@ -50,6 +50,40 @@ void main() {
expect(false, isEndDrawerOpen);
});
testWidgets('Scaffold drawer callback test - only call when changed', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/87914
bool onDrawerChangedCalled = false;
bool onEndDrawerChangedCalled = false;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
drawer: Container(
color: Colors.blue,
),
onDrawerChanged: (bool isOpen) {
onDrawerChangedCalled = true;
},
endDrawer: Container(
color: Colors.green,
),
onEndDrawerChanged: (bool isOpen) {
onEndDrawerChangedCalled = true;
},
body: Container(),
),
));
await tester.flingFrom(Offset.zero, const Offset(10.0, 0.0), 10.0);
expect(false, onDrawerChangedCalled);
await tester.pumpAndSettle();
final double width = tester.getSize(find.byType(MaterialApp)).width;
await tester.flingFrom(Offset(width - 1, 0.0), const Offset(-10.0, 0.0), 10.0);
await tester.pumpAndSettle();
expect(false, onEndDrawerChangedCalled);
});
testWidgets('Scaffold control test', (WidgetTester tester) async {
final Key bodyKey = UniqueKey();
Widget boilerplate(Widget child) {
......
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