为什么会在应用程序中显示?下拉按钮有问题吗



只有在我添加值以显示下拉按钮中的选项后,问题才显示出来。图片显示的是红屏,而不是应用程序,该应用程序表示价值不应为空

代码为

import 'package:flutter/material.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var _calculation = ["Sum ", "Subtraction", "Division", "Multiplication"];
var _currentItemselected = "Add";
@override
Widget build(BuildContext context) {
return Scaffold(
child: ListView(
children: <Widget>[
DropdownButton<String>(
items: _calculation.map((String dropdownStringItem) {
return DropdownMenuItem<String>(
value: dropdownStringItem,
child: Text(dropdownStringItem),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
this._currentItemselected = newValueSelected;
});
value:_currentItemselected;
},
},

of DropDownButton的初始值应该是列表中的一项。

例如,将_currentSelectedIndex的值添加到列表中。

_calculation = ["Add", "Sum ", "Subtraction", "Division", "Multiplication"];

最新更新