1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6
7/// Flutter code sample for [Scaffold.endDrawer].
8
9void main() => runApp(const EndDrawerExampleApp());
10
11class EndDrawerExampleApp extends StatelessWidget {
12 const EndDrawerExampleApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return const MaterialApp(
17 home: EndDrawerExample(),
18 );
19 }
20}
21
22class EndDrawerExample extends StatefulWidget {
23 const EndDrawerExample({super.key});
24
25 @override
26 State<EndDrawerExample> createState() => _EndDrawerExampleState();
27}
28
29class _EndDrawerExampleState extends State<EndDrawerExample> {
30 final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
31
32 void _openEndDrawer() {
33 _scaffoldKey.currentState!.openEndDrawer();
34 }
35
36 void _closeEndDrawer() {
37 Navigator.of(context).pop();
38 }
39
40 @override
41 Widget build(BuildContext context) {
42 return Scaffold(
43 key: _scaffoldKey,
44 appBar: AppBar(title: const Text('Drawer Demo')),
45 body: Center(
46 child: ElevatedButton(
47 onPressed: _openEndDrawer,
48 child: const Text('Open End Drawer'),
49 ),
50 ),
51 endDrawer: Drawer(
52 child: Center(
53 child: Column(
54 mainAxisAlignment: MainAxisAlignment.center,
55 children: <Widget>[
56 const Text('This is the Drawer'),
57 ElevatedButton(
58 onPressed: _closeEndDrawer,
59 child: const Text('Close Drawer'),
60 ),
61 ],
62 ),
63 ),
64 ),
65 // Disable opening the end drawer with a swipe gesture.
66 endDrawerEnableOpenDragGesture: false,
67 );
68 }
69}
70

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com