[Solved] Incorrect use of ParentDataWidget in Flutter

Are you struggling with the “Incorrect use of ParentDataWidget” error in Flutter? Read this article to find out how to solve it and get your app up and running smoothly.

The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type BoxParentData.

Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.

Steps to Fix Incorrect use of ParentDataWidget in Flutter

The offending Expanded is currently placed inside a Center widget.

If your terminal complain the  Incorrect use of ParentDataWidget. I sure you broke the framework rules by using child widget to used as parent widget.

Check your code probably you wrap Expanded or Flexible outside of Column or Row.

Error

Expanded(

 child: Column(

   mainAxisAlignment: MainAxisAlignment.center,

   children: <Widget>[

     const Text(

       'You have pushed the button this many times:',

     ),

     Container(

       //  color: Colors.grey,

       decoration: const BoxDecoration(color: Colors.grey),

       child: Text(

         '$_counter',

         style: Theme.of(context).textTheme.headline4,

       ),

     ),

   ],

 ),

),

Related Reading: [Solved] Incorrect use of ParentDataWidget by using positioned widget

Solution

Column(

 mainAxisAlignment: MainAxisAlignment.center,

 children: <Widget>[

   Expanded(

     child: const Text(

       'You have pushed the button this many times:',

     ),

   ),

   Container(

     //  color: Colors.grey,

     decoration: const BoxDecoration(color: Colors.grey),

     child: Text(

       '$_counter',

       style: Theme.of(context).textTheme.headline4,

     ),

   ),

 ],

),

Follow framework guidelines and read terminal message clearly once.

Share:

Ambika Dulal is a Flutter developer from Nepal who is passionate about building beautiful and user-friendly apps. She is always looking for new challenges and is eager to learn new things. She is also a strong believer in giving back to the community and is always willing to help others.

Leave a Comment

AO Logo

App Override is a leading mobile app development company based in Kathmandu, Nepal. Specializing in both Android and iOS app development, the company has established a strong reputation for delivering high-quality and innovative mobile solutions to clients across a range of industries.

Services

UI/UX Design

Custom App Development

Mobile Strategy Consulting

App Testing and Quality Assurance

App Maintenance and Support

App Marketing and Promotion

Contact

App Override

New Plaza, Kathmandu