为新的行颤动创建按钮 [英] create buttons for new row flutter

查看:49
本文介绍了为新的行颤动创建按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建添加行的按钮和删除按钮(如果添加了一个按钮).就像下面的联系人菜单一样联系屏幕截图

how do I create button to add a row and a delete button if one was added. Like in contacts menu below Contact Screenshot

推荐答案

这只是一个有关如何实现此目的的示例,并非完整代码.您可以在 ListView.builder ="https://docs.flutter.io/flutter/widgets/StatefulWidget-class.html" rel ="nofollow noreferrer"> StatefulWidget 并添加

This is just a sample on how you could do that and is not intended to be the full code. You can use a ListView.builder in a StatefulWidget and add a FormField to the List everytime you click on the button. Same goes with removing it:

var items = [
  FormField(...),
]

class Some extends StatefulWidget{
  SomeState createState()=>  SomeState();
}

class SomeState extends State<Some> {
  @override
  Widget build(BuildContext context){
    return Column(
      children: <Widget> [
        Expanded(child:
          ListView.builder(itemBuilder: (context, index){
            return items[index];  
          }),
        ),
        RaisedButton(
          text: new Text("someButton"), 
          onPressed: () {
            setState(() {
              items.remove(FormField(...));
              items.add(FormField(...));
            })
          }
        ),
      ]
    );
  }
}

这篇关于为新的行颤动创建按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆