0

Flutter: I am using exansion tile foe displaying the items and i have wrapped in a column to display all the list present in the expansion tile when the expansion tile is clicked and i have show without problem for both the portrait and landscape mode but in the landscape mode due to the insufficient space it is throwing an exception as space is not sufficient.

I am trying to display a list of items in expansion tile,it is working in portrait mode,but when the mode is changed to landscape it is throwing exception. I have attached my code here.

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
    home: Scaffold(
        appBar: AppBar(
          title: Text("Appbar"),
        ),
        body: MyApp())));

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        ExpansionTile(
          title: Text("Filters"),
          children: <Widget>[
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
            Text("Hello"),
          ],
        ),
        Expanded(
          child: ListView(
            children: <Widget>[
              Column(
                children: <Widget>[
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here"),
                  Text("test id here")
                ],
              )
            ],
          ),
        )
      ],
    );
  }
}```





I am looking for the contents should to be displayed in the listview inside the expansion tile and also it is coming properly in the portrait mode but it is failing in the landscape mode throwing following exception.

```I/flutter ( 5943): Another exception was thrown: Incorrect use of ParentDataWidget.
I/flutter ( 6076): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 6076): The following assertion was thrown building _BodyBuilder:
I/flutter ( 6076): Incorrect use of ParentDataWidget.
I/flutter ( 6076): Expanded widgets must be placed inside Flex widgets.
I/flutter ( 6076): Expanded(no depth, flex: 2, dirty) has no Flex ancestor at all.
I/flutter ( 6076): The ownership chain for the parent of the offending Expanded was:
I/flutter ( 6076):   _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ←
I/flutter ( 6076): AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#fdec2 ink
I/flutter ( 6076): renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ← 

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 197 pixels on the bottom.

The relevant error-causing widget was: 
  Column file:///Users/praveenramalingam/news_feed_new/lib/pages/home_page.dart:129:13
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#0808f relayoutBoundary=up1 OVERFLOWING
...  needs compositing
...  parentData: offset=Offset(0.0, 80.0); id=_ScaffoldSlot.body (can use size)
...  constraints: BoxConstraints(0.0<=w<=689.4, 0.0<=h<=331.4)
...  size: Size(689.4, 331.4)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ (2) Exception caught by image resource service ════════════════════════════════════════════
Failed host lookup: 'cdn.mos.cms.futurecdn.net' (OS Error: No address associated with hostname, errno = 7)
════════════════════════════════════════════════════════════════════════════════════════════════════```


[![Landscape Mode- Exception][1]][1]


[![Portrait mode - No exception][2]][2]


  [1]: https://i.stack.imgur.com/JR7cI.png
  [2]: https://i.stack.imgur.com/DGLw4.png
Praveen Ramalingam
  • 867
  • 2
  • 7
  • 14
  • Please try to reduce your code sample to the minimum size that reproduces the error. That will help others help you. – David Hempy Jan 29 '20 at 19:09
  • Does this answer your question? [Flutter (Dart): Exceptions caused by rendering / A RenderFlex overflowed](https://stackoverflow.com/questions/49480051/flutter-dart-exceptions-caused-by-rendering-a-renderflex-overflowed) – Aleksandr Belugin Jan 29 '20 at 22:11

1 Answers1

1

That's because of the ExpansionTile items are not scrollable. Wrap your Column widget with SingleScrollChildView and remove the ListView in the Column because it will provide the functionality you require.

Widget build(BuildContext context) {
return SingleChildScrollView(
  child: Column(
    children: <Widget>[
      ExpansionTile(
        title: Text("Filters"),
        children: <Widget>[
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
          Text("Hello"),
        ],
      ),
      Text("test id here"),
      Text("test id here"),
      Text("test id here"),
      Text("test id here"),
      Text("test id here"),
      Text("test id here"),
      Text("test id here"),
      Text("test id here"),
      Text("test id here"),
      Text("test id here"),
      Text("test id here")        ],
  ),
);

}

Ayush Bherwani
  • 2,409
  • 1
  • 15
  • 21
  • This one makes the expansion tile to scroll along with the below column content.What i need is,i want the contents inside expansion tile to be scrollable and contents below expansion tile to be scrollable,users can be able to see the expansion tile from any scroll position – Praveen Ramalingam Jan 30 '20 at 04:43
  • How to make expansion tile items scrollable – Praveen Ramalingam Jan 31 '20 at 05:39
  • As far as I know, it won't be possible that you stick the `ExpansionTile` at the top and scroll the items. You will require to make your own widget to try this. You can stick a `ListTile` at the top and when you click on `ListTile` you can a `ListView`. – Ayush Bherwani Jan 31 '20 at 05:55