【问题标题】:Flutter - Type List<Dynamic> is not subtype of type WidgetFlutter - 类型 List<Dynamic> 不是 Widget 类型的子类型
【发布时间】:2021-05-17 09:03:36
【问题描述】:

我有一个使用 List 的程序,但出现此错误,如何解决?

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(children: [
        CustomScrollView(physics: BouncingScrollPhysics(), slivers: [
          _list(),
        ]),
      ]),
    );
  }

  _list() {
    return List.generate(
      actions.length,
      (i) => _card(actions[i]),
    );
  }


  _card(
String phrase,
  ) {
return SliverToBoxAdapter(
  child: Card(
    shape: RoundedRectangleBorder(
      side: BorderSide(color: Colors.black26, width: 0.1),
      borderRadius: BorderRadius.circular(10),
    ),
    margin: EdgeInsets.only(right: 50, left: 50, top: 20),
    child: InkWell(
      splashColor: Colors.black12,
      borderRadius: BorderRadius.circular(10),
      splashFactory: InkRipple.splashFactory,
      onTap: () => _speak(phrase),
      child: Column(children: <Widget>[
        SizedBox(height: 15.0),
        Padding(
          padding: EdgeInsets.only(left: 15, right: 15),
          child: Text(
            phrase,
            style: TextStyle(
                fontFamily: 'Circular',
                fontSize: 17.0,
                color: Colors.grey[800]),
          ),
        ),
        SizedBox(height: 15.0),
      ]),
    ),
  ),
);
  }

【问题讨论】:

    标签: list flutter widget


    【解决方案1】:

    您的方法_list() 返回一个List&lt;Widget&gt;

    因此,您应该删除CustomScrollView 中的括号:

    CustomScrollView(physics: BouncingScrollPhysics(), slivers: _list()),
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2020-12-10
    • 2018-09-11
    • 2020-04-07
    • 2021-12-02
    • 2019-08-18
    • 2023-03-30
    相关资源
    最近更新 更多