Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AppBar will not take title when you use PreferredSize widget. What is the alternative?

Error message:

  • The named parameter ‘child’ is required, but there’s no corresponding argument
  • The named parameter ‘title’ isn’t defined.
@override
Widget build(BuildContext context) {
    double _w = MediaQuery.of(context).size.width;
        return  Scaffold(
        appBar: PreferredSize(title: Text('hi'); //the problem. How should it be used here?
        preferredSize: const Size.fromHeight(100),
        child: Container(color: Colors.blueGrey),
),

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The PreferredSize widget does not have a property called title. You have to use the child property to display the title.

Example:

Widget build(BuildContext context) {
    double _w = MediaQuery.of(context).size.width;
    return  Scaffold(
        appBar: PreferredSize(
          preferredSize: const Size.fromHeight(100),
          child: Container(child: Text('hi')),
        ),

In the child, you can pass any type of widget i.e. Container, Row, Sizedbox, InputField

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading