[英]The following _TypeError was thrown building RegisterScreen() : type 'String' is not a subtype of type 'int' of 'index'
String? _selectedCity;
List cities = ['Select City'];
@override
void initState() {
super.initState();
_secureText = true;
_getCities();
}
Future _getCities() async {
var url = "baseurl/api/v1/cities";
try {
var response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
var data = json.decode(response.body);
setState(() {
cities = data;
});
}
print(cities);
} catch (e) {
// ignore: avoid_print
print("Error: $e");
}
}
DropdownButton(
hint
: const Text("Select City"), value
: _selectedCity, items
: cities
.map((category) {
return DropdownMenuItem(value
: category['name'], child
: Text(category['name']), );
})
.toList(),
onChanged
: (value) { setState(() { _selectedCity = value as String ? ; }); })
there is problem in my Dropdown Button我的下拉按钮有问题
Value from dropdown were seen before but after update of 2023/1/25, i am facing error "type 'String' is not a subtype of type 'int' of 'index'"下拉列表中的值以前见过,但在 2023 年 1 月 25 日更新后,我遇到错误“type 'String' is not a subtype of type 'int' of 'index'”
Replace this code in your own code.在您自己的代码中替换此代码。 must be correct.
必须正确。
DropdownButton(
hint: const Text("Select City"),
value: _selectedCity,
items: cities
.map((category) {
return DropdownMenuItem(
value: category['name'],
child: Text(category['name'])
);
})
.toList(),
onChanged: (value) {
setState(() {
_selectedCity = value;
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.