我在用sqflite https://pub.dev/packages/sqflite我通过以下代码获取特定记录的行数:
Future<int> getNumberOfUsers() async {
Database db = await database;
final count = Sqflite.firstIntValue(
await db.rawQuery('SELECT COUNT(*) FROM Users'));
return count;
}
Future<int> getCount() async {
DatabaseHelper helper = DatabaseHelper.instance;
int counter = await helper.getNumberOfUsers();
return counter;
}
我想将此函数的结果放入 int 变量中以在内部使用它onPressed
in FloatingActionButton
int count = getCount();
int countParse = int.parse(getCount());
return Stack(
children: <Widget>[
Image.asset(
kBackgroundImage,
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
Scaffold(
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.white,
child: Icon(
Icons.add,
color: kButtonBorderColor,
size: 30.0,
),
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) => AddScreen(
(String newTitle) {
setState(
() {
//--------------------------------------------
//I want to get the value here
int count = getCount();
int countParse = int.parse(getCount());
//--------------------------------------------
if (newTitle != null && newTitle.trim().isNotEmpty) {
_save(newTitle);
}
},
);
},
),
);
},
),
但我得到了这个例外:
“Future”类型的值不能分配给“int”类型的变量。