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), ); } }
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.
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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With