Flutter开发中的一些问题

https://blog.csdn.net/qq_17766199/article/details/94849020

1. setState() called after dispose()

这个是我偶然在控制台发现的,完整的错误信息如下:

This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback. The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the “mounted” property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
 

Unhandled Exception: setState() called after dispose(): _AboutState#9c33a(lifecycle state: defunct, not mounted)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flutter 开发,"DragScrollSheet" 是一个用于实现可拖动滚动的小部件。它允许用户在屏幕上拖动内容并进行滚动,类似于滚动视图(ScrollView),但具有更灵活的交互方式。 你可以使用 `DraggableScrollableSheet` 小部件来实现这样的效果。它通常用作页面的底部或侧边面板,用户可以通过拖动该面板来展示更多内容。 以下是一个简单的示例代码,演示了如何使用 `DraggableScrollableSheet`: ```dart @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('DraggableScrollableSheet'), ), body: Stack( children: <Widget>[ // 页面主体内容 ListView.builder( itemCount: 100, itemBuilder: (context, index) => ListTile( title: Text('Item $index'), ), ), // 可拖动的滚动面板 DraggableScrollableSheet( builder: (context, scrollController) => Container( color: Colors.grey[300], child: ListView.builder( controller: scrollController, itemCount: 20, itemBuilder: (context, index) => ListTile( title: Text('Sheet Item $index'), ), ), ), ), ], ), ); } ``` 在这个示例,页面主体内容由一个 `ListView.builder` 构成,其包含了一些简单的列表项。而 `DraggableScrollableSheet` 是一个具有固定高度的容器,里面包含了另一个 `ListView.builder`,用于展示可拖动面板的内容。 你可以根据需要自定义 `DraggableScrollableSheet` 的样式和行为,例如通过设置高度、背景颜色、滚动控制器等。希望这个示例能帮到你!如果有更多问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值