【问题标题】:How to fetch huge data from API to dropdownlist?如何从 API 获取大量数据到下拉列表?
【发布时间】:2022-11-02 16:15:30
【问题描述】:

当我从数据库中获取数据时,它给出了一个错误,错误是不正确的,但这意味着您正在获取大量数据。

这是要获取的数据;

这是此数据的模型:

class DropdownListModel {
  int? id;
  String? name;

  DropdownListModel({this.id, this.name});

  DropdownListModel.fromJson(Map<String, dynamic> json) {
    id = json['Id'];
    name = json['Name'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['Id'] = id;
    data['Name'] = name;
    return data;
  }
}

我试图获取它,但由于它给出了 renderflex 错误的大量数据。

代码用户界面:

                          CustomDropDown(
                        width: 375,
                        focusNode: FocusNode(),
                        icon: const Icon(
                          Icons.keyboard_arrow_down_outlined,
                          size: 30,
                        ),
                        hintText: "Choose Airport",
                        items:
                            airports!.map<DropdownMenuItem<String>>((e) {
                          return DropdownMenuItem<String>(
                            value: e.name,
                            child: Text(
                              e.name!,
                              textAlign: TextAlign.left,
                            ),
                          );
                        }).toList(),
                        onChanged: (value) {
                          setState(() {
                            int index = airports!
                                .indexWhere((e) => e.name == value);
                            destinationAirportId =
                                int.parse(airports![index].id.toString());
                            debugPrint(
                                "destinationAirportId : " + destinationAirportId.toString());
                          });
                        },
                      )

【问题讨论】:

  • 可以分享一下UI的代码吗?
  • 我编辑了,请大佬看看好吗?
  • 是因为庞大的数据还是文本的长度?尝试使用较小的字体大小或使文本溢出。

标签: flutter


【解决方案1】:

我推断这是您的小部件太大,导致水平渲染溢出。如果您直接在 Text 小部件中显示此数据,请尝试这样做(树中小部件的顺序直到 Text 小部件):

Row -> Expanded -> Text

这可能会使文本换行。

没有更多细节很难回答。

【讨论】:

  • 先生,当我更改数据而不是包含长度为 5 或 6 的短数据时,它没有给出此错误,我认为错误发生在 1780 数据长度
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-02
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多