Nothing works wrong but I still get error message

Viewed 92

I made a page exactly the way I wanted it. Somehow compiler show me an error message every time I go to that page. Nothing seems wrong. Everything works perfectly. Why am I getting this error every time?

My code like this;

Stack(
  children: [
    Image.asset(
      "assets/someImage.jpg",
      fit: BoxFit.cover,
    ),
    Scaffold(
      backgroundColor: Colors.transparent,
      body: ListView(
        children: [
          SlimyCard(), // It's a package from pub.dev
          Expanded(
            child: ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              itemCount: 20,
              itemBuilder: (context, index) {
                return ConstrainedBox(
                  constraints: BoxConstraints(
                    minWidth: MediaQuery.of(context).size.width,
                    minHeight: 50,
                    maxHeight: 500,
                  ),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        child: Row(
                          children: [
                            Text("Some text"),
                            Text("Some text."),
                            Text("Some text.."),
                          ],
                        ),
                      ),
                      Container(
                        child: Text("Some text..."),
                      ),
                    ],
                  ),
                );
              },
            ),
          ),
        ],
      ),
    ),
  ],
);

I tried remove Expanded on ListView and add somewhere else but everything is breaking down.

Compiler says;

Exception has occurred.
FlutterError (Incorrect use of ParentDataWidget.
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 ParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a RepaintBoundary widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
  _ScrollSemantics-[GlobalKey#25b39] ← Scrollable ← ListView ← Expanded ← RepaintBoundary ← IndexedSemantics ← NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← ⋯)
2 Answers

i tried to understand why the Expanded is needed, as the SlimeyCard will take as much as it needs and no more. why did you initially use the Expanded widget?

the code below works for me, try it and say if you get the same results

 return Stack(
  children: [
    Container(height: 1000,width: double.infinity, color: Colors.white,),// instead of the background image
    // Image.asset(
    //   "assets/someImage.jpg",
    //   fit: BoxFit.cover,
    // ),
    Scaffold(
      backgroundColor: Colors.transparent,

      body: ListView(
        children: [
          SlimyCard(bottomCardHeight: 500,),
          ListView.builder(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemCount: 20,
            itemBuilder: (context, index) {
              return ConstrainedBox(
                constraints: BoxConstraints(
                  minWidth: MediaQuery.of(context).size.width,
                  minHeight: 50,
                  maxHeight: 500,
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                      child: Row(
                        children: [
                          Text("Some text"),
                          Text("Some text."),
                          Text("Some text.."),
                        ],
                      ),
                    ),
                    Container(
                      child: Text("Some text..."),
                    ),
                  ],
                ),
              );
            },
          ),

        ],
      ),
    ),
  ],
);

I don't know what your desired UI is, but I made some changes in your code and it works without error. If this isn't something you want, please share the screenshot of your desired UI.

Stack(
  children: [
    Image.asset('assets/someImage.jpg', fit: BoxFit.cover),
    Scaffold(
      backgroundColor: Colors.transparent,
      body: Column(
        children: [
          SizedBox(height: 130, child: Placeholder()), // Replace this with your card.
          Expanded(
            child: ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              itemCount: 20,
              itemBuilder: (context, index) {
                return ConstrainedBox(
                  constraints: BoxConstraints(
                    minWidth: MediaQuery.of(context).size.width,
                    minHeight: 50,
                    maxHeight: 500,
                  ),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        child: Row(
                          children: [
                            Text('Some text'),
                            Text('Some text.'),
                            Text('Some text..'),
                          ],
                        ),
                      ),
                      Text('Some text...'),
                    ],
                  ),
                );
              },
            ),
          ),
        ],
      ),
    ),
  ],
)
Related