Flutter 如何在颤振中继承对象选项?
是否有方法继承小部件的所有默认值和选项 我正在尝试创建自定义小部件,但我不想声明所有扩展小部件参数 是否有类似“选项”的数组或列表Flutter 如何在颤振中继承对象选项?,flutter,Flutter,是否有方法继承小部件的所有默认值和选项 我正在尝试创建自定义小部件,但我不想声明所有扩展小部件参数 是否有类似“选项”的数组或列表 你应该更喜欢组合而不是继承。颤振API声明性。 class ExampleWidget extends StatelessWidget { @override Widget build(BuildContext context) { return AnotherExampleWidget(foo,bar); } } class AnotherEx
你应该更喜欢组合而不是继承。颤振API声明性。
class ExampleWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AnotherExampleWidget(foo,bar);
}
}
class AnotherExampleWidget extends Container{
final foo,bar;
final child;
AnotherExampleWidget(foo,bar);
@override
Widget build(BuildContext context) {
return container(
child:this.child!=null? this.child: Text("no child widget"),
// My purpose is basically giving my "AnotherExampleWidget" a decoration option without
// declaring it in widget (Container widget got a decoration option and i want to call it at)
// "ExampleWidget")
);
}
}