3

I need listview inside the Column(which is the child of SingleChildScrollView), but it is not showing up!

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class BalanceScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          children: [
            Padding(padding: const EdgeInsets.symmetric(vertical: 24), child: Center(child: Text('15 960 UZS',),),),
            Container(height: 48, alignment: Alignment.centerLeft, padding: EdgeInsets.symmetric(horizontal: 24), 
              child: Row(children: [Text('Refill balance',), Spacer(), FaIcon(FontAwesomeIcons.chevronRight, size: 15,),],),),
            
            ///this is causing problem! But i need listview here
            ListView(
              children: [
                Text('some text 1'),
                Text('some text 2'),
              ],
            )
          ],
        ),
      ),
    );
  }
}

this is showing up in terminal: enter image description here

Akbar Pulatov
  • 2,955
  • 2
  • 16
  • 33

2 Answers2

4

SingleChildScrollView should be removed and ListView should be wrapped with Expanded widget

 Expanded(   
      child:ListView(
              children: [
                Text('some text 1'),
                Text('some text 2'),
              ],
            )
       )

Since the ListView height is infinite and Column widget wants to height value of children. It gives an hasSize expection

Akbar Pulatov
  • 2,955
  • 2
  • 16
  • 33
Furkan
  • 302
  • 3
  • 11
4

Adding shrinkWrap: true inside ListView should resolve the error

NBM
  • 926
  • 13
  • 11
  • It does the job temporarily, but the list become unscrollable. I removed the SingleChildScrollView and wrapped ListView with Expanded widget. – Akbar Pulatov Jan 28 '21 at 12:11