Unverified Commit a63ed4e3 authored by jslavitz's avatar jslavitz Committed by GitHub

Scaffold drawer fix (#23689)

* Adds drawer state query functions
parent 8de86d41
......@@ -1045,6 +1045,22 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
bool _drawerOpened = false;
bool _endDrawerOpened = false;
/// Whether the [Scaffold.drawer] is opened.
///
/// See also:
///
/// * [ScaffoldState.openDrawer], which opens the [Scaffold.drawer] of a
/// [Scaffold].
bool get isDrawerOpen => _drawerOpened;
/// Whether the [Scaffold.endDrawer] is opened.
///
/// See also:
///
/// * [ScaffoldState.openEndDrawer], which opens the [Scaffold.endDrawer] of
/// a [Scaffold].
bool get isEndDrawerOpen => _endDrawerOpened;
void _drawerOpenedCallback(bool isOpened) {
setState(() {
_drawerOpened = isOpened;
......
......@@ -998,8 +998,60 @@ void main() {
semantics.dispose();
});
testWidgets('Dual Drawer Opening', (WidgetTester tester) async {
testWidgets('Drawer state query correctly', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: SafeArea(
left: false,
top: true,
right: false,
bottom: false,
child: Scaffold(
endDrawer: const Drawer(
child: Text('endDrawer'),
),
drawer: const Drawer(
child: Text('drawer'),
),
body: const Text('scaffold body'),
appBar: AppBar(
centerTitle: true,
title: const Text('Title')
),
),
),
),
);
final ScaffoldState scaffoldState = tester.state(find.byType(Scaffold));
final Finder drawerOpenButton = find.byType(IconButton).first;
final Finder endDrawerOpenButton = find.byType(IconButton).last;
await tester.tap(drawerOpenButton);
await tester.pumpAndSettle();
expect(true, scaffoldState.isDrawerOpen);
await tester.tap(endDrawerOpenButton);
await tester.pumpAndSettle();
expect(false, scaffoldState.isDrawerOpen);
await tester.tap(endDrawerOpenButton);
await tester.pumpAndSettle();
expect(true, scaffoldState.isEndDrawerOpen);
await tester.tap(drawerOpenButton);
await tester.pumpAndSettle();
expect(false, scaffoldState.isEndDrawerOpen);
scaffoldState.openDrawer();
expect(true, scaffoldState.isDrawerOpen);
await tester.tap(drawerOpenButton);
await tester.pumpAndSettle();
scaffoldState.openEndDrawer();
expect(true, scaffoldState.isEndDrawerOpen);
});
testWidgets('Dual Drawer Opening', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: SafeArea(
......
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