我想在 Flutter 中使列表可重新排序,但我已经有了 Future Builder 和 List View。 ReorderableListView应该是其他 ListView的父级还是子级?如何初始化相同的密钥?
return Scaffold(
body: Container(
child: ListView(
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).size.height * 0.882,
child: FutureBuilder(
future: databaseHelper.getNoteList(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Text('Loading');
} else {
if (snapshot.data.length < 1) {
return Center(
child: Text('No Messages, Create New one'),
);
}
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int i) {
return Column(
children: <Widget>[
ListTile(
title: Text(snapshot.data[i].title),
),
subtitle:
Text(snapshot.data[i].note, maxLines: 4),
onTap: () {},
),
Divider(color: Theme.of(context).accentColor)
],
);
},
);
}
},
),
)
],
),
),
);
我尝试添加 ReorderableListView 但由于 children: [] 是不可能的我不知道在哪里为“ i ”放置一个 for 循环
future: databaseHelper.getNoteList(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Text('Loading');
} else {
if (snapshot.data.length < 1) {
return Center(
child: Text('No Messages, Create New one'),
);
}
return ReorderableListView(
children: List.generate(
snapshot.data.length,
(index) {
return ListTile(
key: Key('$index'),
title: Text(
snapshot.data[i].title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
subtitle:
Text(snapshot.data[i].note, maxLines: 4),
trailing: InkWell(
child: Icon(Icons.check, color: Colors.green),
onTap: () {
TextEditingController txt =
TextEditingController();
txt.text = snapshot.data[i].note;
print(txt);
Route route = MaterialPageRoute(
builder: (context) =>
MyHomePage(custMessage: txt));
Navigator.push(context, route);
// addNewMessageDialog(txt);
},
),
isThreeLine: true,
onTap: () {
Route route = MaterialPageRoute(
builder: (context) => AddNote(
note: snapshot.data[i],
));
Navigator.push(context, route);
},
);
},
).toList()
//Divider(color: Theme.of(context).accentColor),
);
}
})```
Right now the error is undefined variable i.