skip to Main Content

I have solved an issue thanks to stack overflow..but now getting another issue when i open keyboard it shwoing pixel overflow..i wrap column into Singlechild scroll view but not working…

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

  @override
  Widget build(BuildContext context) {
    return SafeArea(child: Scaffold(
      body: Column(children: [
        Center(child: TextField()),
        Container(
          height: 200,
          color: Colors.green,
          child: Center(child: Text('B')),
        ),
        Container(
          height: 200,
          color: Colors.blue,
          child: Center(child: Text('C')),
        ),
        Container(
          height: 200,
          color: Colors.blue,
          child: Center(child: Text('C')),
        ),
        Expanded(child: buildShowListView())

      ],),
    ));
  }

  Widget buildShowListView()
  {

    return Column(children: [
      Text('Showing Data 100'),
      Expanded(
        child: ListView.builder(
            itemCount: 100,
            itemBuilder: (context,index){
              return Text('$index');
            }),
      )
    ],);
  }
}

2

Answers


  1. Add shrinkWrap: true, It will solve your problem

                  ListView.builder(
                   shrinkWrap: true,
                    itemCount: 100,
                    itemBuilder: (context,index){
                      return Text('$index');
                    }),
    
    Login or Signup to reply.
  2. It is possible the screen height is smaller. We can calculate height Container(height:100*4)=> 400 + 48 + textHeight is having less height when keyboard is visible. You can use ListView on top widget instead.

    Widget build(BuildContext context) {
      return SafeArea(
        child: Scaffold(
          body: ListView(
            children: [
              Container(
                height: 40,
                color: Colors.red,
                child: Center(child: Text('A')),
              ),
              Container(
                height: 40,
                color: Colors.green,
                child: Center(child: Text('B')),
              ),
              Container(
                height: 40,
                color: Colors.blue,
                child: Center(child: Text('C')),
              ),
              buildShowListView(),
            ],
          ),
        ),
      );
    

    And buildShowListView

    Widget buildShowListView() {
        List<String> data = ['1', '2', '3', '4', '5'];
        return Column(
          children: [
            Text('Showing Data ${data.length}'),
            for (var item in data) Text(item),
          ],
        );
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search