Looking to get some clarity as this code is driving me crazy. I am passing data between screens in flutter using an object. Here is what my model file looks like
models.dart
class CompInfo<Map> {
String uid;
String email;
String companyName;
String companyAddress;
bool needLandscapingHelp;
bool needLawnServicesHelp;
CompInfo(
{this.uid = '',
this.email = '',
this.companyName = '',
this.companyAddress = '',
this.needLandscapingHelp=false,
this.needLawnServicesHelp=false,};
}
Screen one: user enters company name and address
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => CompanyProject(
companyinfo: sendCompanyInfo(
companyName.text, comapanyAddress.text))));
helper function on screen 1
CompInfo(compName, compAddress) {
CompInfo compinfo =
CompInfo(companyName: compName, companyPitch: compPitch);
return compinfo;
}
Screen 2:
class CompanyProject extends StatefulWidget {
CompanyInfo companyinfo;
CompanyProject({Key? key, required this.companyinfo}) : super(key: key);
@override
State<CompanyProject> createState() => _CompanyProjectState();
}
class _CompanyProjectState extends State<CompanyProject> {
@override
void initState() {
compinfo=widget.companyinfo;
super.initState();
}
late CompanyProject compinfo;
TextEditingController tellusmore = TextEditingController();
bool mvpBoxyes = false;
bool mvpBoxno = false;
bool errorprompt = false;
List checkboxlist = [
CheckBoxState(
title: 'Lawn',
icon: Icons.computer,
),
CheckBoxState(
title: 'Garden', icon: Icons.smartphone, widgettitle: compinfo.needLandscapingHelp),
]
etc...
I'm basically creating checkboxes and would like the model to update with the value. However the widget title: compinfo.needLandscapingHelp keeps throwing "The instance member 'compinfo' can't be accessed in an initializer. Try replacing the reference to the instance member with a different expression"
Any ideas?