在我的数据库实现中,我有以下方法:
static Stream<User> getUserInformationStream() async{
var dbClient = await db;
return dbClient.userDao.getUser();
}
那个getUser()
是:
@Query('SELECT * FROM User LIMIT 1')
Stream<User> getUser();
在数据库帮助程序实现中,我试图使用此方法返回Stream
,但出现此错误:
错误:返回类型'Stream
'不是'Stream ',例如 由方法“ getUserInformationStream”定义。 (return_of_invalid_type为[diabetist_pro] lib \ database \ database_model.dart:36)
我完整的数据库帮助程序类:
已更新
DbModel
类放入db_model.dart
文件
class DbModel {
static final DbModel _instance = DbModel.internal();
factory DbModel()=> _instance;
static AppDatabase _db;
static Future<AppDatabase> get db async {
if (_db != null) {
return _db;
}
_db = await initDb();
return _db;
}
DbModel.internal();
static initDb() async {
var db = await $FloorAppDatabase.databaseBuilder('diabetist.db').build();
return db;
}
/* work fine */
static Future<User> getUserInformation() async {
var dbClient = await db;
return dbClient.userDao.getUserFuture();
}
/* not working and i get error */
static Stream<User> getUserInformationStream() async {
var dbClient = await db;
return dbClient.userDao.getUser();
}
}
已更新
和另一个文件user_dao.dart
类女巫
@dao
abstract class UserDao{
@Query('SELECT * FROM User LIMIT 1')
Stream<User> getUser();
@Query('SELECT * FROM User LIMIT 1')
Future<User> getUserFuture();
@insert
Future<void> insertUser(User user);
@update
Future<int> updateUser(User user);
@delete
Future<void> deleteUser(User user);
@Query('DELETE FROM User')
Future<void> deleteAllUsers(); // query without returning an entity
}