Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

Anyone please give some information why this is happening?

When I try to add a class AppBarDesign which implements appBar flutter is giving the below error.

error: The argument type 'AppBarDesign' can't be assigned to the parameter type 'PreferredSizeWidget'. (argument_type_not_assignable at [flutterbyrajath] lib\main.dart:27)

    import 'package:flutter/material.dart';      main() {       runApp(new MyApp());     }      class MyApp extends StatelessWidget {       @override       Widget build(BuildContext context) {         return MaterialApp(           title: 'Rajath\'s design ',           debugShowCheckedModeBanner: false,           theme: new ThemeData(primarySwatch: Colors.amber),           home: new MyHomePage(key, 'App is Fun'),         );       }     }      class MyHomePage extends StatelessWidget {       MyHomePage(Key key, this.title) : super(key: key);        final title;        @override       Widget build(BuildContext context) {         return new Scaffold(           appBar: new AppBarDesign(key, title),         );       }     }      class AppBarDesign extends StatelessWidget {       AppBarDesign(Key key, this.title) : super(key: key);        final title;        @override       Widget build(BuildContext context) {         return new AppBar(           title: new Text(title),         );       }     } 
like image 824
Rajath Avatar asked Oct 06 '18 11:10

Rajath


People also ask

What is PreferredSizeWidget in flutter?

A widget with a preferred size. This widget does not impose any constraints on its child, and it doesn't affect the child's layout in any way. It just advertises a preferred size which can be used by the parent. Parents like Scaffold use PreferredSizeWidget to require that their children implement that interface.


1 Answers

helpful tips to implementing that without searching any other topics:

class ApplicationToolbar extends StatelessWidget with PreferredSizeWidget{   @override   Widget build(BuildContext context) {     return AppBar( ... );   }    @override   Size get preferredSize => Size.fromHeight(kToolbarHeight); } 
like image 110
DolDurma Avatar answered Oct 06 '22 01:10

DolDurma