【问题标题】:Hide/show DrawerItems in some conditions flutter?在某些情况下隐藏/显示 DrawerItems?
【发布时间】:2021-03-26 16:46:39
【问题描述】:

如果用户未登录,我想在我的抽屉上隐藏一些选项

这是 DrawerItem 小部件:

Widget drawerItem(item) {

if (item['show'] == false) return const SizedBox();

final isListing = Config().isListingType;

switch (item['type']) {

  case 'pointEnd':
    {
      return ListTile(
          leading: const Icon(CupertinoIcons.bag_badge_plus,
              size: 25),
          title: Text(S.of(context).myPoints),
          onTap : () => Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => UserPoint(),
            ),
      )
);

我只想在用户登录时显示端点

【问题讨论】:

    标签: flutter dart flutter-layout flutter-animation


    【解决方案1】:

    您可以维护一个小部件集合并根据您的需要向其中添加相应的项目。喜欢

    Widget _buildDrawer() {
      List<ListTile> listTile = [
        ListTile(),
        ListTile(),
      ];
    
      /// Check the condition here to add more list tiles to the listTile collection
      /// If the user is logged In.
      if (hasUserLoggedIn) {
        listTile.add(ListTile(
            leading: const Icon(CupertinoIcons.bag_badge_plus, size: 25),
            title: Text(s.of(context).myPoints),
            onTap: () => Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => UserPoint(),
                  ),
                )));
      }
    
      return Drawer(
        child: ListView(
          children: listTile,
        ),
      );
    }
    ``
    
      
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 1970-01-01
      • 2015-01-10
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多