'Getting error "Incorrect use of ParentDataWidget." on flutter

The following assertion was thrown while applying parent data.: Incorrect use of ParentDataWidget. The ParentDataWidget Flexible(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.

Usually, this means that the Flexible widget has the wrong ancestor RenderObjectWidget. Typically, Flexible widgets are placed directly inside Flex widgets. The offending Flexible is currently placed inside a RepaintBoundary widget.

enter image description here

My Code is

class Search extends StatelessWidget {
  //final homeProvider;
  final HomeProvider homeProvider;

  Search(this.homeProvider);

  @override
  Widget build(BuildContext context) {
  return Container(
    child: SmartRefresher(
     controller: homeProvider.getSearchRefreshControllerLook(),
     enablePullDown: true,
     enablePullUp: true,
     onRefresh: () {
      debugPrint('on pull to refresh ');
      
     
    //modistaboxApplicationProvider.getTrendingLooksWithLoginStatus();
      homeProvider.getAllLooks();
    },
    onLoading: () {
      debugPrint('next loading --------- ');
      homeProvider.getAllNextLooks();

    },

    child: ListView(
      controller: homeProvider.controllerLooksList,
      children: [
        Selector<HomeProvider, NetWorkResponseStatus>(
            builder: (context, data, child) {
              Widget lookWidget;
              switch (data) {
                case NetWorkResponseStatus.ResponseError:
                  lookWidget = Column(
                    children: <Widget>[
                      SizedBox(
                        height: MediaQuery.of(context).size.height / 3,
                      ),
                      const ModistaboxErrorWidget(
                        error: 'No Internet',
                        visible: true,
                      )
                    ],
                  );
                  break;
                case NetWorkResponseStatus.ResponseEmpty:
                  lookWidget = const EmptyWidget(
                    visible: true,
                  );
                  break;
                case NetWorkResponseStatus.NetworkError:
                  lookWidget = const EmptyWidget(
                    visible: true,
                  );
                  break;
                case NetWorkResponseStatus.ResponseData:
                  lookWidget = getLooksWidget(context, homeProvider);
                  break;
                default:
                  lookWidget = Column(
                    children: <Widget>[
                      SizedBox(
                        height: MediaQuery.of(context).size.height / 3,
                      ),
                      Center(child: CustomProgressIndicator())
                    ],
                  );
                  break;
              }
              return Padding(
                padding: const EdgeInsets.only(left: 5, right: 5),
                child: lookWidget,
              );
            },
            selector: (buildContext, provider) => homeProvider.lookResponseStatus),
      ],
    ),
  ),
);
}



 Widget getLooksWidget(context, HomeProvider homeProvider) {
    return homeProvider.lookListResponce != null &&
    homeProvider.lookListResponce.results.length > 0
    ? GridView.builder(
       shrinkWrap: true,
       itemCount: homeProvider.lookListResponce.results.length,
       scrollDirection: Axis.vertical,
       physics: const ScrollPhysics(),
       gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,
       crossAxisSpacing: 5,
      mainAxisSpacing: 5,
      childAspectRatio: 2 / 3,
  ),
  itemBuilder: (BuildContext context, int index) {
    return lookWidget(index, context,
        homeProvider.lookListResponce.results[index], homeProvider);
  },
)
    : const EmptyWidget(
  visible: true,
  );
 }

 Widget lookWidget(int index, context, ResultsLook look,
  HomeProvider homeProvider) {
  return Stack(
   children: <Widget>[
    InkWell(
      onTap: () {
        debugPrint('look data --- $look');

        
    Navigator.pushNamed(context,TagrankRoutes.lookTagging,arguments: 
       look.image);

      },
      child: CachedNetworkImage(
          imageUrl: look.image,
          fit: BoxFit.fitHeight,
          height: (MediaQuery.of(context).size.height) - 80),
    ),
    Positioned(
      left: 5,
      bottom: 5,
      child: InkWell(
        onTap: () {
          //debugPrint("this is inkwell");
          if (TagRankPreferences().getLoginStatus()) {
            
          } else {
            
            Fluttertoast.showToast(msg: 'Please login to see user profile');

          }
        
        },
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            SizedBox(
              width: 5,
            ),
            Text(
              look.username ?? '',
              style: textStyle12White,
            ),
          ],
        ),
      ),
    ),

    Positioned(
      child: Container(
        height: 16,
        width: 16,
        child: Checkbox(
          checkColor: Colors.red  ,
          activeColor: Colors.white
          //checkColor: dividerColor,
          onChanged:(newValue){
            homeProvider.onClickCheckBox(look);
          },
          value: true,
        ),
      ),
      /*child: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: <Widget>[
          *//* InkWell(
                 child: Icon(
                   Icons.share,
                   color: white,
            ),
          ),*//*

        ],
      ),*/
      right: 5,
      bottom: 5,
    )

  ],
);

} }



Solution 1:[1]

Apparently, you forgot to post the actual code with Flexible.

It seems that you provide the only Flexible widget in the container, so it does not understand what space it should allocate. To fix that, add another Flexible in a Row or a Column so that Flutter knows the proportion of the space you want to dedicate to your widget.

Here is the example of the code:

Row(
    children: [
      Flexible(
          flex: 1,
          child: Container() // your widget here
      ),
      Flexible(
          flex: 2, 
          child: Container() // another widget or an empty container to allocate the space
      ),
    ],
  );

See also: Flutter Flexible.

Solution 2:[2]

Your code is missing the flexible widget which you are trying to explain.

If you are trying to use ListView inside a Flexible or Expanded widget this kind of error is shown. Because it can accept only row, column, or flex.

Try to use a ConstrainedBox or container with a fixed height/width

ConstrainedBox(
  constraints: BoxConstraints(minHeight: 50, maxHeight: 500),
  child: ListView(...),
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sergey S.
Solution 2 Sanjay Chakrapani