我正在做大学作业,我正在尝试在“ Cursos”课程中做一个列表视图,如果有人可以帮助我,它会给我带来一些问题!
如果有人有解决方案,如何以及如何进行学校作业,那么如果丑陋就存在问题。
错误:
════════ Exception caught by rendering library ═════════════════════════════════
'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 545 pos 12: 'child.hasSize': is not true.
The relevant error-causing widget was
ListView
lib\userscreen\userscreen.dart:82
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
Null check operator used on a null value
The relevant error-causing widget was
ListView
lib\userscreen\userscreen.dart:82
════════════════════════════════════════════════════════════════════════════════
主班
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:signupexample/Database/database_helper.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:signupexample/main.dart';
import './avaliacao.dart';
import './consultoria.dart';
import './cursos.dart';
import './sair.dart';
class UserScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() => _UserScreen();
}
class _UserScreen extends State<UserScreen> with WidgetsBindingObserver {
final dbHelper = DatabaseHelper.instance;
Map<String, dynamic> _useData;
bool _fetchingData = true;
@override
void initState() {
_query();
super.initState();
}
int indice = 0;
static List<Widget> telas = <Widget>[
Curso(),
Consultoria(),
Avaliacao(),
Sair()
];
void selecionar(int indice) {
setState(
() {
this.indice = indice;
},
);
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
exit(0);
return true;
},
child: Scaffold(
appBar: AppBar(
title: Text('Home'),
automaticallyImplyLeading: true,
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.home),
label: 'Cursos',
),
BottomNavigationBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.business),
label: 'Consultoria',
),
BottomNavigationBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.warning_rounded),
label: 'Avaliação',
),
BottomNavigationBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.exit_to_app),
label: 'Sair',
),
],
currentIndex: this.indice,
selectedItemColor: Colors.red[0],
onTap: selecionar,
),
body: _fetchingData
? CircularProgressIndicator()
: ListView(
children: [telas.elementAt(this.indice)],
),
),
);
}
void _query() async {
final allRows = await dbHelper.queryAllRows();
print('query all rows:');
allRows.forEach((row) => print(row));
setState(() {
_useData = allRows[0];
_fetchingData = false;
});
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool('isLogin', true);
}
}
Cursos类。这是我要制作列表视图的课程
import 'package:flutter/material.dart';
class Curso extends StatefulWidget {
State<StatefulWidget> createState() => _Curso();
}
class _Curso extends State<Curso> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
return 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')),
),
],
);
}
}
答案 0 :(得分:0)
将shrinkWrap: true,
添加到您的Curso类ListView()