0

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

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Akshay
  • 55
  • 5

1 Answers1

1

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.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
  • I appreciate it..if you dont feel bad can you explain because of why this error was came? – Akshay Mar 29 '23 at 18:25
  • It was added on null-safety,you can check analysis_options default rules, and [lazy-initialization ](https://dart.dev/null-safety/understanding-null-safety#lazy-initialization) – Md. Yeasin Sheikh Mar 29 '23 at 18:28