Home > Software design >  Flutter ListView is not visible or hidden
Flutter ListView is not visible or hidden

Time:11-16

I am trying to make ListView for my app. when I add listview, listview is not visible or showing.

INFO

Flutter version: 3.3.8 Engine revision 857bd6b74c Dart version 2.18.4 DevTools version 2.15.0

  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[100],
      body: Container(
        padding: const EdgeInsets.only(left: 20, top: 50),
        child: Column(
          children: <Widget>[
            Container(
              padding: const EdgeInsets.all(0),
              child: Column(
                children: [
                  Expanded(
                    child: ListView(
                      shrinkWrap: true,
                      children: <Widget>[
                        Expanded(
                          child: Column(
                            children: [
                              Container(
                                decoration: BoxDecoration(
                                  image: const DecorationImage(
                                    image: NetworkImage("..."),
                                  ),
                                  borderRadius: BorderRadius.circular(20.0)
                                ),
                              ),
                              const Text("Pineapple")
                            ],
                          ),
                        )
                      ],
                    ),
                  )
                ],
              ),
            )
          ],
        )
      )
    );
}

CodePudding user response:

Add property "primary: false"

Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.grey[100], body: Container( padding: const EdgeInsets.only(left: 20, top: 50), child: Column( children: [ Container( padding: const EdgeInsets.all(0), child: Column( children: [ Expanded( child: ListView( shrinkWrap: true, primary:false, children: [ Expanded( child: Column( children: [ Container( decoration: BoxDecoration( image: const DecorationImage( image: NetworkImage("..."), ), borderRadius: BorderRadius.circular(20.0) ), ), const Text("Pineapple") ], ), ) ], ), ) ], ), ) ], ) ) ); }

CodePudding user response:

Just Remove Expand() Widget

return Scaffold( backgroundColor: Colors.grey[100], body: Container( padding: const EdgeInsets.only(left: 20, top: 50), child: Column( children: [ Container( padding: const EdgeInsets.all(0), child: Column( children: [ ListView( shrinkWrap: true, primary: false, children: [ Column( children: [ Container( decoration: BoxDecoration( image: const DecorationImage( image: NetworkImage("..."), ), borderRadius: BorderRadius.circular(20.0)), ), const Text("Pineapple") ], ) ], ) ], ), ) ], )));

CodePudding user response:

Remove Expanded Widgets

Widget build(BuildContext context) { 
  return Scaffold( 
    backgroundColor: Colors.grey[100], 
    body: Container( 
      padding: const EdgeInsets.only(left: 20, top: 50), 
      child: Column( 
        children: [ 
          Container( 
            padding: const EdgeInsets.all(0), 
            child: Column( 
              children: [ 
                ListView( 
                  shrinkWrap: true, 
                  primary:false, 
                  children: [ 
                    Column( 
                      children: [ 
                        Container( 
                          decoration: BoxDecoration( 
                            image: const DecorationImage( image: NetworkImage("..."), ), 
                            borderRadius: BorderRadius.circular(20.0) 
                          ), 
                        ), 
                        const Text("Pineapple") 
                      ],
                    ) 
                  ],
                ) 
              ], 
            ), 
          ) 
        ], 
      ) 
    )
  );
}

CodePudding user response:

Please remove unnecessary widgets like Expanded(), Column(), etc. You don't need to use those widgets cause you use ListView(), ListView() itself takes multiple children. So you won't need to use Column() or Expanded() inside of ListView(). Here is the full solution

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.grey[100],
        body: Container(
          padding: const EdgeInsets.only(left: 20, top: 50),
          child: Column(
            children: <Widget>[
              Container(
                padding: const EdgeInsets.all(0),
                child: Column(
                  children: [
                    ListView(
                      shrinkWrap: true,
                      children: <Widget>[
                        Container(
                          height: 200,
                          decoration: BoxDecoration(
                              image: const DecorationImage(
                                image: NetworkImage(
                                    "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/640px-Image_created_with_a_mobile_phone.png"),
                              ),
                              borderRadius: BorderRadius.circular(20.0)),
                        ),
                        const Text("Pineapple")
                      ],
                    )
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
  • Related