我想创建一个新的Widget
来包裹IconButton
并覆盖其onPressed
属性,但是我希望这个新的Widget
接受所有IconButton
的其他属性。
在React Native中,我可以将一个组件的propsTypes
设置为另一个组件的propsTypes
。
以下是我需要的示例:
class AudioWidget extends StatelessWidget {
final Icon child;
AudioWidget(this.child); // How do I get all of IconButton's properties?
@override
Widget build(BuildContext context) {
return IconButton(
icon: child,
onPressed: () => play(context), // Some custom function
);
}
}
答案 0 :(得分:0)
您可以通过使用骇客的方式使用构造函数来做到这一点
.navbar {
z-index: 9 !important;
}
另一个具有多个参数的示例是
class AudioWidget extends StatelessWidget {
final Icon child;
AudioWidget(this.child):mySize=child.size; // In the contructor now we are getting the size and assignin it to OUR size
final double mySize;
@override
Widget build(BuildContext context) {
return IconButton(
icon: child,
onPressed: () {}// Some custom function
);
}
}