skip to Main Content

while using dropdown text field I got this error

LateInitializationError: Field '_listTileTextStyle@76295511' has not been initialized.

When the exception was thrown, this was the stack:
#0      _DropDownTextFieldState._listTileTextStyle (package:dropdown_textfield/dropdown_textfield.dart)
#1      _DropDownTextFieldState.updateFunction.<anonymous closure> (package:dropdown_textfield/dropdown_textfield.dart:455:41)
dropdown_textfield.dart:455
#2      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15)
binding.dart:1392
#3      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1326:11)
binding.dart:1326
#4      SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1035:9)
binding.dart:1035
#5      PlatformDispatcher.scheduleWarmUpFrame.<anonymous closure> (dart:ui/platform_dispatcher.dart:837:16)
platform_dispatcher.dart:837
#9      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
isolate_patch.dart:184
(elided 3 frames from class _Timer and dart:async-patch)

Here’s the code:

                         DropDownTextField(
                                textStyle: TextStyle(
                                  color: Colors.white,
                                ),
                                listTextStyle: TextStyle(
                                  color: Colors.grey,
                                ),
                                controller: gendercontroller,
                                clearOption: true,
                                dropdownColor: Colors.black,
                                textFieldDecoration:
                                    InputDecoration(
                                  hintText: gender,
                                  border: InputBorder.none,
                                  fillColor: Colors.blue,
                                ),
                                validator: (value) {
                                  if (value == null) {
                                    return "Required field";
                                  } else {
                                    print(gendercontroller
                                        .dropDownValue!.name);

                                    return null;
                                  }
                                },
                                dropDownItemCount: 2,
                                dropDownList: const [
                                  DropDownValueModel(
                                      name: 'Male', value: "Male"),
                                  DropDownValueModel(
                                    name: 'Female',
                                    value: "Female",
                                  ),
                                ],
                                onChanged: (val) {
                                  setState(() {
                                    print(val);
                                  });
                                },
                              )

How to solve the problem

2

Answers


  1. The variable : _listTileTextStyle has not successfully get initialized.

    Try to initialize it on initState() method or whatever to deal with late modifier

    Login or Signup to reply.
  2.   // Adding _listTileTextStyle initialization
      late TextStyle _listTileTextStyle;
    
      @override
      void didChangeDependencies() {
         super.didChangeDependencies();
         _listTileTextStyle = TextStyle(color: Colors.grey); 
         // Initialize _listTileTextStyle here
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search