首页 > 解决方案 > Flutter:启动应用程序时卸载的小部件和无响应的小部件

问题描述

有一段时间,我一直在尝试学习 Flutter 进行移动开发。所以,一切都很简单,很容易掌握。但是,我似乎无法解决以下问题:

我的颤振是最新的,当我运行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)),
                  );
                }),
          ),
        ],
      ),
    );
  }
}

标签: flutterdart

解决方案


  • 尝试CircleAvatar用 a包装Container
Container(height: 10, width: 10, child: CircleAvatar(...))
  • 是否有可能chats只是长度为 0 而没有元素?也许第二个ListView.builder()确实显示正确但不包含任何项目。至少这是我可以从给定代码中检索到的。

推荐阅读