Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

The instance member ‘’ can’t be accessed in an initializer

//to use varialble and not change them
class MyAlert extends StatefulWidget {
  final Map task;
  const MyAlert({Key? key, required this.task}) : super(key: key);

  @override
  State<MyAlert> createState() => _MyAlertState();
}

class _MyAlertState extends State<MyAlert> {
  TextEditingController titleController = TextEditingController();
  @override
  Widget build(BuildContext context) {
 //if you're not using a state management tool to rebuild a certain part
 //the variables below widget build will be reset again 
 //ex: if used setState()
    String dropValue = widget.task['status'];
    titleController.text = widget.task['title'];
    return AlertDialog(....);
  }
}
Source by flutterhq.com #
 
PREVIOUS NEXT
Tagged: #The #instance #member #accessed #initializer
ADD COMMENT
Topic
Name
4+6 =