简体   繁体   中英

ListView widget isn't showing on my screen and not working properly (in Flutter)

I want to have a ListView in my app, but when i run it I get an error and it's not showing (and my custom widget also isn't showing):

Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderRepaintBoundary#2aa9b relayoutBoundary=up5 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1687 pos 12: 'hasSize'
The relevant error-causing widget was
Column

When I removed the column, I got the same error but the relevant error-causing widget was ListView. Does someone know how to fix it? (I'm new to flutter and i don't know exactly how things are supposed to work).

Here's my code: (I took the ListView code from the flutter docs. I will change it when it'll work)

class DashboardPage extends StatefulWidget {
  @override
  _DashboardPageState createState() => _DashboardPageState();
}

class _DashboardPageState extends State<DashboardPage> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Column(
        children: <Widget>[
          CustomAppBar('Dashboard'),
          ListView(
            padding: const EdgeInsets.all(8),
            children: <Widget>[
              Container(
                height: 50,
                color: Colors.amber[600],
                child: const Center(child: Text('Entry A')),
              ),
              Container(
                height: 50,
                color: Colors.amber[500],
                child: const Center(child: Text('Entry B')),
              ),
              Container(
                height: 50,
                color: Colors.amber[100],
                child: const Center(child: Text('Entry C')),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

CustomAppBar is a custom widget I made, It works perfectly fine without the ListView.

EDIT: Screenshot: screenshot of what I see on the emulator

EDIT: Code from my custom widget:

class CustomAppBar extends StatelessWidget {

  CustomAppBar(this.title);

  String title = '';

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: MediaQuery.of(context).size.height * 0.30,
      width: double.infinity,
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.vertical(
            bottom: Radius.elliptical(MediaQuery.of(context).size.width, 60.0)
          ),
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [const Color(0XFF3632EA), const Color(0XFF2A27C1)]
          ),
        ),
        child: Container(
          alignment: Alignment.bottomLeft,
          padding: EdgeInsets.only(bottom: 50.0, left: 30.0, right: 30.0),
          child: Text(
            title,
            style: Theme.of(context).textTheme.headline,
          ),
        ),
      ),
    );
  }
}

set shrinkWrap of listView to true. it will solve your issue.

 ListView(
              shrinkWrap: true,
              padding: const EdgeInsets.all(8),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM