动态重新排列列表项

时间:2020-07-06 06:55:36

标签: php mysql flutter dart

为什么!我正在使用可重新排序的列表视图来动态更改列表顺序或通过拖放交换值。问题是列表项是交换项,但未保存在数据库中。我的意思是我想从数据库更改列表索引。我正在使用mysql数据库。请帮我如何将网络请求发送到数据库。

可充电列表视图的飞镖代码

Widget _reorderable() {
return ReorderableListView(
  onReorder: (int oldIndex, int newIndex) {
    setState(() {
      if (newIndex > oldIndex) {
        newIndex -= 1;
      }

      final item = data.removeAt(oldIndex);

      data.insert(newIndex, item);
    });
  },
  children: List.generate(data.length, (index) {
    return Card(
      key: ValueKey("$index"),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Row(
          // mainAxisAlignment: MainAxisAlignment.start,

          children: <Widget>[
            Flexible(
              flex: 2,
              child: Container(
                margin: EdgeInsets.only(
                  left: 5,
                  right: 10,
                ),
                child: Text(
                  data[index]['sno'].toString(),
                  style: TextStyle(
                    color: Colors.blue,
                    fontSize: 11,
                  ),
                ),
              ),
            ),
            Flexible(
              flex: 2,
              child: Container(
                  margin: EdgeInsets.only(
                    left: 5,
                    right: 10,
                  ),
                  child: Icon(Icons.play_circle_outline)),
            ),
            Flexible(
              flex: 11,
              child: Container(
                child: Column(
                  children: <Widget>[
                    Container(
                      margin: EdgeInsets.only(
                        left: 10,
                        right: 0,
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: <Widget>[
                          Container(
                            child: Flexible(
                                child: Text(
                              data[index]['name'].toString(),
                              overflow: TextOverflow.ellipsis,
                              maxLines: 1,
                              softWrap: true,
                              style: TextStyle(
                                color: Colors.black,
                                fontSize: 12,
                              ),
                            )),
                          ),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 5,
                    ),
                    Container(
                      margin: EdgeInsets.only(
                        left: 5,
                        right: 25,
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: <Widget>[
                          Container(
                            margin: EdgeInsets.only(
                              left: 5,
                            ),
                            child: Icon(Icons.play_circle_outline),
                          ),

                          Container(
                            margin: EdgeInsets.only(
                              left: 1,
                            ),
                            child: Text(
                              " Videos",
                              style: TextStyle(
                                color: Colors.black,
                                fontSize: 8,
                              ),
                            ),
                          ),

                          // Padding(

                          //   padding:

                          //       const EdgeInsets.only(left: 10),

                          //   child:

                          Container(
                            margin: EdgeInsets.only(
                              left: 20,
                              right: 1,
                              top: 0,
                              bottom: 0,
                            ),
                            child: Icon(
                              Icons.star,
                              size: 15,
                              color: Colors.black,
                            ),
                          ),

                          //),

                          Container(
                            margin: EdgeInsets.only(
                              left: 0,
                              right: 10,
                              top: 0,
                              bottom: 0,
                            ),
                            child: Text(
                              data[index]['lecture_views'],
                              style: TextStyle(
                                color: Colors.black,
                                fontSize: 8,
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }),
);
}

0 个答案:

没有答案