【发布时间】:2019-03-11 17:16:40
【问题描述】:
任何人请提供一些信息为什么会发生这种情况?
当我尝试添加实现 appBar 的类 AppBarDesign 时,颤动会出现以下错误。
错误:不能将参数类型“AppBarDesign”分配给参数类型“PreferredSizeWidget”。 (argument_type_not_assignable 在 [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),
);
}
}
【问题讨论】:
-
当我添加 appBar : appBar();它运行良好。当我向它添加一个类时,它只会引发错误。