When I try to click the button using provider the error will appear: A InspectionFormProvider was used after being disposed. Once you have called dispose() on a InspectionFormProvider, it can 开发者_运维知识库no longer be used. I was wondering how this error should be appeared.
ChangeNotifierProvider(
create: (_) {
return inspectionFormProvider;
},
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(0.0),
child: ElevatedButton.icon(
icon: Icon(...),
label: Text(...),
onPressed: () {
inspectionFormProvider.insertItem();
},
),
),
Consumer<InspectionFormProvider>(
builder: (context, InspectionFormProvider, _) {
return ListView.builder(
itemCount: inspectionFormList.length,
itemBuilder: (context, index) {
return InspectionFormCard(...);
},
);
},
),
],
),
)
I faced such kinda problem some time ago. I didn't find anything in code sample you gave, but here's two possible reason's that you are getting that error:
1. You are using this provider with async await method and that method is executing after dispose method
2. You are passing this provider object from parent class, and inside that class you are disposing it, but in parent class using somewhere
IMPORTANT: These are only predictions, if you provide with screenshot of error message, I can help more. Because mostly there will be showed exactly what line is causing error
精彩评论