简体   繁体   English

构建 RegisterScreen() 时抛出了以下 _TypeError:类型“String”不是“index”的“int”类型的子类型

[英]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.

相关问题 TypeError(类型'String'不是'index'类型'int'的子类型) - TypeError (type 'String' is not a subtype of type 'int' of 'index') _TypeError(类型'String'不是'index'类型'int'的子类型) - _TypeError (type 'String' is not a subtype of type 'int' of 'index') _Typeerror(类型“String”不是“index”的“int”的子类型)错误 - _Typeerror ( type 'String' is not a subtype of 'int' of 'index' ) Error _TypeError 在构建 NotesListView(dirty) 时被抛出:“Null”类型不是“String”类型的子类型 - _TypeError was thrown building NotesListView(dirty) : type 'Null' is not a subtype of type 'String' 以下 _TypeError 被抛出构建:类型'MappedListIterable<akcijedokument, widget> ' 不是 'Widget' 类型的子类型</akcijedokument,> - The following _TypeError was thrown building: type 'MappedListIterable<AkcijeDokument, Widget>' is not a subtype of type 'Widget' Flutter/Dart _TypeError(类型'String'不是'index'的'int'类型的子类型) - Flutter/Dart _TypeError (type 'String' is not a subtype of type 'int' of 'index') 以下 _TypeError 被抛出 building Builder(dirty, dependencies: [MediaQuery]): type &#39;Future<Null> &#39; 不是 &#39;Widget&#39; 类型的子类型 - The following _TypeError was thrown building Builder(dirty, dependencies: [MediaQuery]): type 'Future<Null>' is not a subtype of type 'Widget' “String”不是“index”的“int”类型的子类型 - 'String' is not a subtype of type 'int' of 'index' flutter 类型“字符串”不是“索引”的“int”类型的子类型 - flutter type 'String' is not a subtype of type 'int' of 'index' 错误:“String”类型不是“index”类型“int”的子类型 - Error: type 'String' is not a subtype of type 'int' of 'index'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM