我创建了由图标和2个堆叠按钮组成的StatelessWidget。
我正在使用2种方法来指定按钮的标签和可见性。 我已经成功覆盖了子类中标签的方法,但是由于某种原因,可见性是从超类中调用的。
此外,在子类中,我在shouldShowFirstButton()上收到“未引用声明”警告
任何帮助将不胜感激。谢谢!
覆盖子类中的属性:
@override
String firstButtonTitleForStatus(UserClassStatus status) {
return "someOverridenLabel"; // this one is called properly
}
@override
bool shouldShowFirstButton() {
return true; // this is never called (only the one from the super class)
}
超类的标签/可见性方法:
bool shouldShowFirstButton() {
return false;
}
String firstButtonTitleForStatus(UserClassStatus status) {
switch (status) {
case UserClassStatus.unknown: ....
return "Some super string";
}
超类的构建方法:
@override
Widget build(BuildContext context) {
UserClassStatus status = someUserStatus;
return Row(
children: <Widget>[
Center(child: classStatusIcon(status)),
Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
child: Container(
width: 100,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Visibility(
maintainSize: false,
visible: shouldShowFirstButton(),
child: MyFlatButton(
title: firstButtonTitleForStatus(status),
onPressed: () async {
handleFirstButtonPressed(
lesson, user, status, context);
}),
),
Visibility(
maintainSize: false,
visible: shouldShowSecondButton(),
child: MyFlatButton(
title: secondButtonTitleForStatus(status),
onPressed: () async {
handleSecondButtonPressed(
lesson, user, status, context);
}),
),
],
),
))
],
);
}
}
答案 0 :(得分:0)
清理,重新启动android studio,重新启动计算机。瞧!