[英]Flutter listview
I'm doing a college assignment, I'm trying to do a listview in the "Cursos" class, and it's giving me some problems, if anyone can help I appreciate it!我正在做一项大学作业,我正在尝试在“Cursos”课程中做一个列表视图,这给我带来了一些问题,如果有人能帮助我,我将不胜感激!
If someone has a solution, how and for school work, there is a problem if it gets ugly.如果有人有解决方案,如何以及如何进行学校作业,如果它变得丑陋,就会出现问题。
Error:错误:
════════ 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
════════════════════════════════════════════════════════════════════════════════
Main class主班
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);
}
}
class Cursos.类 Cursos。 This is the class where I want the listview to be made
这是我想要制作列表视图的课程
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')),
),
],
);
}
}
添加shrinkWrap: true,
到你的Curso 类ListView()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.