Listview 如果已经有列表视图生成器,如何添加可重排序列表视图

Listview 如果已经有列表视图生成器,如何添加可重排序列表视图,listview,flutter,flutter-listview,reorderable-list,Listview,Flutter,Flutter Listview,Reorderable List,我想让列表在flatter中可重新排序,但我已经有了未来的生成器和列表视图。 ReorderableListView应该是其他ListView的父视图还是子视图? 如何初始化相同的键 return Scaffold( body: Container( child: ListView( children: <Widget>[ SizedBox( height: MediaQuery.of(context).size.he

我想让列表在flatter中可重新排序,但我已经有了未来的生成器和列表视图。 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)
                      ],
                    );
                  },
                );
              }
            },
          ),
        )
      ],
    ),
  ),
);
返回脚手架(
主体:容器(
子:ListView(
儿童:[
大小盒子(
高度:MediaQuery.of(context).size.height*0.882,
孩子:未来建设者(
future:databaseHelper.getNoteList(),
生成器:(BuildContext上下文,异步快照){
如果(snapshot.data==null){
返回文本(“加载”);
}否则{
如果(snapshot.data.length<1){
返回中心(
子项:文本(“无消息,创建新消息”),
);
}
返回ListView.builder(
itemCount:snapshot.data.length,
itemBuilder:(构建上下文,int i){
返回列(
儿童:[
列表砖(
标题:文本(snapshot.data[i].title),
),
字幕:
文本(快照.数据[i].注,最大行数:4),
onTap:(){},
),
分隔符(颜色:Theme.of(context.accentColor)
],
);
},
);
}
},
),
)
],
),
),
);
我尝试添加ReorderableListView,但由于不可能有子项:[],我不知道在哪里为“I”设置for循环

future:databaseHelper.getNoteList(),
生成器:(BuildContext上下文,异步快照){
如果(snapshot.data==null){
返回文本(“加载”);
}否则{
如果(snapshot.data.length<1){
返回中心(
子项:文本(“无消息,创建新消息”),
);
}
返回ReorderableListView(
子项:List.generate(
snapshot.data.length,
(索引){
返回列表块(
key:key(“$index”),
标题:正文(
snapshot.data[i].标题,
样式:TextStyle(
fontWeight:fontWeight.bold,
尺寸:20,
),
),
字幕:
文本(快照.数据[i].注,最大行数:4),
拖尾:墨水井(
子项:图标(Icons.check,颜色:Colors.green),
onTap:(){
文本编辑控制器=
TextEditingController();
txt.text=snapshot.data[i]。注;
打印(txt);
路线=物料管理路线(
生成器:(上下文)=>
我的主页(custMessage:txt));
推送(上下文、路线);
//addNewMessageDialog(txt);
},
),
伊斯特里琳:是的,
onTap:(){
路线=物料管理路线(
生成器:(上下文)=>AddNote(
注:snapshot.data[i],
));
推送(上下文、路线);
},
);
},
)托利斯先生()
//分隔符(颜色:主题。背景。重音颜色),
);
}
})```
现在错误是未定义的变量i。

我找到了解决这个问题的方法

```Widget build(BuildContext context) {
    databaseHelper.initlizeDatabase();
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.green,
        title: Text('Notes'),
      ),
      body: Container(
          padding: EdgeInsets.all(8.0),
          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 ReorderableListView(
                              children: List.generate(
                                snapshot.data.length,
                                (index) {
                                  return ListTile(
                                    key: Key('$index'),
                                    title: Text(
                                      snapshot.data[index].title,
                                      style: TextStyle(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 20,
                                      ),
                                    ),
                                    subtitle: Text(snapshot.data[index].note,
                                        maxLines: 4),
                                    trailing: InkWell(
                                      child: Icon(Icons.check,
                                          color: Colors.green),
                                      onTap: () {
                                        TextEditingController txt =
                                            TextEditingController();

                                        txt.text = snapshot.data[index].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[index],
                                              ));
                                      Navigator.push(context, route);
                                    },
                                  );
                                },
                              ).toList(),
                              onReorder: (int oldIndex, int newIndex) {
                                setState(() {
                                  if (newIndex > oldIndex) {
                                    newIndex -= 1;
                                  }
                                  final item = snapshot.data.removeAt(oldIndex);
                                  snapshot.data.insert(newIndex, item);
                                });
                              }

                              //Divider(color: Theme.of(context).accentColor),
                              );
                        }
                      }))
            ],
          )),
      floatingActionButton: _buildFAB(context, key: _fabKey),
    );
  }```
小部件构建(BuildContext){ databaseHelper.initlizeDatabase(); 返回脚手架( appBar:appBar( 背景颜色:Colors.green, 标题:文本(“注释”), ), 主体:容器( 填充:边缘设置。全部(8.0), 子:ListView( 儿童:[ 大小盒子( 高度:MediaQuery.of(context).size.height*0.882, 孩子:未来建设者( future:databaseHelper.getNoteList(), 生成器:(BuildContext上下文,异步快照){ 如果(snapshot.data==null){ 返回文本(“加载”); }否则{ 如果(snapshot.data.length<1){ 返回中心( 子项:文本(“无消息,创建新消息”), ); } 返回ReorderableListView( 子项:List.generate( snapshot.data.length, (索引){ 返回列表块(
```Widget build(BuildContext context) {
    databaseHelper.initlizeDatabase();
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.green,
        title: Text('Notes'),
      ),
      body: Container(
          padding: EdgeInsets.all(8.0),
          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 ReorderableListView(
                              children: List.generate(
                                snapshot.data.length,
                                (index) {
                                  return ListTile(
                                    key: Key('$index'),
                                    title: Text(
                                      snapshot.data[index].title,
                                      style: TextStyle(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 20,
                                      ),
                                    ),
                                    subtitle: Text(snapshot.data[index].note,
                                        maxLines: 4),
                                    trailing: InkWell(
                                      child: Icon(Icons.check,
                                          color: Colors.green),
                                      onTap: () {
                                        TextEditingController txt =
                                            TextEditingController();

                                        txt.text = snapshot.data[index].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[index],
                                              ));
                                      Navigator.push(context, route);
                                    },
                                  );
                                },
                              ).toList(),
                              onReorder: (int oldIndex, int newIndex) {
                                setState(() {
                                  if (newIndex > oldIndex) {
                                    newIndex -= 1;
                                  }
                                  final item = snapshot.data.removeAt(oldIndex);
                                  snapshot.data.insert(newIndex, item);
                                });
                              }

                              //Divider(color: Theme.of(context).accentColor),
                              );
                        }
                      }))
            ],
          )),
      floatingActionButton: _buildFAB(context, key: _fabKey),
    );
  }```
                      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[index].title,
                                      ),
                                    ),
                                    subtitle: Text(snapshot.data[index].note,
                                        maxLines: 4),
                                    onTap: () {                                       

                                      },
                                    ),

                                    onTap: () {
                                      Route route = MaterialPageRoute(
                                          builder: (context) => AddNote(
                                                note: snapshot.data[index],
                                              ));
                                      Navigator.push(context, route);
                                    },
                                  );
                                },
                              ).toList(),
                              onReorder: (int oldIndex, int newIndex) {
                                setState(() {
                                  if (newIndex > oldIndex) {
                                    newIndex -= 1;
                                  }
                                  final item = snapshot.data.removeAt(oldIndex);
                                  snapshot.data.insert(newIndex, item);
                                });
                              }