0

我需要列内的列表视图(它是 SingleChildScrollView 的子项),但它没有显示出来!

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'),
              ],
            )
          ],
        ),
      ),
    );
  }
}

这显示在终端中: 在此处输入图像描述

4

2 回答 2

3

SingleChildScrollView应该被删除并ListView应该用Expanded小部件包裹

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

由于 ListView 高度是无限的,并且 Column 小部件想要孩子的高度值。它给出了 hasSize 期望

于 2021-01-28T11:44:02.490 回答
2

在 ListView 中添加shrinkWrap: true应该可以解决错误

于 2021-01-28T11:58:01.350 回答