错误的原因是,您在声明方法变量
newValue时必须在变量内部声明该变量为全局变量
StatefulWidget。
String newValue; Widget buildDropdownButton() { return new Padding( padding: const EdgeInsets.all(24.0), child: new Column( mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[ new ListTile( title: const Text('Frosting'), trailing: new DropdownButton<String>( hint: Text('Choose'), onChanged: (String changedValue) { newValue=changedValue; setState(() { newValue; print(newValue); }); }, value: newValue, items: <String>['None', 'Chocolate', 'Vanilla', 'ButterCream'] .map((String value) { return new DropdownMenuItem<String>( value: value, child: new Text(value), ); }).toList()), ), ], ), ); }


