gpt4 book ai didi

listview - 我的 listView 只显示一个没有内容的空白页面。我该如何解决?

转载 作者:IT王子 更新时间:2023-10-29 07:19:55 25 4
gpt4 key购买 nike

我为包含图片和详细信息的联系人构建 ListView ,但我的页面中没有显示任何内容。它只是空白。

我尝试了两种方法,但都呈现空白页面。

import 'package:flutter/services.dart' show rootBundle;
import 'dart:async';
import 'dart:convert';

import 'package:homenet/pages/search_page.dart';

class PhoneBook extends StatefulWidget {
@override
_PhoneBookState createState() => _PhoneBookState();
}

class _PhoneBookState extends State<PhoneBook> {
List data;
Future<String> loadJsonData() async {
var jsonText = await rootBundle.loadString("data/data.json");
setState(() {
data = json.decode(jsonText);
});
return 'success';
}

@override
void initState() {
// TODO: implement initState
this.loadJsonData();
}

@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return SingleContact(
name: data[index]['name'],
company: data[index]['company'],
cell: data[index]['cell'],
office: data[index]['office'],
picture: data[index]['picture'],
email: data[index]['email'],
);
},
),
);
}
}
class SingleContact extends StatelessWidget {
final name;
final company;
final cell;
final office;
final picture;
final email;

SingleContact({Key key, this.name, this.company, this.cell, this.office, this.picture, this.email});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: new Color(0xFFFA983A),
title: Image.asset(
'assets/images/logo_white.png',
fit: BoxFit.cover,
),
elevation: 0.0,
centerTitle: true,
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.search),
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => new SearchPage()));
},
),
],
),
body: Card(
elevation: 5,
margin: EdgeInsets.all(8.0),
child: Container(
padding: EdgeInsets.all(12.0),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
height: 75,
width: 75,
child: ClipRRect(
borderRadius: BorderRadius.circular(50.0),
child: Image.asset(picture)),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(name,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24.0
),),
Text(company,
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 18.0
)),
Text(email,
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 18.0,
color: Color(0xFFFA983A)
))
],
),
FloatingActionButton(
backgroundColor: Color(0xFFFA983A),
mini: true,
onPressed: (){},
child: Icon(Icons.phone, color: Colors.white,),
),
],
),
],
),
),
),
);
}
}

这是我的代码,有人可以帮助发现问题吗,因为我无能为力。数据来自 data.json 并且文件中的所有信息都是正确的。有些信息重复了,比如“email”,这对空白渲染有什么影响吗?

最佳答案

您不能将 Scoffold 直接放在 ListView 中,您可能应该在 _PhoneBookState 的构建方法中使用 Scaffold。如果您真的想在 ListView 中使用 Scaffold,请使用指定高度的 Container 将其包裹起来。

我很难理解您期望的 UI,也许可以解释一下您希望在列表中看到的内容。

关于listview - 我的 listView 只显示一个没有内容的空白页面。我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56171425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com