【问题标题】:RangeError (index): Invalid value: Not in range 0..6, inclusive: -2RangeError(索引):无效值:不在 0..6 范围内,包括:-2
【发布时间】:2019-11-01 12:48:12
【问题描述】:

这是来自官方 Flutter 包站点的通话记录包。我试图学习并实现它以从设备获取呼叫列表,但出现此错误。

    Iterable<CallLogEntry> _callLogEntries = [];

    @override
    Widget build(BuildContext context) {

    var children = <Widget>[];
    _callLogEntries.forEach((entry) {
    children.add(
    Column(
      children: <Widget>[
        Divider(),
        Text('NUMBER   : ${entry.formattedNumber}', style: mono),
        Text('NAME     : ${entry.name}', style: mono),
      ],
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
    ),
  );
 });

return MaterialApp(
  home: Scaffold(
    appBar: AppBar(title: Text('call_log example')),
    body: SingleChildScrollView(
      child: Column(
        children: <Widget>[
          Center(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: RaisedButton(
                onPressed: () async {
                  var result = await CallLog.query();
                  setState(() {
                    _callLogEntries = result;
                  });
                },
                child: Text("Get all"),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(children: children),
          ),
        ],
      ),
    ),
  ),
);

错误:I/flutter (25293):RangeError(索引):无效值:不在 0..6 范围内,包括:-2

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    尝试将var children = &lt;Widget&gt;[]; 移出方法构建。

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 1970-01-01
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 2021-07-08
      • 2023-03-03
      • 2021-01-01
      相关资源
      最近更新 更多