I am using sqflite and I am getting rows count of specific record via below code:
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;
}
I want to get the result of this function into int variable to use it inside 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);
}
},
);
},
),
);
},
),
but I am getting this exception:
A value of type 'Future' can't be assigned to a variable of type 'int'.
await
keyword. Can you explain why it would not be sufficient here? – RussellrussetFutureBuilder
or useawait
keyword in order to getFuture
's value. – PasFuture<T>
to aT
3 times in the code you posted. Why is that not good enough now? Why can't you use it a fourth time? – Russellrusset