|
| 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 | +} |
0 commit comments