Thursday, July 8, 2021

FLUTTER | APP DRAWER DYNAMIC NAVIGATION

Selamat datang di blog ali-mahdali.blogstpot.com, kali ini penulis memposting artikel yang berjudul FLUTTER | APP DRAWER DYNAMIC NAVIGATION yang mana artikel ini dapat kalian akses melalui alamat : https://ali-mahdali.blogspot.com/2021/07/flutter-app-drawer-dynamic-navigation.html,
tanpa basa-basi yuk disimak artikelnya dibawah ini. Selamat membaca

kali ini abang akan membagikan skrip membuat app drawer secara dinamis, langsung saja berikut ini tampilan gambarnya




ini skripnya


import 'package:flutter/material.dart';

class DrawerItem {
  String title;
  IconData icon;
  bool enable;
  Widget conten;
  DrawerItem(this.titlethis.iconthis.enablethis.conten);
}

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Keykey}) : super(keykey);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title'Flutter Demo',
      debugShowCheckedModeBannerfalse,
      themeThemeData(
        primarySwatchColors.teal,
      ),
      homeHomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  final List<DrawerItemdrawerItems = [];

  HomePage({Keykey}) : super(keykey);

  @override
  State<StatefulWidgetcreateState() {
    return HomePageState();
  }
}

class HomePageState extends State<HomePage> {
  int _selectedDrawerIndex = 0;

  _getDrawerItemWidget(int pos) {
    return widget.drawerItems[pos].conten;
  }

  _onSelectItem(int index) {
    setState(() => _selectedDrawerIndex = index);
    Navigator.of(context).pop();
  }

  _rebuildMenu(bool mode) {
    widget.drawerItems.clear();
    widget.drawerItems.add(DrawerItem(
        "Dashboard",
        Icons.dashboard_rounded,
        true,
        const Center(
          childText('Selamat Datang'),
        )));
    widget.drawerItems.add(DrawerItem(
        "List",
        Icons.list_alt_rounded,
        true,
        const Center(
          childCard(
            childText('data'),
          ),
        )));
    widget.drawerItems.add(DrawerItem(
        "Disable",
        Icons.disabled_by_default,
        false,
        const Center(
          childCard(
            childnull,
          ),
        )));
    widget.drawerItems.add(DrawerItem(
        "Berita",
        Icons.radio,
        true,
        const Center(
          childCard(
            childText('Berita'),
          ),
        )));
    widget.drawerItems.add(DrawerItem(
        "Pesan",
        Icons.message,
        true,
        Center(
          childCard(
            childElevatedButton(
              onPressed: () => _pesan(
                  title'Konfirmasi',
                  subtitle'Apakah anda akan kembali ke halaman utama?',
                  iconIcons.access_alarm_outlined,
                  kliknull),
              childconst Text('Pop Up'),
            ),
          ),
        )));
  }

  void _pesan(
      {Stringtitle,
      Stringsubtitle,
      IconDataicon,
      GestureDetectorklik}) {
    showDialog(
      contextcontext,
      builder: (context) => AlertDialog(
        contentSizedBox(
            height170,
            width70,
            childColumn(
              children: <Widget>[
                Icon(
                  icon,
                  size50,
                ),
                const Padding(paddingEdgeInsets.all(5)),
                const Divider(colorColors.black),
                Text(
                  title.toString(),
                  textAlignTextAlign.justify,
                  styleconst TextStyle(
                    fontSize20,
                    fontWeightFontWeight.bold,
                  ),
                ),
                const Divider(colorColors.black),
                const Padding(paddingEdgeInsets.all(5)),
                Text(
                  subtitle.toString(),
                  textAlignTextAlign.justify,
                  styleconst TextStyle(
                    fontSize12,
                    fontWeightFontWeight.bold,
                  ),
                )
              ],
            )),
        actions: <Widget>[
          ElevatedButton.icon(
            iconconst Icon(Icons.check_circle_rounded),
            labelconst Text('Ok'),
            styleButtonStyle(
              backgroundColorMaterialStateProperty.all<Color>(Colors.green),
            ),
            onPressed: () {
              Navigator.of(context).pop();
              klik;
            },
          ),
          ElevatedButton.icon(
            iconconst Icon(Icons.highlight_off_outlined),
            labelconst Text('Batal'),
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),
        ],
      ),
    );
  }

  Widget _appBar(String judulString subJudul) {
    String isiJudul = judul.toString();
    String isiSubJudul = subJudul.toString();
    //Image isiGambar = FlutterLogo();
    return Container(
        alignmentAlignment.centerLeft,
        height100,
        colorTheme.of(context).primaryColor,
        childListTile(
          leadingSizedBox(
              height50.0,
              width50.0,
              childCircleAvatar(
                radius40,
                backgroundColorTheme.of(context).primaryColorLight,
                childconst CircleAvatar(
                  radius20,
                  childFlutterLogo(), //gambar app
                ),
              )),
          titleText(
            isiJudul.toString(),
            styleTextStyle(
                colorTheme.of(context).cardColor,
                fontSize20,
                fontWeightFontWeight.w900),
          ),
          subtitleText(isiSubJudul.toString(),
              styleconst TextStyle(
                  colorColors.white,
                  fontSize12,
                  fontWeightFontWeight.w100)),
        ));
  }

  List<WidgetcreateMenu() {
    List<WidgetdrawerOptions = [];
    bool isSelected = false;

    for (var i = 0i < widget.drawerItems.lengthi++) {
      var d = widget.drawerItems[i];
      if (_selectedDrawerIndex == i) {
        isSelected = true;
      } else {
        isSelected = false;
      }
      drawerOptions.add(daftarMenu(
          juduld.title,
          ikond.icon,
          terpilihisSelected,
          enabled.enable,
          fungsi: () => _onSelectItem(i)));
    }

    return drawerOptions;
  }

  Widget daftarMenu(
      {Stringjudul,
      bool enable = false,
      IconDataikon,
      GestureTapCallbackfungsi,
      bool terpilih = false}) {
    return Ink(
        color:
            terpilih ? Theme.of(context).primaryColorLight : Colors.transparent,
        childListTile(
            leadingIcon(
              ikon,
              colorTheme.of(context).primaryColorDark,
            ),
            titleText(
              judul.toString(),
              styleTextStyle(
                  colorTheme.of(context).primaryColorDark,
                  fontWeightterpilih ? FontWeight.bold : FontWeight.w100),
            ),
            trailingIcon(
              Icons.arrow_right_rounded,
              colorTheme.of(context).primaryColorDark,
            ),
            selectedterpilih,
            enabledenable,
            onTapfungsi));
  }

  @override
  Widget build(BuildContext context) {
    if (widget.drawerItems.isEmpty) {
      setState(() {
        _rebuildMenu(true);
      });
    }

    return Scaffold(
      appBarAppBar(
        iconThemeIconThemeData(colorTheme.of(context).cardColor),
        titleRow(children: <Widget>[
          Text(
            widget.drawerItems[_selectedDrawerIndex].title,
            styleTextStyle(
                fontWeightFontWeight.w900,
                fontSize20,
                colorTheme.of(context).cardColor),
          )
        ]),
      ),
      drawerDrawer(
        childColumn(
          children: <Widget>[
            _appBar('Menu App''Tampilan menu keren'),
            Column(childrencreateMenu()),
          ],
        ),
      ),
      body_getDrawerItemWidget(_selectedDrawerIndex),
    );
  }
}

Sebelum melanjutkan membaca artikel ini, berikut adalah artikel yang berkaitan dengan judul artikel FLUTTER | APP DRAWER DYNAMIC NAVIGATION :
ok, silahkan lanjut membaca.

Terimakasih atas kunjungan Anda dan Karena telah sudi membaca artikel yang berjudul FLUTTER | APP DRAWER DYNAMIC NAVIGATION.Tak Lengkap Rasanya Jika Kunjungan Anda di Blog ini Tanpa Meninggalkan Komentar, untuk Itu Silahkan Berikan Kritik dan saran Pada Kotak Komentar di bawah. Anda boleh menyebarluaskan atau mengcopy artikel FLUTTER | APP DRAWER DYNAMIC NAVIGATION ini jika memang bermanfaat bagi anda, namun jangan lupa untuk mencantumkan link sumbernya. Terima Kasih, Happy Blogging :)

1 comment

  1. Jammin' Jars 2 online slot at JCMH - Mecca - JTM Hub
    The Jammin' 상주 출장안마 Jars 2 video slot is a 7 reel, 구미 출장안마 7 row video slot. The 군포 출장샵 96.51% RTP is 96.53% 남원 출장샵 which is just above the 밀양 출장마사지 96.51% of the original game! It has a high volatility

    ReplyDelete


EmoticonEmoticon