最佳答案
有人能告诉我为什么会这样吗?
当我试图添加一个类 AppBarDesign,它实现 应用程序吧颤振是给出下面的错误。
错误: 参数类型‘ AppBarDesign’不能分配给参数类型‘ PreferredSizeWidget’
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),
);
}
}