Navigator.pop before PopupMenuItem onTap call (#127446)
*The order of calling Navigator.pop and PopupMenuItem.onTap has been changed so before calling PopupMenuItem onTap method, PopupMenuBotton onSelect method is going to be called.* *Solves #127443* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
parent
ceeaf98e64
commit
4e9869b925
@ -339,9 +339,10 @@ class PopupMenuItemState<T, W extends PopupMenuItem<T>> extends State<W> {
|
|||||||
/// the menu route.
|
/// the menu route.
|
||||||
@protected
|
@protected
|
||||||
void handleTap() {
|
void handleTap() {
|
||||||
widget.onTap?.call();
|
// Need to pop the navigator first in case onTap may push new route onto navigator.
|
||||||
|
|
||||||
Navigator.pop<T>(context, widget.value);
|
Navigator.pop<T>(context, widget.value);
|
||||||
|
|
||||||
|
widget.onTap?.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -3260,6 +3260,48 @@ void main() {
|
|||||||
final Offset menuTopLeft = tester.getTopLeft(find.bySemanticsLabel('Popup menu'));
|
final Offset menuTopLeft = tester.getTopLeft(find.bySemanticsLabel('Popup menu'));
|
||||||
expect(childBottomLeft, menuTopLeft);
|
expect(childBottomLeft, menuTopLeft);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('PopupmenuItem onTap should be calling after Navigator.pop', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
actions: <Widget>[
|
||||||
|
PopupMenuButton<int>(
|
||||||
|
itemBuilder: (BuildContext context) => <PopupMenuItem<int>>[
|
||||||
|
PopupMenuItem<int>(
|
||||||
|
onTap: () {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return const SizedBox(
|
||||||
|
height: 200.0,
|
||||||
|
child: Center(child: Text('ModalBottomSheet')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
value: 10,
|
||||||
|
child: const Text('ACTION'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.byType(PopupMenuButton<int>));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.text('ACTION'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// Verify that the ModalBottomSheet is displayed
|
||||||
|
final Finder modalBottomSheet = find.text('ModalBottomSheet');
|
||||||
|
expect(modalBottomSheet, findsOneWidget);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestApp extends StatelessWidget {
|
class TestApp extends StatelessWidget {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user