Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The instance member 'widget' can't be accessed in an initializer in flutter

i want to assign value of defulttitle into the text but its showing some error..

 final foldertitle =
 TextEditingController(text: folderbox.isEmpty ? defulttitle : folderbox.get(1));
class Addnotes extends StatefulWidget {
  const Addnotes(
      {super.key,
     
      
      this.defulttitle = "My passwords.."});

 
  final String defulttitle;
 
  @override
  State<Addnotes> createState() => _AddnotesState();
}

class _AddnotesState extends State<Addnotes> {
 
  BuildContext? myContext;
 
  final foldertitle =
      TextEditingController(text: folderbox.isEmpty ? defulttitle : folderbox.get(1)); //here i cant assign the value of defulttitle into the text..can anyone explain?thank you..

why i cant assign the value of defulttitle into the text..can anyone explain?thank you

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use lazy initialization with late.

BuildContext? myContext;
 
late final foldertitle =....;

Also you can use initState. but you may need to create variable for BuildContext, better will be passing using method.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading