Flutter 如何从Moor中删除所有内容?
我尝试在注销时删除所有Flutter 如何从Moor中删除所有内容?,flutter,dart,Flutter,Dart,我尝试在注销时删除所有 onPressed: () { _categoryBloc.deleteEntry(); } 但错误即将来临 未处理的异常:NoSuchMethodError:方法“deleteEntry”无效 调用null。E/颤振(9255):接收器:零E/颤振(9255): 已尝试调用:deleteEntry() 初始集团 CategoryBloc _categoryBloc; MyBloc类 class CategoryBloc { ... vo
onPressed: () {
_categoryBloc.deleteEntry();
}
但错误即将来临
未处理的异常:NoSuchMethodError:方法“deleteEntry”无效
调用null。E/颤振(9255):接收器:零E/颤振(9255):
已尝试调用:deleteEntry()
初始集团
CategoryBloc _categoryBloc;
MyBloc类
class CategoryBloc {
...
void deleteEntry() {
_categoryRepository.deleteCategory();
}
...
}
deleteCategory() async {
try{
await _categoryDao.deleteEntry();
}catch (e){
print('Caught in delete ${e.body}');
rethrow;
}
}
Future deleteEntry() {
return delete(categories).delete(Categorie());
}
class Categorie extends DataClass implements Insertable<Categorie> {
final String id;
final bool isActive;
final String categoryName;
final int displayOrder;
Categorie(
{@required this.id,
@required this.isActive,
@required this.categoryName,
@required this.displayOrder});
factory Categorie.fromData(Map<String, dynamic> data, GeneratedDatabase db,
.....
我的回购类
class CategoryBloc {
...
void deleteEntry() {
_categoryRepository.deleteCategory();
}
...
}
deleteCategory() async {
try{
await _categoryDao.deleteEntry();
}catch (e){
print('Caught in delete ${e.body}');
rethrow;
}
}
Future deleteEntry() {
return delete(categories).delete(Categorie());
}
class Categorie extends DataClass implements Insertable<Categorie> {
final String id;
final bool isActive;
final String categoryName;
final int displayOrder;
Categorie(
{@required this.id,
@required this.isActive,
@required this.categoryName,
@required this.displayOrder});
factory Categorie.fromData(Map<String, dynamic> data, GeneratedDatabase db,
.....
dao类
class CategoryBloc {
...
void deleteEntry() {
_categoryRepository.deleteCategory();
}
...
}
deleteCategory() async {
try{
await _categoryDao.deleteEntry();
}catch (e){
print('Caught in delete ${e.body}');
rethrow;
}
}
Future deleteEntry() {
return delete(categories).delete(Categorie());
}
class Categorie extends DataClass implements Insertable<Categorie> {
final String id;
final bool isActive;
final String categoryName;
final int displayOrder;
Categorie(
{@required this.id,
@required this.isActive,
@required this.categoryName,
@required this.displayOrder});
factory Categorie.fromData(Map<String, dynamic> data, GeneratedDatabase db,
.....
数据类
class CategoryBloc {
...
void deleteEntry() {
_categoryRepository.deleteCategory();
}
...
}
deleteCategory() async {
try{
await _categoryDao.deleteEntry();
}catch (e){
print('Caught in delete ${e.body}');
rethrow;
}
}
Future deleteEntry() {
return delete(categories).delete(Categorie());
}
class Categorie extends DataClass implements Insertable<Categorie> {
final String id;
final bool isActive;
final String categoryName;
final int displayOrder;
Categorie(
{@required this.id,
@required this.isActive,
@required this.categoryName,
@required this.displayOrder});
factory Categorie.fromData(Map<String, dynamic> data, GeneratedDatabase db,
.....
类Categorie扩展数据类实现可插入{
最终字符串id;
最终目标是积极的;
最终字符串类别名称;
最终显示顺序;
分类(
{@required this.id,
@需要这个.isActive,
@需要此.categoryName,
@需要此.displayOrder});
工厂分类。fromData(地图数据、生成的数据库数据库、,
.....
更改了onPressed
这样的方法
ProxyProvider<CategoriesRepository,CategoryBloc>(
builder: (context, categoryRepo, categoryBloc)=>
CategoryBloc(categoryRepository: categoryRepo),
dispose: (context, categoryBloc)=> categoryBloc.dispose(),
).didChangeDependencies(context, _categoryBloc).deleteEntry();
您是否每次都分配
\u categoryBloc
和\u categoryDao
?异常告诉您试图调用空值的deleteEntry
。这可能在您的小部件中,也可能在您的repo类中(不确定是哪个,因为您没有包含堆栈跟踪)是的,你可能只是忘了实例化你的blocwhy问题vote down?@HannesKüttner我添加我自己的答案。谢谢supporting@RodrigoBastos我补充我自己的答案。谢谢你的支持