0

I Created Custom Widget (cardChild) but it's not showing any element

class ReuseableCard extends StatelessWidget {
  ReuseableCard({required this.colour, required this.cardChild});
  Color colour;
  final Widget cardChild;

Icon And Text both not showing in app

                Expanded(
                  child: ReuseableCard(
                    colour: activeCardColour,
                    cardChild: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Icon(
                          FontAwesomeIcons.mars,
                          size: 80.0,
                        ),
                        Text(
                          'Male',
                          style: TextStyle(
                              fontSize: 18.0, color: Color(0xFF8D8E98)),
                        )],
                    ),
                  ),),

No Error in flutter And please tell why widget require "required" will constructing.

7
  • try putting the "@" symbol in front of the word "required" Commented Feb 17, 2022 at 2:52
  • Showing Error suggesting to remove @ Commented Feb 17, 2022 at 2:55
  • before your semi colon, add this Commented Feb 17, 2022 at 2:57
  • : super(key: key) Commented Feb 17, 2022 at 2:57
  • so, class ReuseableCard extends StatelessWidget { ReuseableCard({required this.colour, required this.cardChild}) : super(key: key); Color colour; final Widget cardChild; Commented Feb 17, 2022 at 2:58

2 Answers 2

1
class ReuseableCard extends StatelessWidget {
  ReuseableCard({required this.colour, required this.cardChild});
  Color colour;
  final Widget cardChild;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: cardChild,    //Here 
      margin: const EdgeInsets.all(15.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10.0),
        color: colour,
      ),
    );}
}

We need to add cardChild in Container.

Sign up to request clarification or add additional context in comments.

Comments

1

hope this will solve you issue..

class SecondRoute extends StatelessWidget {
  const SecondRoute({Key? key, required this.argumentWidget}) : super(key: key);
  
  final Widget argumentWidget;

  @override
  Widget build(BuildContext context) {
    
    return Scaffold(
      body: Column(
        children: [
          argumentWidget,/// this widget is come from FirstRoute screen as you can see we are on second route screen
          customMyWidget(stringData: 'myNameIsFlutterDev'),//this is from your class 
        ],
      ),
    );
  }
  
  // the below widget is your customWidget inside the class
  
  Widget customMyWidget({required String stringData}){
    return Text(stringData);
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.