Once I tried to add appBar to the feed page it is raising error.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wecare_u/constants/Constantcolors.dart';
class FeedHelpers with ChangeNotifier {
ConstantColors constantColors = ConstantColors();
Widget appBar(BuildContext context) {
return AppBar(
backgroundColor: constantColors.darkColor,
centerTitle: true,
actions: [
IconButton(
icon: Icon(Icons.camera_enhance_rounded,
color: constantColors.greenColor),
onPressed: () {})
],
title: RichText(
text: TextSpan(
text: 'Social ',
style: TextStyle(
color: constantColors.whiteColor,
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
children: <TextSpan>[
TextSpan(
text: 'Feed',
style: TextStyle(
color: constantColors.blueColor,
fontWeight: FontWeight.bold,
fontSize: 20.0,
))
]),
),
);
}
}
Above is my Feed_helpers.dart file which contains the code for the page.
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wecare_u/Designs/Feed_helpers.dart';
class Feed extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: Provider.of<FeedHelpers>(context, listen: false).appBar(context),
);}}
This is my feed.dart file, When I tried to add appBar in this page it is raising error as 'The argument type 'Widget' can't be assigned to the parameter type 'PreferredSizeWidget?'.'
CodePudding user response:
Try to wrap AppBar widget with PreferredSize Widget.
PreferredSize(
preferredSize: Size.fromHeight(20.0), // height of appbar
child: AppBar(
..........
),
),