首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在颤动中关闭sqf

在颤动中关闭sqf
EN

Stack Overflow用户
提问于 2020-04-09 10:42:41
回答 1查看 26关注 0票数 0

如果我有一个ListView来显示来自sql的数据。1)这个关闭数据库的函数应该放在哪里? 2)_Close函数足以关闭数据库还是需要使用异步??

代码语言:javascript
复制
 void _Close(Database db)  {
     db.close();
  }

这是我的Listview:

代码语言:javascript
复制
 ListView getStudentsList() {
    return ListView.builder(
        itemCount: count,
        itemBuilder: (BuildContext context, int position) {
          return Card(
            color: Colors.white,
            elevation: 2.0,
            child: ListTile(
              leading: CircleAvatar(
                backgroundColor: isPassed(this.studentsList[position].pass),
                child: getIcon(this.studentsList[position].pass),
              ),
              title: Text(this.studentsList[position].name),
              subtitle: Text(this.studentsList[position].description + " | " +
                  this.studentsList[position].date),
              trailing:
              GestureDetector(
                child: Icon(Icons.delete, color: Colors.grey,),
                onTap: () {
                  _delete(context, this.studentsList[position]);
                },
              )
              ,
              onTap: () {
                navigateToStudent(this.studentsList[position], "Edit Student");
              },
            ),

          );
        });
  }
EN

回答 1

Stack Overflow用户

发布于 2020-04-09 10:47:53

使用异步函数确保在UI更改之前已关闭数据库:

代码语言:javascript
复制
 Future<void> _close(Database db) async {
     await db.close();
  }

该函数可以放在db变量作用域中的任何位置,当您完成从数据库读取时,应该使用代码await _close();调用它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61113128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档