'type 'Null' is not a subtype of type 'String' of 'function result' when update the provider model

Provider version and dart

provider: ^6.0.1
sdk: ">=2.12.0 <3.0.0"

I have two screens.

Screen A - I have a form. when you tap on the textbox it will open a Screen B Full screen Modal.

Screen B - you will choose an item from the list in and return back to Screen A.

In the Screen A textbox i have wrapped with consumer method.

Consumer<AgentModel>( //                    <--- Consumer
        builder: (context, agentModel, child) {
          agentController.text = agentModel.name.toString();
          return  AppInputWrapper(
            marginBottom: 'small',
            widgets: Column(
              children: [
                TextFormField(
                  style: appInputStyle,
                  keyboardType: TextInputType.text,
                  autocorrect: false,
                  enableSuggestions: false,
                  decoration: AppInputStyleDecoration.textFieldStyle(hintTextStr: "Agent"),
                  controller: agentController,
                  validator: (value) {
                    return validateAgent(value);
                  },
                  readOnly: true,
                  onTap: (){
                    Navigator.push(  context, MaterialPageRoute( builder: (context) => AgentFormComponent(),),);
                  },
                ),
              ],
            ),
          );
        }
    )

When the first instance it comes from screen B to screen A its not loading the value from provider. i get the following error.

======== Exception caught by widgets library =======================================================
The following _TypeError was thrown building Consumer<AgentModel>(dirty, dependencies: [_InheritedProviderScope<AgentModel?>]):
type 'Null' is not a subtype of type 'String' of 'function result'

The relevant error-causing widget was: 
  Consumer<AgentModel> file:///Users/soundharraj/StudioProjects/LHMarine/lib/screens/jobs/create/form.dart:389:13
When the exception was thrown, this was the stack: 
#0      _Location.file (package:flutter/src/widgets/widget_inspector.dart)
#1      _Location.toJsonMap (package:flutter/src/widgets/widget_inspector.dart:2844:15)
#2      _Location.toJsonMap.<anonymous closure> (package:flutter/src/widgets/widget_inspector.dart:2853:42)
#3      MappedListIterable.elementAt (dart:_internal/iterable.dart:412:31)
#4      ListIterator.moveNext (dart:_internal/iterable.dart:341:26)
...
====================================================================================================
Reloaded 1 of 1128 libraries in 592ms.

I am not sure how to check the provider value is NULL. its turn the string.

Thanks



Solution 1:[1]

Wrap your TextFormField with Gesturedetector on write your function on the ontab.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anandh Krishnan