Dart 颤振:生成函数返回null和NoSuchMethodError:对null调用了方法“[]”

Dart 颤振:生成函数返回null和NoSuchMethodError:对null调用了方法“[]”,dart,flutter,Dart,Flutter,我为用户配置文件数据构建了一个表单,但为什么总是在调试控制台中显示这样的消息: I/flatter 31833:引发了另一个异常:构建函数 返回null。I/Flatter 31833:引发了另一个异常: NoSuchMethodError:对null调用了方法“[]”。I/颤振 31833:引发了另一个异常:NoSuchMethodError:方法 对null调用了“[]” 这是我的全部代码: import 'package:flutter/material.dart'; class Edi

我为用户配置文件数据构建了一个表单,但为什么总是在调试控制台中显示这样的消息:

I/flatter 31833:引发了另一个异常:构建函数 返回null。I/Flatter 31833:引发了另一个异常: NoSuchMethodError:对null调用了方法“[]”。I/颤振 31833:引发了另一个异常:NoSuchMethodError:方法 对null调用了“[]”

这是我的全部代码:

import 'package:flutter/material.dart';

class EditProfile extends StatefulWidget {
  final String value;

  EditProfile({Key key, this.value}) : super(key: key);

  @override
  _EditProfileState createState() => _EditProfileState();
}

final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

String selectSex;

class _EditProfileState extends State<EditProfile> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      key: _scaffoldKey,
      appBar: new AppBar(
        title: new Text('Edit Profile'),
      ),
      body: new Padding(
        padding: const EdgeInsets.all(10.0),
        child: new SingleChildScrollView(
          child: new Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              new Padding(
                padding: const EdgeInsets.symmetric(vertical: 10.0),
                child: new TextFormField(
                  decoration: const InputDecoration(
                      border: OutlineInputBorder(), hintText: 'First Name'),
                ),
              ),
              new Padding(
                padding: const EdgeInsets.only(bottom: 10.0),
                child: new TextFormField(
                  decoration: const InputDecoration(
                      border: OutlineInputBorder(),
                      hintText: 'Birth Date'),
                ),
              ),
              new Padding(
                padding: const EdgeInsets.only(bottom: 10.0),
                child: new Container(
                  decoration: new BoxDecoration(
                    border: new Border.all(color: Colors.black),
                    borderRadius: new BorderRadius.all(Radius.circular(4.0)),
                  ),
                  height: 55.0,
                  width: double.infinity,
                  child: new DropdownButtonHideUnderline(
                    child: new DropdownButton<String>(
                      hint: new Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: new Text('Sex'),
                      ),
                      value: selectSex,
                      items: <String>['Man', 'Woman']
                          .map((String value) {
                        return new DropdownMenuItem<String>(
                          value: value,
                          child: new Padding(
                            padding: const EdgeInsets.all(10.0),
                            child: new Text(value),
                          ),
                        );
                      }).toList(),
                      onChanged: (value) {
                        print(value);
                        setState(() {
                          selectSex = value;
                        });
                      },
                    ),
                  ),
                ),
              ),
              new Padding(
                padding: const EdgeInsets.only(bottom: 10.0),
                child: new TextFormField(
                  decoration: const InputDecoration(
                      border: OutlineInputBorder(), hintText: ' Handphone'),
                ),
              ),
              new Padding(
                padding: const EdgeInsets.only(bottom: 10.0),
                child: new TextFormField(
                  decoration: const InputDecoration(
                      border: OutlineInputBorder(), hintText: 'Status'),
                ),
              ),
              new SizedBox(
                width: double.infinity,
                child: new RaisedButton(
                    child: new Text(
                      'Save',
                      style: TextStyle(color: Colors.white),
                    ),
                    color: Colors.orange,
                    onPressed: () {

                    }),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
您应该检查您的项目值:

 items: <String>['Man', 'Woman']
                      .map((value) { // remove the `String` attribute
                    return new DropdownMenuItem<String>(
                      value: value,
                      child: new Padding(
                        padding: const EdgeInsets.all(10.0),
                        child: new Text(value),
                      ),
                    );
                  }).toList(),