How can I auto-update Text according to fetched value from Database using Flutter?

陌路散爱 提交于 2020-01-05 04:23:09

问题


I fetched counting of a total number of records from Sqflite database and I display it on the Dashboard page but records counting is not increased when new record added, need to reopen the page to view changes? So how can I make it auto-update when a new record added?

Databse

Future<int> getSubCount() async {
    Database db = await this.database;
    return Sqflite.firstIntValue(await db.rawQuery("SELECT COUNT(*) FROM $subTable"));
  }
int subjects;

void _getCount() async {
    final int count = await db.getSubCount();
    setState(() {
      subjects = count;
    });
  }

Text Field

                    Column(
                            children: <Widget>[
                              Container(
                                  padding:
                                  EdgeInsets.only(top: 15, bottom: 5),
                                  child: Text("Subjects",
                                      style: TextStyle(
                                          color: Colors.black54))),
                              Container(
                                  padding: EdgeInsets.only(bottom: 15),
                                  child: Text("$subjects",
                                      style: TextStyle(
                                          color: Colors.black87,
                                          fontSize: 16))),
                            ],
                          ),

来源:https://stackoverflow.com/questions/59496576/how-can-i-auto-update-text-according-to-fetched-value-from-database-using-flutte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!