Я хочу иметь ListView в своем приложении, но при его запуске я получаю сообщение об ошибке, и оно не отображается (и мой пользовательский виджет также не отображается):
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
Когда я удалил столбец, я получил ту же ошибку, но соответствующий виджет, вызывающий ошибку был ListView. Кто-нибудь знает как это исправить? (Я новичок во флаттере, и я не знаю точно, как все должно работать).
Вот мой код: (Я взял код ListView из документации флаттера. Я изменю его, когда он ' сработает)
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 - это пользовательский виджет, который я сделал, он прекрасно работает без ListView.
РЕДАКТИРОВАТЬ: Снимок экрана: снимок экрана, который я вижу на эмуляторе
РЕДАКТИРОВАТЬ: код из моего пользовательского виджета:
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,
),
),
),
);
}
}