The argument type 'Widget' can't be assigned to the parameter type 'PreferredSizeWidget?'
2,859
Solution 1
This happens because you declared your header
method with the type Widget
. You should instead declare it with the type PreferredSizeWidget
.
PreferredSizeWidget header() {
return PreferredSize(
preferredSize: Size.fromHeight(70),
child: AppBar(
backgroundColor: backgroundColor1,
),
);
}
Solution 2
change
Widget header() {
return PreferredSize(
preferredSize: Size.fromHeight(70),
child: AppBar(
backgroundColor: backgroundColor1,
),
);
}
to
PreferredSize header() {
return PreferredSize(
preferredSize: Size.fromHeight(70),
child: AppBar(
backgroundColor: backgroundColor1,
),
);
}
Author by
Jon
Updated on December 30, 2022Comments
-
Jon over 1 year
class DetailChatPage extends StatelessWidget { @override Widget build(BuildContext context) { Widget header() { return PreferredSize( preferredSize: Size.fromHeight(70), child: AppBar( backgroundColor: backgroundColor1, ), ); } return Scaffold( backgroundColor: backgroundColor3, appBar: header(), ); } }
i get an error in my code that is The argument type 'Widget' cannot be set to the parameter type 'PreferredSizeWidget?' how to solve this