Flutter Custom component

    0

    3

    michaelessiet

    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,
            ),
          ],
        ));
      }
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.