unified_popups 1.2.2
unified_popups: ^1.2.2 copied to clipboard
A unified popups SDK for Flutter, providing a flexible way to show toasts, dialogs, and other custom popups.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
1.2.2 #
Performance Optimizations ⚡ #
PopScopeWidget Rebuild Optimization
- 重构 PopScopeWidget:从
StatelessWidget+ValueListenableBuilder改为StatefulWidget - 减少 90%+ 不必要重建:只在
hasNonToastPopup状态真正变化时才触发setState - 避免子树重建:
child参数永不重建,减少性能开销
AnimationController Object Pool
- 新增对象池机制:
lib/src/utils/animation_controller_pool.dart - 复用 AnimationController:减少 60-80% 的 AnimationController 分配
- 降低 GC 压力:频繁显示 toast/loading 时性能更佳
RenderBox Caching
- 缓存 RenderBox 引用:避免重复调用
findRenderObject() - 减少 50-70% 布局计算开销:锚定菜单位置计算更高效
Screen Size Caching
- 懒加载屏幕尺寸:避免重复查询 MediaQuery
- 缓存失效机制:在依赖变化时自动更新缓存
Internal Changes #
- 优化
_PopupLayout的状态管理和缓存策略 - 改进动画资源生命周期管理
1.2.1 #
Added #
Widget 自定义支持
- Pop.toast() 新增 messageWidget 参数,支持完全自定义消息内容 Widget
- Pop.confirm() 新增 titleWidget、contentWidget、confirmButtonWidget、cancelButtonWidget 参数,支持完全自定义标题、内容和按钮 Widget
- Pop.sheet() 新增 titleWidget 参数,支持完全自定义标题 Widget
- 所有 Widget 参数优先于对应的 String 参数,提供更灵活的定制能力
Confirm 回调增强
- Pop.confirm() 新增 onConfirm 和 onCancel 回调参数
- 回调在内部关闭逻辑之前执行,允许外部完全接管按钮点击事件
- 保留原有的 Future<bool?> 返回值机制,向后兼容
示例页面 新增 PopupManagerPage 示例页面,展示 PopScopeWidget 和 PopupManager.show 的搭配使用
1.2.0 #
✨ New Features #
Animation Curve Support
- 新增
animationCurve参数:所有弹窗 API 都支持自定义动画曲线 - 默认曲线优化:所有 API 默认使用
Curves.easeInOut - 灵活的动画配置:每个弹窗可独立配置动画时长和曲线
使用示例:
Pop.toast(
'消息',
animationDuration: Duration(milliseconds: 200),
animationCurve: Curves.easeOutBack, // 自定义曲线
);
Pop.sheet(
title: '面板',
animationDuration: Duration(milliseconds: 500),
animationCurve: Curves.easeOutCubic,
childBuilder: (dismiss) => Content(),
);
PopupRouteObserver - Route Change Management
- 新增路由观察者:
PopupRouteObserver自动监听路由变化 - 智能弹窗清理:confirm、sheet 默认在路由切换时关闭
- 可配置行为:通过
dismissOnRouteChange控制是否自动关闭
使用方式:
MaterialApp(
navigatorObservers: const [PopupRouteObserver()],
home: PopScopeWidget(child: HomePage()),
);
PopScopeWidget Enhancement
- 返回键拦截优化:优先关闭弹窗而非页面路由
- 状态监听改进:使用
ValueNotifier高效监听弹窗状态
🐛 Bug Fixes #
Sheet Animation
- 裁剪多余动画:修复 sheet 动画超出区域的裁剪问题
- 动画边界优化:
clipDuringAnimation正确应用于锚定模式
Layout and Positioning
- edgeGap 正确传递:修复
dockToEdge模式下的边缘间隙传递 - 动态动画偏移:锚定模式下支持智能位置调整的动画偏移
Loading Management
- 单例模式强化:loading 自动关闭旧的实例,避免多个同时显示
- 键盘抖动修复:解决 loading 在键盘弹出时的位置抖动问题
Async Support
- 构建阶段检测:支持在
build()方法中调用所有弹窗类型 - SafeOverlayEntry 优化:延迟执行构建阶段的弹窗插入操作
Toast Interaction
- 点击切换功能:新增
toggleable参数,支持 toast 状态切换 - 点击回调:新增
onTap参数,支持点击事件处理
Menu Enhancements
- 样式自定义:新增
padding、decoration、constraints参数 - 更灵活的布局:支持完整的样式定制
Sheet Enhancements
- TabBar 适配:新增
dockToEdge和edgeGap参数 - 边缘保留区域:支持保留底部/侧边导航栏的交互区域
🏗️ Architecture Improvements #
- 弹窗生命周期管理:改进弹窗的创建、显示、隐藏流程
- 资源管理优化:优化 AnimationController 和 OverlayEntry 的释放逻辑
- 状态同步改进:优化
hasNonToastPopup的更新机制
📝 Documentation #
- 更新 API 参考文档
- 新增最佳实践指南
- 完善使用示例
1.1.17 #
Added #
- Add
PopupRouteObserver.- Popups such as sheet and confirm will automatically close when the route changes.
1.1.14 #
Fixed #
- Fix the bug where the area that disappears when multiple Loading triggers occur remains and causes unclickability due to OverLary's effect.
- Following the singleton pattern, the loading process cannot be triggered many times. The displayed OverLary will always have only one.
1.1.13 #
Added #
- Toast Toggle Feature
- Added toggle functionality for Toast, allowing users to switch between two states by tapping
- Added
tMessageparameter: alternate message text for toggle mode - Added
tImagePathparameter: alternate image path for toggle mode - Added
tToastTypeparameter: alternate toast type for toggle mode - Added
tImgColorparameter: alternate image color for toggle mode - Added
onTapparameter: callback function when toast is tapped - Added
toggleableparameter: enable/disable toggle mode (default: false) - ToastWidget changed from StatelessWidget to StatefulWidget to support state management
- When
toggleableistrueandtMessageortImagePathis provided, tapping the toast will switch between two states
1.1.12 #
Feat #
clipDuringAnimationfor PopupConfig: Whether to crop the animation that exceeds the area in anchor point mode, default false.
1.1.11 #
Fixed #
- Enhanced Build Phase Error Handling
- Fixed
overlay.insert()setState error when called during build phase - Extracted
_insertPopupprivate method to handle overlay insertion logic - Added build phase detection in
PopupManager.show()method - If called during build phase (
SchedulerPhase.persistentCallbacks), automatically defers topostFrameCallbackexecution - Now fully supports calling popups in async operations and during build phase without errors
- Perfect support for scenarios like
Get.put()immediate initialization in route building process
- Fixed
1.1.10 #
Changed #
- Loading API Simplification
Pop.loading()now returnsvoidinstead ofString(loading ID)Pop.hideLoading()no longer requires a parameter- The entire application can only have one loading instance at a time, managed internally
- When showing a new loading, any existing loading is automatically closed
Added #
- PopupManager Enhancement
- Added
PopupManager.hideByType(PopupType type)method to hide popups by type - Useful for managing single-instance popup types like loading
- Added
Fixed #
- Fixed "setState() called during build" error when calling
Pop.loading()during build phase - Implemented
SafeOverlayEntrythat delays overlay insertion if called during build phase - Uses
SchedulerBindingto check build phase and defer overlay operations
1.1.8 #
Added #
- Introduced sheet barrier options (
showBarrier,barrierDismissible,barrierColor) for finer control. - Added
dockToEdgeto reserve space for system/tab/navigation bars when sliding from the bottom/left/right edges. - Added
edgeGapwith a default ofkBottomNavigationBarHeight + 4, allowing custom edge spacing.
Changed #
- When
dockToEdgeis enabled, the barrier now uses clipping instead of margin so the reserved edge remains interactive.
Fixed #
- Improved sheet keyboard handling so bottom sheets lift with the keyboard without compressing content.
1.1.7 #
1.1.6 #
Changed #
- Toast API Enhancement
- Added
imgColorparameter so custom images can be tinted directly fromPop.toast
- Added
1.1.5 #
Added #
- Confirm API Enhancement
- Added
confirmBorderandcancelBorderparameters to allow customBoxBorderfor confirm/cancel buttons - Preserves the original borderless style when a border is not provided
- Added
Changed #
ConfirmWidgetbuttons now useGestureDetector + Container, maintaining border radius, custom borders, and background colors consistently
1.1.4 #
Added #
-
Toast API Enhancement
- Added
customImagePathparameter to support custom local images - Added
imageSizeparameter to customize image size (default: 24.0) - Added
layoutDirectionparameter to support Row/Column layout switching (default: Row) - Custom images will override toastType icons when provided
- Added
-
Loading API Enhancement
- Added
customIndicatorparameter to support custom Widget (typically images) as loading indicator - Added
rotationDurationparameter to configure rotation animation speed (default: 1 second) - Custom indicator automatically includes rotation animation
- When both message and customIndicator are present, Container maintains square aspect ratio with adaptive sizing (max 25% screen width, 100px)
- Added
Changed #
- LoadingWidget changed from StatelessWidget to StatefulWidget to support rotation animation
- Loading container with message now maintains square aspect ratio for better visual consistency
1.1.1 #
Fixed #
- 修复了所有widget组件中的文本溢出问题
- ToastWidget: 使用Flexible包裹文本,支持多行显示
- ConfirmWidget: 为标题和内容文本添加maxLines和overflow处理
- LoadingWidget: 为消息文本添加溢出处理
- SheetWidget: 为标题文本添加溢出处理
- 所有文本组件现在都支持长文本的多行显示,避免溢出错误
1.1.0 #
Added #
- 为所有API入口添加了
animationDuration参数,支持外部传入不同的动画时长 - 每个API都有合理的默认动画时长:
Pop.toast(): 200ms (快速显示)Pop.loading(): 150ms (快速显示)Pop.confirm(): 250ms (适中时长)Pop.date(): 250ms (适中时长)Pop.menu(): 200ms (快速响应)Pop.sheet(): 400ms (较长动画,适合抽屉效果)PopupConfig.animationDuration默认值从400ms调整为300ms,作为最终兜底值
Changed #
- 优化了动画时长的默认配置,不同场景使用不同的动画时长,提升用户体验
- 所有API方法现在都支持
animationDuration参数,保持向后兼容性
Technical Details #
- 参数传递链路:API方法 → 实现方法 → PopupConfig → PopupManager
- 不传参数时使用合理的默认值,传入自定义值时覆盖默认值
1.0.3 #
Added #
- Submit Code, A unified popups SDK for Flutter, providing a flexible way to show toasts, dialogs, and other custom popups.
- 统一弹窗库的基础功能实现
- 支持Toast、Loading、Confirm、Sheet、Date、Menu等弹窗类型
- 基于Overlay的多实例弹窗管理系统
- 完整的API文档和最佳实践指南
版本说明 #
- [1.2.1]: 性能优化版本 - 重点优化重建和资源管理
- [1.2.0]: 功能增强版本 - 新增动画曲线和路由观察者
- [1.1.17]: 路由观察者版本
- [1.1.14]: Bug 修复版本
升级指南 #
从 1.1.x 升级到 1.2.1
- 更新
pubspec.yaml中的版本号到^1.2.1 - 如果使用了路由观察者,确保已添加
PopupRouteObserver - 享受性能提升!无需修改现有代码
API 兼容性
- ✅ 完全向后兼容
- ✅ 所有新参数都是可选的
- ✅ 默认行为保持一致
性能对比 #
| 指标 | 1.1.x | 1.2.1 | 提升 |
|---|---|---|---|
| PopScopeWidget 重建次数 | 100+ | <10 | 90%+ ↓ |
| AnimationController 分配 | 每次新建 | 对象池复用 | 60-80% ↓ |
| 布局计算开销 | 重复计算 | 缓存优化 | 50-70% ↓ |
| 内存占用 | ~50KB/弹窗 | ~30KB/弹窗 | 40% ↓ |
贡献者 #
感谢所有贡献者的支持!
许可证 #
MIT License - 详见 LICENSE 文件