Advertisement
yudiwibisono

flutter_drawer

Apr 4th, 2022
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.56 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(const MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   const MyApp({Key? key}) : super(key: key);
  9.  
  10.   @override
  11.   Widget build(BuildContext context) {
  12.     return const MaterialApp(
  13.       title: 'Test Drawer',
  14.       home: HomePage(),
  15.     );
  16.   }
  17. }
  18.  
  19. class HomePage extends StatefulWidget {
  20.   const HomePage({Key? key}) : super(key: key);
  21.   @override
  22.   HomePageState createState() {
  23.     return HomePageState();
  24.   }
  25. }
  26.  
  27. class HomePageState extends State<HomePage> {
  28.   int idx = 0;
  29.  
  30.   static const List<Center> halaman = [
  31.     Center(child: Text("satu")),
  32.     Center(child: Text("dua")),
  33.     Center(child: Text("tiga")),
  34.   ];
  35.  
  36.   void gantiItem(int index) {
  37.     setState(() {
  38.       idx = index;
  39.     });
  40.   }
  41.  
  42.   @override
  43.   Widget build(BuildContext context) {
  44.     return Scaffold(
  45.         appBar: AppBar(title: const Text("Test Drawer.")),
  46.         body: halaman[idx],
  47.         drawer: Drawer(
  48.             child: ListView(
  49.           children: [
  50.             const DrawerHeader(child: Text("Ini Header")),
  51.             ListTile(
  52.                 title: const Text("item1"),
  53.                 onTap: () {
  54.                   gantiItem(0);
  55.                 }),
  56.             ListTile(
  57.                 title: const Text("item2"),
  58.                 onTap: () {
  59.                   gantiItem(1);
  60.                 }),
  61.             ListTile(
  62.                 title: const Text("item3"),
  63.                 onTap: () {
  64.                   gantiItem(2);
  65.                 })
  66.           ],
  67.         )));
  68.   }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement