-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Can we access your project?
- I give permission for members of the FlutterFlow team to access and test my project for the sole purpose of investigating this issue.
Current Behavior
If I create a page state variable of type custom Data Type the generated code does not use this variable uniformly over the generated code.
Expected Behavior
The variable should be treated the same way independently of any condition.
Steps to Reproduce
- Create new project
- Head up to Data Types tab and create a new custom data Type called MyClass
- Add the following fields to your data type
a. name, string
b. valid, boolean
- Open the HomePage in your project and add a page state variable
a. Field name: myClassInstance
b. Type: Data Type
c. Data Type: MyClass
Now have a look at the generated code:
The model class, generated by FF, is like this one:
class HomePageModel extends FlutterFlowModel<HomePageWidget> {
/// Local state fields for this page.
MyClassStruct? myClassInstance;
void updateMyClassInstanceStruct(Function(MyClassStruct) updateFn) {
updateFn(myClassInstance ??= MyClassStruct());
}
}
As you can see myClassInstance is declared as nullable, which is correct.
- Back in HomePage add a Column and, within the column, add a TextField and a Switch.
- For the text field widget, go in Text Properties and set initial value to the
namemember of the page state variable, like this
- For the Switch widget, go in Switch Properties and set Switch Initial Value to the
validmember of the page state variable, like this
Now back to the generated code: the initState() method has been updated like this:
class _HomePageWidgetState extends State<HomePageWidget> {
late HomePageModel _model;
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
void initState() {
super.initState();
_model = createModel(context, () => HomePageModel());
_model.textController ??=
TextEditingController(text: _model.myClassInstance?.name);
_model.textFieldFocusNode ??= FocusNode();
_model.switchValue = _model.myClassInstance!.valid;
}
}
Here is the problem: when creating TextEditingController the generated code consider correctly myClassInstance as nullable and uses the conditional access in in _model.myClassInstance?.name
But for switchValue this does not happen and the code is _model.myClassInstance!.valid
Reproducible from Blank
- The steps to reproduce above start from a blank project.
Bug Report Code (Required)
IT4slc/qx89OxL1E7c+BcvlR/SIROVA6ap0kscp/bxIgGIDzPOw+ZPWlVBJocM+mT2xfekSmmkAd0NqNvvHXV+0EIkyBY6Zqz7hUcznzUTmRUZOBDKmBPX9DO+FjfxGB07SzhBJQXctsc0UjwGWyBumuazDbHZe2ImdISq/LZO4=
Visual documentation
Environment
- FlutterFlow version:
- Platform:
- Browser name and version:
- Operating system and version affected:Additional Information
No response