anilraj
anilraj

Reputation: 73

Flutter - Not able to scroll Listview

I'm trying to write basic Listview example, however not able to scroll down, screen is fixed not able to view all items.

Tried with working example from flutter official documentation (displaying Listview till items29) https://api.flutter.dev/flutter/widgets/ListView-class.html

Not able to figure out Whether it is settings issue or other.

import 'package:flutter/material.dart';

class mySquare extends StatelessWidget {
  String child;
  mySquare({required this.child});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Container(height: 200, color: Colors.amber, child: Text(child)),
    );
  }
}

class HomePage extends StatelessWidget {
  List posts = ['post1', 'post2', 'post3', 'post4', 'post5', 'post6'];

  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
        itemCount: posts.length,
        itemBuilder: ((BuildContext context, index) {
          return mySquare(
            child: posts[index],
          );
        }),
      ),
    );
  }
}

Upvotes: 0

Views: 46

Answers (1)

powerman23rus
powerman23rus

Reputation: 1583

I launched your code on Android emulator and it works as expected.

If the device is big enough for all items ListView wouldn't scroll

enter image description here

Upvotes: 1

Related Questions