gpt4 book ai didi

flutter - 如何在flutter中为附件创建一个 float 按钮

转载 作者:IT王子 更新时间:2023-10-29 07:23:24 26 4
gpt4 key购买 nike

如何在 Flutter 中创建一个 float 按钮并在按钮按下时为不同的选项设置动画?我正在尝试制作如下内容:

当我尝试添加多个 float 按钮时,出现“argument for the name floating button action has already been specified”错误

    class MyBills extends StatelessWidget {
MyBills({Key key}) : super(key: key);

//@override
//MyBillsPageState createState() => MyBillsPageState();
@override
Widget build(BuildContext context) {
return new Scaffold(
body: ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
return new Container(height: 100, child: BillItem());
}
),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.add),
heroTag: 1,
onPressed: _addAttachment
),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.camera),
heroTag: 2,
onPressed: _cameraAttachment
),
);
}

enter image description here或动画 float 选项 like this

最佳答案

给每个 FloatingActionButton 一个唯一的 heroTag 标签,你就可以开始了。

floatingActionButton: FloatingActionButton(
heroTag: 0, // you can use any object here
),

您的解决方案:

@override
Widget build(BuildContext context) {
return new Scaffold(
body: Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
return new Container(height: 100, child: BillItem());
}
),
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new FloatingActionButton(child: new Icon(Icons.add), heroTag: 1, onPressed: _addAttachment),
new FloatingActionButton(child: new Icon(Icons.camera), heroTag: 2, onPressed: _cameraAttachment),
],
),
],
),
);
}

关于flutter - 如何在flutter中为附件创建一个 float 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54395652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com