问题
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