【问题标题】:I keep on getting this error in Flutter itemBuilder我在 Flutter itemBuilder 中不断收到此错误
【发布时间】:2021-04-10 06:11:54
【问题描述】:

这显示在 android studio 构造函数返回的类型 'dynamic' 不是预期的类型 'Widget' 并且还给了我这个参考 package:flutter/src/material /scaffold.dart

body: new Container(
          child: new Column(
            children: <Widget>[
              new Flexible(
                child: new FirebaseAnimatedList(
                  query: reference,
                  padding: const EdgeInsets.all(8.0),
                  reverse: true,
                  sort: (a, b) => b.key.compareTo(a.key),
                  itemBuilder: (_, DataSnapshot messageSnapshot, Animation<double> animation, int index) {
                    return new ChatTextController(
                      messageSnapshot: messageSnapshot,
                      animation: animation,
                    );
                  },
                ),
              ),
              new Divider(height: 1.0),
              new Container(
                decoration:
                new BoxDecoration(color: Theme.of(context).cardColor),
                child: _buildTextComposer(),
              ),
              new Builder(builder: (BuildContext context) {
                _scaffoldContext = context;
                return new Container(width: 0.0, height: 0.0);
              })
            ],
          ),
          decoration: Theme.of(context).platform == TargetPlatform.android
              ? new BoxDecoration(
              border: new Border(
                  top: new BorderSide(
                    color: Colors.grey[200],
                  )))
              : null,
        )

【问题讨论】:

  • 引用package:flutter/src/material/scaffold.dart 表示您的问题与Scaffold 的构造函数有关。您是否在任何特定行上收到此错误?是你得到的所有信息还是有更详细的错误信息?

标签: firebase flutter dart firebase-realtime-database


【解决方案1】:

确保这个控制器返回一个像 Container 之类的 Widget 而不是动态值:

ChatTextController(
                      messageSnapshot: messageSnapshot,
                      animation: animation,
);

ListView 的 itemBuilder 属性总是期望其构建器函数返回一个 UI 小部件

【讨论】:

    猜你喜欢
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-19
    • 2021-11-28
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 2021-12-16
    相关资源
    最近更新 更多