Failed assertion: line 5143 pos 16: 'child is! ParentDataElement<ParentData>': is not true

123

On your snippet replace

 Expanded(child: Expanded(
            child: Reusable_card(changeColor: activeCardColor,),
          )),

with

 Expanded(
   child: Reusable_card(
       changeColor: activeCardColor,),
       )

Remove one Expanded from here, we don't need to wrap Expanded with another Expanded.

And for bottom Container with height: double.infinity, you need to remove this. If you just want background color, use backgroundColor

    return Scaffold(
      backgroundColor: yourColor,
      body: ...

Or for customizing/image use Stack widget.

You can check Layouts in Flutter.

Share:
123
Nonsookongwu
Author by

Nonsookongwu

Updated on January 04, 2023

Comments

  • Nonsookongwu
    Nonsookongwu over 1 year

    I am trying to use a Gesturedetector widget on my card to initiate onTap properties. I have both cards, male and Female and each card widgets get pressed once and never works again until i run a full restart of the app. I mean, if i press the male card first, i will have to run gradle and make a whole restart before i could press the female card.

    This is my code: I am new to flutter... i need help

    import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';
    import 'package:font_awesome_flutter/font_awesome_flutter.dart';
    import 'package:bmi_calculator/Icon_content.dart';
    import 'package:bmi_calculator/Reusable_card.dart';
    
    const bottomContainerHeight = 70.0;
    const activeCardColor = Color(0xFF272A4E);
    const inactiveCardColor = Color(0xFF111328);
    const bottomContainerColor = Color(0xffEB1555);
    
    class InputPage extends StatefulWidget {
      @override
      _InputPageState createState() => _InputPageState();
    }
    
    class _InputPageState extends State<InputPage> {
    
      Color maleCardColor = inactiveCardColor;
      Color femaleCardColor = inactiveCardColor;
    
      //1 = male, 2 = Female
      void updateColor (int gender){
        if (gender == 1){
          if (maleCardColor == inactiveCardColor){
            maleCardColor = activeCardColor;
          } else {
            maleCardColor = inactiveCardColor;
          }
        }
        if (gender == 2){
          if (femaleCardColor == inactiveCardColor){
            femaleCardColor = activeCardColor;
          } else{
            femaleCardColor = inactiveCardColor;
          }
        }
      }
    
    
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('BMI CALCULATOR'),
          ),
          body: Column(
            children: [
              Expanded(child: Row(
                children: [
                  Expanded(
                    child: GestureDetector(
                      onTap: (){
                        setState(() {
                          updateColor(1);
                        });
                        print('male card was pressed');
                      },
                      child: Reusable_card(changeColor: maleCardColor,
                      cardChild: TopCardContent(
                        gender: FontAwesomeIcons.mars,
                        label: 'MALE',
                      ),
                      ),
                    ),
                  ),
                  Expanded(
                    child: GestureDetector(
                      onTap: (){
                        setState(() {
                          updateColor(2);
                        });
                        print('female was pressed');
                      },
                      child: Reusable_card(changeColor: femaleCardColor,
                        cardChild: TopCardContent(
                          label: 'FEMALE',
                          gender: FontAwesomeIcons.venus,
                        ),
                      ),
                    ),
                  )
                ],
              )),
              Expanded(child: Expanded(
                child: Reusable_card(changeColor: activeCardColor,),
              )),
              Expanded(child: Row(
                children: [
                  Expanded(
                    child: Reusable_card(changeColor: activeCardColor,),
                  ),
                  Expanded(
                    child: Reusable_card(changeColor: activeCardColor,),
                  )
                ],
              )),
              Container(
                color: bottomContainerColor,
                margin: EdgeInsets.only(top: 10.0),
                width: double.infinity,
                height: bottomContainerHeight,
              )
            ],
          )
        );
      }
    }
    

    These are the errors I get:

    ======== Exception caught by widgets library =======================================================
    The following assertion was thrown while looking for parent data.:
    Incorrect use of ParentDataWidget.
    
    The following ParentDataWidgets are providing parent data to the same RenderObject:
    - Expanded(flex: 1) (typically placed directly inside a Flex widget)
    - Expanded(flex: 1) (typically placed directly inside a Flex widget)
    However, a RenderObject can only receive parent data from at most one ParentDataWidget.
    

    and this

    ======== Exception caught by widgets library =======================================================
    The following assertion was thrown building _BodyBuilder:
    'package:flutter/src/widgets/framework.dart': Failed assertion: line 5143 pos 16: 'child is! ParentDataElement<ParentData>': is not true.
    
    
    Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
    In either case, please report this assertion by filing a bug on GitHub:
      https://github.com/flutter/flutter/issues/new?template=2_bug.md