Search code examples
flutterdart-null-safety

type 'Null' is not a subtype of type 'DataList' in type cast flutter


======== Exception caught by widgets library =======================================================

The following _CastError was thrown building ItemTags(dirty, dependencies: [DataListInherited], state: _ItemTagsState#a7193): type 'Null' is not a subtype of type 'DataList' in type cast

The relevant error-causing widget was:

ItemTags ItemTags:file:///C:/Users/hp/AndroidStudioProjects/edufly/lib/pages/edit_product/components/edit_product_form.dart:172:22


Solution

  • Your code tries to assign a null to a variable or parameter that expects DataList. Since in such cases DataList or one of its subclass is mandatory, anything else will trigger a similar error. Since null (the unknown) is not a subclass of DataList, you get this error.

    In order to solve this problem, you will need to find line 172 of :///C:/Users/hp/AndroidStudioProjects/edufly/lib/pages/edit_product/components/edit_product_form.dart and carefully review the possible reasons of this anomaly. Once you have understood why a null is being passed, you will be able to either logically fix the error, or handle the edge-case accordingly.