我正在创建使用RaisedButton
的自定义窗口小部件
我想将onTap
的事件RaisedButton
导出到父窗口小部件。我该怎么办?
答案 0 :(得分:3)
// your custom widget
class MyCustomWidget extends StatefulWidget {
final VoidCallback onTap;
const MyCustomWidget({Key key, this.onTap}) : super(key: key);
@override
_MyCustomWidgetState createState() => _MyCustomWidgetState();
}
class _MyCustomWidgetState extends State<MyCustomWidget> {
@override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: widget.onTap, // this is called in child
);
}
}
在父级中使用它,如:
MyCustomWidget(
onTap: () {}, // when this is tapped in parent
);