Search code examples
flutterflutter-layout

Incorrect use of ParentDataWidget in my app and dont know what is wrong


I dont know why Incorrect use of ParentDataWidget error is showing while using a column widget . 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 SizedBox widget.

And code is:-

    class HomeWidget extends StatelessWidget {
  const HomeWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      margin: const EdgeInsets.symmetric(horizontal: 20),
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            const SizedBox(
              height: 20,
            ),
            const ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.person),
              ),
              title: Text('Welcome Username!'),
              subtitle: Text('Have a nice day'),
            ),
            const SizedBox(
              height: 20,
            ),
            
            const TextField(
              decoration: InputDecoration(
                hintText: 'Search',
                suffixIcon: Icon(Icons.search),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.all(
                    Radius.circular(10),
                  ),
                ),
              ),
            ),
            const SizedBox(
              height: 10,
            ),
            FirstListView(),
            const Text('Some Links'),
            const SizedBox(
              height: 10,
            ),
            SomeWidget(),
            const Text('some Places'),
            const SizedBox(
              height: 10,
            ),
            SomeWidget(),
            
            const Text('Recent Searches'),
            const SizedBox(
              height: 20,
            ),
            SomeWidget(),
            const SizedBox(
              height: 80,
            ),
          ],
        ),
      ),
    );
  }
}

The screenshot of error image is attached error image


Solution

  • Just add shrinkWrap: true to the inner ListView (FirstListView) like:

     ListView(
                  shrinkWrap: true,
                  children: [
                    SomeInnerWidget(),
                    SomeInnerWidget2(),
                  ],
                ),