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

Time:09-28

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

CodePudding user response:

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

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

CodePudding user response:

The issue is using ListView inside SingleChildScrollView, You can use shrinkWrap: true, instead of Expanded on this case but you can just use Column widget here like

const SizedBox(
  height: 10,
),

Column(
  children: [
    for (int i = 0; i < 10; i  ) 
       Text("List item $i")],
),

const Text('Some Links'),
  • Related