The AppBarDesign can't be assigned to the parameter type 'PreferredSizeWidget'

前端 未结 5 1647
刺人心
刺人心 2021-02-02 06:42

Anyone please give some information why this is happening?

When I try to add a class AppBarDesign which implements appBar flutter is gi

5条回答
  •  没有蜡笔的小新
    2021-02-02 06:52

    If you get the error

    The argument type x can't be assigned to the parameter type 'PreferredSizeWidget'.

    Just wrap x in the PreferredSize widget.

    Example:

    appBar: AppBar(
        bottom: Column(
                  children: [
                    new TabBar(
                      tabs: [
                        new Tab(icon: new Icon(Icons.directions_car)),
                        new Tab(icon: new Icon(Icons.directions_transit)),
                        new Tab(
                          icon: new Icon(Icons.airplanemode_active),
                        )
                      ],
                    ),
                  ],
                ),
    

    Here I get the error: The argument type 'Column' can't be assigned to the parameter type 'PreferredSizeWidget'.

    Solution:

    Click on Column

    Click on light bulb

    Choose Wrap with Widget

    Replace widget with PreferredSize

    Add a PreferredSize attribute, such as preferredSize: Size.fromHeight(100.0),

    Result:

    appBar: AppBar(
         bottom: PreferredSize(
                  preferredSize: Size.fromHeight(100.0),
                  child: Column(
                    children: [
                      new TabBar(
                        tabs: [
                          new Tab(icon: new Icon(Icons.directions_car)),
                          new Tab(icon: new Icon(Icons.directions_transit)),
                          new Tab(
                            icon: new Icon(Icons.airplanemode_active),
                          )
                        ],
                      ),
                    ],
                  ),
                ),
    

提交回复
热议问题