Incorrect use of parent data widget. expanded widgets must be placed inside flex widgets

FlutterDart

Flutter Problem Overview


I am getting the following error:

i.e.., Another exception was thrown: Incorrect use of ParentDataWidget. showing error on the mobile screen.

 @override
  Widget build(BuildContext context) {

    return MaterialApp(
      title: widget.title,
      theme: ThemeData.light().copyWith(
        platform: _platform ?? Theme.of(context).platform,
      ),
      home: DefaultTabController(
        length: categoryNames.length,
        child: Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
                 ),
        body: SafeArea(
            child: Column(
              children: <Widget>[
                Chewie(
                  controller: _chewieController,
                ),
                TabBar(
                  labelColor:Colors.black,
                  tabs: categoryNames,
                ),
                Expanded(
                  child: TabBarView(
                    children: [
                      ImageList()
                    ],
                  ),
                )
                /*TabBarView(
                  children: [
                    Icon(Icons.directions_car),
                    Icon(Icons.directions_transit),
                    Icon(Icons.directions_bike),
                  ],
                )*/
              ],
            )
        ),
      ),
      ),
    );
  }

It's my code, please check and let me know the issue.

Flutter Solutions


Solution 1 - Flutter

Expanded cannot be used inside a Stack.

You should use Expanded only within a Column, Row or Flex

Solution 2 - Flutter

First Rule: use Expanded only within a column, row or flex.

Second Rule: Parent column that have expanded child column must be wrapped with expanded as well

Solution 3 - Flutter

there are may things to get this problem

  1. Under ListView don't use Spacer Widget
  2. don't use Positioned under Row or Column
  3. Expanded can only use it must be a descendant of Column Row Flex

Solution 4 - Flutter

there's no expanded in my code so i found that using Spacer() too can cause this error if it's inside a listview

Solution 5 - Flutter

In my case, I was using Positioned inside a column. Removing it solved the problem!

Solution 6 - Flutter

I removed a Positioned widget that was inside a Container inside a Stack and the problem "Incorrect use of ParentDataWidget" went away.

Solution 7 - Flutter

when I skip the video, the chewie controller shows these errors when I fix in chewie package error gone.

please fix in material_controls.dart here

[remove expanded widget in Stack widget]

return MouseRegion(
  onHover: (_) {
    _cancelAndRestartTimer();
  },
  child: GestureDetector(
    onTap: () => _cancelAndRestartTimer(),
    child: AbsorbPointer(
      absorbing: notifier.hideStuff,
      child: Stack(
        children: [
          if (_latestValue.isBuffering)
            const Expanded(
              child: Center(
                child: CircularProgressIndicator(),
              )
            )
          else
            _buildHitArea(),
          _buildActionBar(),
          Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              if (_subtitleOn)
                Transform.translate(
                  offset: Offset(
                      0.0, notifier.hideStuff ? barHeight * 0.8 : 0.0),
                  child:
                      _buildSubtitles(context, chewieController.subtitle!),
                ),
              _buildBottomBar(context),
            ],
          ),
        ],
      ),
    ),
  ),
);

}

Solution 8 - Flutter

This Solution works only if you are using Position as a parent of row or column

In my case, I was using Positioned inside a column. Removing it solved the problem!

Else

Always remember to use Expanded in Row, Column or Flex

Solution 9 - Flutter

In my case, I was using Expanded inside a Padding widget. Padding was inside a column but since Expanded was wrapped by a Padding it gave me the error. Simply removing Expanded solved my issue.

Solution 10 - Flutter

In my case it was because I was enclosing an Expanded inside a SizedBox, I just enclosed the Expanded inside a Row and that's it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMounika View Question on Stackoverflow
Solution 1 - FlutterMark BellView Answer on Stackoverflow
Solution 2 - FluttersecrealView Answer on Stackoverflow
Solution 3 - FlutterAkbar MasterpadiView Answer on Stackoverflow
Solution 4 - Flutteroth manView Answer on Stackoverflow
Solution 5 - FlutterM.AQIBView Answer on Stackoverflow
Solution 6 - FluttermjukkaView Answer on Stackoverflow
Solution 7 - FlutterThaw Thu HanView Answer on Stackoverflow
Solution 8 - FlutterSrikanthView Answer on Stackoverflow
Solution 9 - Fluttersithum dilangaView Answer on Stackoverflow
Solution 10 - FlutteredalvbView Answer on Stackoverflow