简体   繁体   中英

Flutter function error: Column's children must not contain any null values, but a null value was found at index 1

After I separate a dropdown list to a separate method in flutter, the debugger returns the following error:

"Column's children must not contain any null values, but a null value was found at index 1"

This is the code I had to a separate method _actionDropdown() :

  _actionDropdown() {
DropdownButton<String>(
            value: actionValue,
            icon: Icon(Icons.arrow_downward),
            iconSize: 24,
            elevation: 16,
            style: TextStyle(
              color: Colors.deepPurple
            ),
            underline: Container(
              height: 2,
              color: Colors.deepPurpleAccent,
            ),
            onChanged: (String newValue) {
              setState(() {
                dropdownValue = newValue;
                // if(dropdownValue == 'Move to...') {
                //   return Text('add chips for folders here');
                // } else if(dropdownValue == 'Label as...') {
                //     return Text('add chips for labels here');
                // }
              });
            },
            items: <String>['Archive', 'Delete', 'Move To...', 'Label as...']
              .map<DropdownMenuItem<String>>((String value) {
                return DropdownMenuItem<String>(
                  value: value,
                  child: Text(value),
                );
              })
              .toList(),
          );

}

This chunk of code for DropdownButton<String> works as a column child but not when I add the separated method _actionDropdown as a child. What am I missing?

As @brendan suggested you forgot to add return keyword.

 _actionDropdown() {
 return DropdownButton<String>( // return added here
            value: actionValue,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM