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

前端 未结 5 1622
刺人心
刺人心 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:43

    Scaffold requires as appbar a class that implements PreferredSizeWidget

    Either wrap your custom appbar into a PreferredSize

    Scaffold(
      appBar: PreferredSize(
        preferredSize: const Size.fromHeight(100),
        child: Container(color: Colors.red),
      ),
    )
    

    or implement PreferredSizeWidget:

    Scaffold(
      appBar: MyAppBar(),
    )
    
    ...
    
    class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
      @override
      Size get preferredSize => const Size.fromHeight(100);
    
      @override
      Widget build(BuildContext context) {
        return Container(color: Colors.red);
      }
    }
    

提交回复
热议问题