简体   繁体   English

如何在 flutter 的下拉列表中添加删除选项

[英]how to add delete option in dropdown in flutter

I'm working in small project.我在做一个小项目。 For Login, I need to save URL in shared preferences so that next time user can select it in dropdown.对于登录,我需要将 URL 保存在共享首选项中,以便下次用户可以在下拉列表中使用 select 它。 I need to keep delete option in that dropdown to delete old URL.我需要在该下拉列表中保留删除选项以删除旧的 URL。 How to do?怎么做?

code:代码:

 if (getALLURL.isNotEmpty) ...[
                DropdownButton<String>(
                  value: baseurl.isNotEmpty ? baseurl : null,
                  borderRadius: BorderRadius.circular(2.0),
                  underline: SizedBox(),
                  focusColor: AppColors().linenDark,
                  elevation: 1,
                  enableFeedback: true,
                  isExpanded: true,
                  style: GoogleFonts.montserrat(
                      fontSize: AppSizes().paraLarge16,
                      color: AppColors().linenDark,
                      fontWeight: FontWeight.w400),
                  icon: Icon(
                    Icons.keyboard_arrow_down_rounded,
                    color: AppColors().linenMedium,
                  ),
                  items: getALLURL.map((String item) {
                    return DropdownMenuItem<String>(
                      child: Text(item),
                      value: item,
                    );
                  }).toList(),
                  onChanged: (value) async {
                    setState(() {
                      baseurl = value!;
                      print(baseurl);
                    });
                    await Prefs().setBaseURLLogin(baseurl);
                  },
                  hint: Text("Select item"),
                ),
                //IconButton(onPressed: onDelete, icon: Icon(Icons.delete))
              ],

Now I'm only used text in menuitems, how to add delete in it.现在我只在菜单项中使用文本,如何在其中添加删除。 Can I delete particular value in shared preferences我可以删除共享偏好中的特定值吗

Can I delete particular value in shared preferences我可以删除共享偏好中的特定值吗

Yes, you can write new value over the old one with same key.是的,您可以使用相同的键在旧值上写入新值。

Now I'm only used text in menuitems, how to add delete in it现在我只在菜单项中使用文本,如何在其中添加删除

i don't think it could support that directly.我认为它不能直接支持这一点。 Even if it, i recommended you to use instead way for delete option such as any position of the screen.即使是这样,我还是建议您改用删除选项的方式,例如屏幕的任何 position。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM