使用删除按钮删除小部件,但不反映在屏幕上

时间:2019-07-13 06:32:08

标签: flutter dart

我有一个小部件列表,有一个删除按钮,但是当我按下按钮时,它应该从列表视图中删除小部件,但是它不起作用。

List<Widget> items = []; //list of widget
class MyClass extends StatefulWidget {
  @override
  _MyClassState createState() => _MyClassState();
}

class _MyClassState extends State<MyClass> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
         onPressed: () {
        }),
      body: Container(
        child: ListView.builder(
          itemCount: allRowsLength == null ? 0 : allRowsLength,
          itemBuilder: (BuildContext context, index) {
            return NoteC(

              ontap: () async {
                //save button
              },
              onPress: () async {
                //delete button
                setState(() {
                  _delete(
                      index); // deleting data from database (which works) and widget(which is not working)
                });
              },
            );
          },
        ),
      ),
    );
  }


  void _delete(index) {
    //delete function
    setState(() {
      getID = allRows[index]['_id'];
      print('delete $getID');
      dbHelper.delete(getID);

      items.removeAt(index); 
    });
  }

小部件已从小部件列表中删除,但未反映在列表视图构建器中

0 个答案:

没有答案