gpt4 book ai didi

flutter - AppBarDesign 无法分配给参数类型 'PreferredSizeWidget'

转载 作者:IT老高 更新时间:2023-10-28 12:32:02 29 4
gpt4 key购买 nike

任何人请提供一些信息为什么会发生这种情况?

当我尝试添加实现 appBar 的类 AppBarDesign 时, flutter 会出现以下错误。

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),
);
}
}

最佳答案

在不搜索任何其他主题的情况下实现该功能的有用提示:

class ApplicationToolbar extends StatelessWidget with PreferredSizeWidget{
@override
Widget build(BuildContext context) {
return AppBar( ... );
}

@override
Size get preferredSize => Size.fromHeight(kToolbarHeight);
}

关于flutter - AppBarDesign 无法分配给参数类型 'PreferredSizeWidget',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52678469/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com