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(home: EndDrawerExample());
17 }
18}
19
20class EndDrawerExample extends StatefulWidget {
21 const EndDrawerExample({super.key});
22
23 @override
24 State<EndDrawerExample> createState() => _EndDrawerExampleState();
25}
26
27class _EndDrawerExampleState extends State<EndDrawerExample> {
28 final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
29
30 void _openEndDrawer() {
31 _scaffoldKey.currentState!.openEndDrawer();
32 }
33
34 void _closeEndDrawer() {
35 Navigator.of(context).pop();
36 }
37
38 @override
39 Widget build(BuildContext context) {
40 return Scaffold(
41 key: _scaffoldKey,
42 appBar: AppBar(title: const Text('Drawer Demo')),
43 body: Center(
44 child: ElevatedButton(onPressed: _openEndDrawer, child: const Text('Open End Drawer')),
45 ),
46 endDrawer: Drawer(
47 child: Center(
48 child: Column(
49 mainAxisAlignment: MainAxisAlignment.center,
50 children: <Widget>[
51 const Text('This is the Drawer'),
52 ElevatedButton(onPressed: _closeEndDrawer, child: const Text('Close Drawer')),
53 ],
54 ),
55 ),
56 ),
57 // Disable opening the end drawer with a swipe gesture.
58 endDrawerEnableOpenDragGesture: false,
59 );
60 }
61}
62

Provided by KDAB

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