Skip to content

Commit 32a1c27

Browse files
authored
Adding example for migrating to navigation drawer (flutter#128295)
Fixes flutter#127214
1 parent 42cf3e3 commit 32a1c27

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
5+
import 'package:flutter/material.dart';
6+
7+
/// Flutter code sample for [NavigationDrawer].
8+
9+
void main() => runApp(const MyApp());
10+
11+
class MyApp extends StatelessWidget {
12+
const MyApp({super.key});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return MaterialApp(
17+
title: 'Flutter Demo',
18+
debugShowCheckedModeBanner: false,
19+
theme: ThemeData(
20+
useMaterial3: true,
21+
),
22+
home: const MyHomePage(),
23+
);
24+
}
25+
}
26+
27+
class MyHomePage extends StatelessWidget {
28+
const MyHomePage({super.key});
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
return Scaffold(
33+
appBar: AppBar(
34+
title: const Text('Drawer Demo'),
35+
),
36+
drawer: NavigationDrawer(
37+
children: <Widget>[
38+
Padding(
39+
padding: const EdgeInsets.fromLTRB(28, 16, 16, 10),
40+
child: Text(
41+
'Drawer Header',
42+
style: Theme.of(context).textTheme.titleSmall,
43+
),
44+
),
45+
const NavigationDrawerDestination(
46+
icon: Icon(Icons.message),
47+
label: Text('Messages'),
48+
),
49+
const NavigationDrawerDestination(
50+
icon: Icon(Icons.account_circle),
51+
label: Text('Profile'),
52+
),
53+
const NavigationDrawerDestination(
54+
icon: Icon(Icons.settings),
55+
label: Text('Settings'),
56+
),
57+
])
58+
);
59+
}
60+
}

packages/flutter/lib/src/material/drawer.dart

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ const Duration _kBaseSettleDuration = Duration(milliseconds: 246);
130130
/// ```
131131
/// {@end-tool}
132132
///
133+
/// {@tool snippet}
134+
/// This example shows how to migrate the above [Drawer] to a [NavigationDrawer].
135+
///
136+
/// See code in examples/api/lib/material/navigation_drawer/navigation_drawer.1.dart **
137+
/// {@end-tool}
138+
///
133139
/// An open drawer may be closed with a swipe to close gesture, pressing the
134140
/// escape key, by tapping the scrim, or by calling pop route function such as
135141
/// [Navigator.pop]. For example a drawer item might close the drawer when tapped:

0 commit comments

Comments
 (0)