0
3
mmichaelessiet
custom component extends stateless widget with key, text and onPress properties. It also has a build method which takes in a BuildContext .
The Column in the custom component is a widget. Column contains two children: TextButton and Text. TextButton has a child: Text which is the text that will be displayed on the button. TextButton also has an onPressed property which points to the VoidCallback that will be used to execute the onPress event. Text is the child of TextButton. Text contains the text that will be displayed on the widget.
Library: Flutter
class CustomComponent extends StatelessWidget {
const CustomComponent({
Key? key,
required this.text,
required this.onPress,
}) : super(key: key);
final String text;
final VoidCallback onPress;
@override
Widget build(BuildContext context) {
return Card(
child: Column(
children: <Widget>[
Text('$text'),
TextButton(
child: const Text('Press'),
onPressed: onPress,
),
],
));
}
}