Flutter 如何使位置成为小部件的动态属性?

Flutter 如何使位置成为小部件的动态属性?,flutter,dart,Flutter,Dart,我想为小部件创建一个类,其中一个属性是它的位置。我试着用Align包装它,但它只返回一个空白页。怎么了 class Note extends StatefulWidget { @override _NoteState createState() => _NoteState(); } class _NoteState extends State<Note> { AudioCache _audioCache; List<NoteButton> not

我想为小部件创建一个类,其中一个属性是它的位置。我试着用Align包装它,但它只返回一个空白页。怎么了

class Note extends StatefulWidget {
  @override
  _NoteState createState() => _NoteState();
}

class _NoteState extends State<Note> {
  AudioCache _audioCache;

  List<NoteButton> notes = [
  NoteButton(hori: 5.0, noteName: 'a3.mp3', num: '0', vert: 8.0),
  NoteButton(hori: 8.0, noteName: 'a-3.mp3', num: '0', vert: 4.0)
  ];


  Widget buttonTemplate(NoteButton note){
      return Align(
            alignment: Alignment(note.vert, note.hori),
              child: FloatingActionButton(
                  onPressed: () => null,
    ),
    );
  }

void initState() {
    super.initState();
  
  @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home:  Scaffold(
          body: Row(
            children:  notes.map((note) => buttonTemplate(note)).toList(),
          ),
        ),
      );
    }
  }
类注释扩展StatefulWidget{
@凌驾
_NoteState createState();
}
类_NoteState扩展了状态{
AudioCache\u AudioCache;
列表注释=[
NoteButton(hori:5.0,noteName:'a3.mp3',num:'0',vert:8.0),
NoteButton(hori:8.0,noteName:'a-3.mp3',num:'0',vert:4.0)
];
小部件按钮模板(注意按钮注意){
返回对齐(
对齐:对齐(注:垂直,注:水平),
子:浮动操作按钮(
onPressed:()=>null,
),
);
}
void initState(){
super.initState();
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
正文:世界其他地区(
子项:notes.map((note)=>buttonTemplate(note)).toList(),
),
),
);
}
}

嘿,你试过stack小部件了吗: 例如:

如果您想在堆栈中设置动画的子对象添加关键点以获得平滑体验,请指向“带回家”

.....
body: Stack(
        children:[
          Positioned(
            top:10,left:20,
            child: Text("Hello 1"),
          ),
          Positioned(
            top:50,left:70,
            child: Text("Hello 2"),
          ),
        ]
      )
.....