Reputation: 239
I am creating my custom widget in which I am using RaisedButton
I want to export onTap
event from RaisedButton
to parent widget. How can I do that?
Upvotes: 8
Views: 2588
Reputation: 268314
Create a custom widget:
class MyCustomWidget extends StatelessWidget {
final String text;
final VoidCallback? onTap;
const MyCustomWidget(this.text, {
Key? key,
this.onTap,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onTap,
child: Text(text),
);
}
}
Usage:
MyCustomWidget(
'My button',
onTap: () {},
)
Upvotes: 16