flutter - Flutter:启动应用程序时卸载的小部件和无响应的小部件
问题描述
有一段时间,我一直在尝试学习 Flutter 进行移动开发。所以,一切都很简单,很容易掌握。但是,我似乎无法解决以下问题:
- 调整
CircleAvatar()
中的大小AppBar
:我尝试使用scale
,size
,但没有任何效果。 - 无论我在 1st 之后添加什么
ListView.builder()
,模拟器都不会读取/显示
我的颤振是最新的,当我运行flutter doctor
或运行应用程序时没有显示错误/问题。
谢谢
使用的代码:
class MessageScreen extends StatefulWidget {
static Route<dynamic> route() => MaterialPageRoute(
builder: (context) => MessageScreen(),
);
@override
_MessageScreenState createState() => _MessageScreenState();
}
class _MessageScreenState extends State<MessageScreen> {
String tempLink =
'https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80';
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue[400],
appBar: AppBar(
elevation: 0.0,
leading: CircleAvatar(
backgroundImage: NetworkImage(tempLink),
radius: 15.0,
child: tempLink == null ? Text('HH') : null,
),
title: Text('Chats'),
backgroundColor: Colors.blue[400],
actions: [
IconButton(
onPressed: () {},
icon: Icon(Icons.search),
),
],
),
body: Column(
children: [
Row(
children: [
Container(
child: ListView.builder(
itemCount: newMatching.length,
padding: EdgeInsets.only(left: 6),
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ChatScreen(
user: newMatching[index],
),
),
),
child: _profileButton(tempLink),
);
},
),
),
],
),
SizedBox(
height: 18,
),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20), topRight: Radius.circular(20)),
),
child: ListView.builder(
itemCount: chats.length,
itemBuilder: (BuildContext context, int index) {
final Message chat = chats[index];
return GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ChatScreen(
user: chat.sender,
),
),
),
child: Container(
margin: EdgeInsets.only(top: 5, bottom: 5, right: 1),
padding:
EdgeInsets.symmetric(horizontal: 2, vertical: 5),
decoration: BoxDecoration(
color: chat.unread ? Color(0xFFFFEFEE) : Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(20.0),
bottomRight: Radius.circular(20.0),
),
),
child: _chatNavigatorButton(
chat.sender.imgAvatar,
chat.sender.fname,
chat.text,
chat.time,
chat.unread)),
);
}),
),
],
),
);
}
}
解决方案
- 尝试
CircleAvatar
用 a包装Container
:
Container(height: 10, width: 10, child: CircleAvatar(...))
- 是否有可能
chats
只是长度为 0 而没有元素?也许第二个ListView.builder()
确实显示正确但不包含任何项目。至少这是我可以从给定代码中检索到的。
推荐阅读
- iis - 在 IIS 上发布“托管 Blazor WASM”时出现错误
- python - bs4没有得到所有列表项
- javascript - 如何从Javascript中android.util Base64生成的字节数组中获取字符串
- php - Larave 限制列不适用于多个嵌套关系
- tensorflow - TF2:在非急切模式下计算 keras 回调中的梯度
- python - 我在 ubuntu 18.04 上使用 pycharm 编译我的 py 项目时遇到问题
- npm-install - 如何修复 nodemon@2.0.3 安装后脚本错误?
- mysql - MySQL - 如何对同一列的多个范围求和
- database - 师生答疑——数据库设计
- c - C - 我收到“缺少数组大小”错误,我是在声明数组错误吗?