小编bra*_*dge的帖子

颤振:带有后备文本的 CircleAvatar

我正在学习 Flutter 并想制作一个Widget就像内置的CircleAvatar. 但是,我希望这种行为是

  • 指定图像 ( NetworkImage) 和首字母(即 BB)
  • 当图像未加载时,显示首字母
  • 如果图像确实加载,显示图像并删除首字母

以下代码可以正常工作,但在聊天演示中使用时,由于添加了多个 MyAvatar,它会崩溃。initState 上的断点显示它总是使用输入的第一个消息文本调用 - 不是我所期望的。它也会随着图像“重新加载”而闪烁。小部件似乎以我不明白的方式被重用。

class MyAvatar extends StatefulWidget {                     
  NetworkImage image;
  MyAvatar({this.text}) {
    debugPrint("MyAvatar " + this.text);
    if (text.contains('fun')) {
      this.image = new NetworkImage("https://cdn3.iconfinder.com/data/icons/minicons-for-web-sites/24/minicons2-14-512.png");
    }
  }
  final String text;
  @override                                                        
  MyAvatarState createState() {
    return new MyAvatarState();
  }                    
}

class MyAvatarState extends State<MyAvatar> {
  bool showImage = false;
  @override
  initState() {
    super.initState();
    if (widget.image != null) {
      var completer = widget.image.load(widget.image);
      completer.addListener((info, sync) { …
Run Code Online (Sandbox Code Playgroud)

dart flutter

6
推荐指数
1
解决办法
1万
查看次数

Rxjs - unexpected publishReplay + refCount behaviour after refCount goes to 0

My usecase is this: I connect to a service with a websocket and get periodic (but unpredictable) health data from the service. The app may have multiple users of this data stream, so I want to share it. New subscribers should see the most recently emitted health data. I also want to close the websocket when there are no more subscribers.

My app used shareReplay(1) for quite some time, until it was discovered that it leaks the underlying connection ( …

rxjs rxjs5 rxjs6

6
推荐指数
1
解决办法
523
查看次数

标签 统计

dart ×1

flutter ×1

rxjs ×1

rxjs5 ×1

rxjs6 ×1