Home > Mobile >  Listview does not scroll
Listview does not scroll

Time:12-27

The listview I have used in the application I am making with flutter cannot be scrolled. I tried everything but couldn't find the solution.There is no other scroll in the code tree.I also added pysics but it still didn't work. How can i fix this? I'm leaving all the code below. Thank you from now. Here is my code:

Container(
      height: ScreenSize.getScreenHeight(context),
      width: ScreenSize.getScreenWidth(context),
      decoration: Background.setBackground,
      child: Column(
        children: [
          const SizedBox(
            height: 30,
          ),
          const Text(
            "Oylama Oluştur",
            style: TextStyle(
              fontSize: 30,
              fontWeight: FontWeight.w600,
            ),
          ),
          const SizedBox(
            height: 15,
          ),
          const Divider(
            color: Colors.black,
            indent: 25,
            endIndent: 25,
          ),
          const SizedBox(
            height: 50,
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Container(
              //height: ScreenSize.getScreenHeight(context)/2-20,
              width: ScreenSize.getScreenWidth(context) / 1.2,
              decoration: const BoxDecoration(
                borderRadius: BorderRadius.all(const Radius.circular(10)),
              ),
              child: TextFormField(
                onChanged: null,
                decoration: const InputDecoration(
                  hintText: '   Oylama başlığı giriniz',
                  hintStyle: TextStyle(
                    color: Colors.grey,
                    fontSize: 16.0,
                  ),
                  //labelText: "Name" ,
                  labelStyle: TextStyle(
                    color: Colors.black,
                  ),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.all(Radius.circular(10)),
                    borderSide: BorderSide(color: Colors.black, width: 2),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.all(Radius.circular(10)),
                    borderSide: BorderSide(color: Colors.black, width: 2),
                  ),
                ),
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.all(8),
            child: SizedBox(
              width: ScreenSize.getScreenWidth(context) / 1.2,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    //height: ScreenSize.getScreenHeight(context)/2-20,
                    width: ScreenSize.getScreenWidth(context) / 2,
                    decoration: const BoxDecoration(
                      borderRadius:
                          BorderRadius.all(const Radius.circular(10)),
                    ),
                    child: TextFormField(
                      onChanged: null,
                      decoration: const InputDecoration(
                        hintText: '  Ekle',
                        hintStyle: TextStyle(
                          color: Colors.grey,
                          fontSize: 16.0,
                        ),
                        //labelText: "Name" ,
                        labelStyle: TextStyle(
                          color: Colors.black,
                        ),
                        border: OutlineInputBorder(
                          borderRadius:
                              BorderRadius.all(Radius.circular(10)),
                          borderSide:
                              BorderSide(color: Colors.black, width: 2),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderRadius:
                              BorderRadius.all(Radius.circular(10)),
                          borderSide:
                              BorderSide(color: Colors.black, width: 2),
                        ),
                      ),
                    ),
                  ),
                  SizedBox(
                    width: ScreenSize.getScreenWidth(context) / 4,
                    height: 60,
                    child: ElevatedButton(
                      onPressed: () {},
                      style: ElevatedButton.styleFrom(
                          primary:
                              const Color.fromARGB(222, 167, 162, 162),
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(10))),
                      child: const Text("Ekle",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                            fontSize: 20,
                            fontWeight: FontWeight.bold,
                          )),
                    ),
                  ),
                ],
              ),
            ),
          ),
          ListView.builder(
            itemCount: entries.length,
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            
            itemBuilder: (BuildContext context, int index) {
              return ListTile(
                title: Text('Item ${entries[index]}'),
              );
            },
          )
          //button(context),
        ],
      )),

Here is the list:

final List<String> entries = <String>['A', 'B', 'C', 'B', 'C', 'B', 'C', 'B', 'C', 'B', 'C', 'B', 'C', 'C', 'B', 'C', 'C', 'B', 'C'];

CodePudding user response:

Wrap your ListView with Expanded to get all the space available in column:

Expanded(
    child: ListView.builder(
      itemCount: entries.length,
      scrollDirection: Axis.vertical,
      shrinkWrap: true,
      itemBuilder: (BuildContext context, int index) {
        return ListTile(
          title: Text('Item ${entries[index]}'),
        );
      },
    ),
  )

CodePudding user response:

In your code, your ListView is within a Column which can't scroll. So wrap your ListView in an Expanded widget:

  Expanded(
            child: ListView.builder(
              shrinkWrap: true,

              itemCount: entries.length,
              scrollDirection: Axis.vertical,
              itemBuilder: (BuildContext context, int index) {
                return ListTile(
                  title: Text('Item ${entries[index]}'),
                );
              },
            ),
          )
  • Related