Flutter 在移动设备上使用Floor缓存数据,但也希望为web构建
我想同时支持android和web 但我使用Floor来缓存数据,web上不支持它。所以我只想在android上调用数据库,我不想在web上缓存数据。我想忽略网络上的这些行 我可以这样做吗Flutter 在移动设备上使用Floor缓存数据,但也希望为web构建,flutter,floor,Flutter,Floor,我想同时支持android和web 但我使用Floor来缓存数据,web上不支持它。所以我只想在android上调用数据库,我不想在web上缓存数据。我想忽略网络上的这些行 我可以这样做吗 void loadNews() async { emit(Loading()); await newsCacheRepository.init(); //because of this line on web the data doesn't appear var articles
void loadNews() async {
emit(Loading());
await newsCacheRepository.init(); //because of this line on web the data doesn't appear
var articles = await newsCacheRepository.getArticles();
emit(Loaded(articles));
refreshNews();
}
Future<void> refreshNews() async {
var articles = await newsNetworkRepository.getArticles();
emit(Loaded(articles));
newsCacheRepository.cacheArticles(articles);
}
void loadNews()异步{
发射(加载());
等待newsCacheRepository.init();//由于web上的这一行,数据不会出现
var articles=await newscaherepository.getArticles();
发射(装载(物品));
刷新新闻();
}
Future refreshNews()异步{
var articles=await newsNetworkRepository.getArticles();
发射(装载(物品));
newsCacheRepository.cacheArticles(文章);
}
您也可以使用支持web的Hive。或者,您也可以随时检查平台:
if(!kIsWeb){
// Your code that doesn't support web
}
但为了安全起见,您可以将代码包装在try-catch块上
但我更喜欢使用支持web的Hive。谢谢。成功了。也许将来我会检查蜂巢:)