Open iamprakash13 opened 4 years ago
searchTextField
is null
, maybe try checking whether it's mounted or not?
@ericomine how to check that?
void setCusno() {
setState(() {
if (!mounted) return;
searchTextField.textField.controller.text = widget.custno;
});
}
it still shows the same error. we can't fix value before building this widget. we need to set value after the widget is initialized. but how to do that? @felixlucien
Sorry, I miss interpreted the error message before. What seems to be null is actually the textField that's retrieved by the getter, which is initialized inside the AutoCompleteTextField state constructor.
Maybe that constructor call hasn't finished yet when you're assigning this value? Can you check the textField for null before assigning and see if it'll at least build?
Can you provide more details/context?
I am facing the same problem, is this issue fixed ?
Sorry, I miss interpreted the error message before. What seems to be null is actually the textField that's retrieved by the getter, which is initialized inside the AutoCompleteTextField state constructor.
Maybe that constructor call hasn't finished yet when you're assigning this value? Can you check the textField for null before assigning and see if it'll at least build?
Can you provide more details/context?
So the following is on my initstate ( imagesToPost.mlMake.toString() is supposed to be 'Toyota' ) :
try {
print( "imagesToPost.mlMake.toString() IS ============== ${imagesToPost.mlMake.toString()}");
searchTextFieldMake.textField.controller.text = imagesToPost.mlMake.toString()';
} catch (e) {
print("CATCHED ERROR IS ============== $e");
}
And i get this in my following try and catch error: NoSuchMethodError: The getter 'mlMake' was called on null.
So basically what i am doing is: I get a String from my API response and save it in imagesToPost.mlMake.toString() on my first screen so that i can show it in the next screen on my AutoCompleteTextField .
If the AutoCompleteTextField is in the same screen where i am calling the API, and i assign the string direct from the API response to the AutoCompleteTextField, it works perfectly fine.
But if the AutoCompleteTextField is in the next page, i can not assign the value to that field if its in the second screen from the initstate.
I can initialize textfield controller in init function. but can't do with autocomplete textfield. it shows error while running code.
this line:
searchTextField.textField.controller.text = widget.custno;
log:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'textField' was called on null. E/flutter (23780): Receiver: null E/flutter (23780): Tried calling: textField E/flutter (23780): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/flutter (23780): #1 _EditBillPageState.setValues.<anonymous closure> package:audit_shop/pages/bill_edit_page.dart:101 E/flutter (23780): #2 State.setState package:flutter/…/widgets/framework.dart:1148 E/flutter (23780): #3 _EditBillPageState.setValues package:audit_shop/pages/bill_edit_page.dart:95 E/flutter (23780): #4 _EditBillPageState.initState
how do I resolve this?