【发布时间】:2022-01-18 16:02:42
【问题描述】:
我正在尝试创建一个扩展原始类的自定义脚手架。 如果没有传递一个新的,则使用默认的 AppBar。
class CommonScaffold extends Scaffold {
final AppBar? appBar;
final Widget body;
CommonScaffold({
Key? key,
this.appBar,
required this.body,
}) : super(
key: key,
body: body,
appBar: appBar ??
AppBar(
title: const Text("Default Text"),
),
);
}
如果我调用类避免传递 appBar 参数,AppBar 将不会出现。但应该会出现。
@override
Widget build(BuildContext context) {
return CommonScaffold(
body: _createContent(),
);
}
如果我调用将 AppBar 传递给 appBar 参数的类,则会出现 AppBar。
@override
Widget build(BuildContext context) {
return CommonScaffold(
body: _createContent(),
appBar: AppBar(
title: const Text("TEST"),
),
);
}
【问题讨论】:
标签: flutter flutter-layout appbar scaffold