Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect use of ParentDataWidget. Flutter

Tags:

flutter

Does Anyne know what this error is? I think some child cannot be placed inside somthing?

The ownership chain for the RenderObject that received the incompatible parent data was: _GestureSemantics ← RawGestureDetector ← GestureDetector ← Expanded ← ColoredBox ← Container ← Padding ← ColoredBox ← ConstrainedBox ← Container ← ⋯

Container(
                        height: 35,
                        width: 150,
                        color: Colors.blueGrey,
                        child: Row(
                          children: [
                            Container(
                              width: 35,
                              height: double.infinity,
                              color: Colors.blue,
                              child: Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: Container(
                                  color: Colors.black,
                                  child: Expanded(
                                    child: GestureDetector(
                                      onTap: () {
                                        setState(() {
                                          intAmount = int.parse(amount);
                                          intAmount--;
                                          amount = intAmount.toString();
                                          print(intAmount);
                                        });
                                      },
                                      child: SizedBox(
                                        child: Image(
                                          image:
                                              AssetImage('images/plus.png'),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            ),
                            Expanded(
                              child: Container(
                                height: double.infinity,
                                color: Colors.black,
                                child: Center(
                                  child: GestureDetector(
                                    onTap: () {},
                                    child: Text(
                                      '$intAmount',
                                      style: TextStyle(
                                        color: Colors.amber,
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            ),
                            Container(
                              width: 35,
                              height: double.infinity,
                              color: Colors.orange,
                              child: Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: Container(
                                  color: Colors.black,
                                  child: GestureDetector(
                                    onTap: () {
                                      setState(() {
                                        intAmount = int.parse(amount);
                                        intAmount++;
                                        amount = intAmount.toString();
                                        print(intAmount);
                                      });
                                      //*********************************** */
                                    },
                                    child: Expanded(
                                      child: SizedBox(
                                        child: Image(
                                          image: AssetImage(
                                              'images/minus.png'),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            )
                          ],
                        ),
                      )
like image 286
Genzo Avatar asked Nov 24 '25 18:11

Genzo


1 Answers

I have updated you code,The problem is you can't use Expand in child,means that An Expanded widget must be a descendant or parent

example:

 Expanded(
      child: MyWidget(),
    ),

Row

Row(
  children: [
    Expanded(
      child: MyWidget(),
    ),
    Expanded(
      child:Text("Text Widget"),
    ),
  ],
)

in Column

Column(
  children: [
    Expanded(
      child: MyWidget(),
    ),
    Expanded(
      child:Text("Text Widget"),
    ),
  ],
),

not like this

Container(
  child: Expanded(
    child: MyWidget(),
  ),
)

your updated code

Column(
    children: <Widget>[
      Container(
        height: 35,
        width: 150,
        color: Colors.blueGrey,
        child: Row(
          children: [
            Container(
              width: 35,
              height: double.infinity,
              color: Colors.blue,
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Container(
                  color: Colors.black,
                  child: GestureDetector(
                    onTap: () {
                     setState(() {
                        intAmount = int.parse(amount);
                        intAmount--;
                        amount = intAmount.toString();
                        print(intAmount);
                      });
                    },
                    child: SizedBox(
                      child: Image(
                        image: AssetImage('images/plus.png'),
                      ),
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              child: Container(
                height: double.infinity,
                color: Colors.black,
                child: Center(
                  child: GestureDetector(
                    onTap: () {},
                    child: Text(
                      '$intAmount',
                      style: TextStyle(
                        color: Colors.amber,
                      ),
                    ),
                  ),
                ),
              ),
            ),
            Container(
              width: 35,
              height: double.infinity,
              color: Colors.orange,
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Container(
                  color: Colors.black,
                  child: GestureDetector(
                    onTap: () {
                     setState(() {
                        intAmount = int.parse(amount);
                        intAmount++;
                        amount = intAmount.toString();
                        print(intAmount);
                      });
                    },
                    child: SizedBox(
                      child: Image(
                        image: AssetImage('images/minus.png'),
                      ),
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
      )
    ],
  ),

checkout Expanded class

like image 82
Abhijith Avatar answered Nov 26 '25 21:11

Abhijith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!