button - 为新行颤动创建按钮
问题描述
如果添加了一个,我如何创建按钮来添加一行和一个删除按钮。就像在联系人 屏幕下方的联系人菜单中一样
解决方案
这只是一个关于如何做到这一点的示例,并不是完整的代码。您可以在StatefulWidget中使用ListView.builder并在每次单击按钮时将FormField添加到列表中。删除它也是如此:
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(...));
})
}
),
]
);
}
}
推荐阅读
- python - 序列化 Django 模型并返回 GET 响应
- flutter - 如何使用自定义画家 - Flutter 在资产图像中绘制一些点?
- python - Python。如何设置“函数”的数量等于数组中的对象数量?
- r - R:改变绘图颜色
- ruby-on-rails - 带分页的rails动态路由
- reactjs - 使用 useState 在 React 中更新对象的属性
- javascript - 您如何强制 Foundation Reveal 模式将 HTML 块保留在其写入的父 div 中?
- python - TypeError: can only concatenate list (not "str") to list 创建一个连接值的脚本
- python - Matplotlib - 分组数据框值并将它们添加到一定范围内的 X 轴
- c - 为什么下面编写的两个程序(C 中的联合)的输出存在矛盾?