不少用 iOS 的小夥伴都用過該功能:git
微信聊天窗口,長按某一條消息,彈出彈框,選擇「複製、轉發...」等等。github
基於這個需求,我封裝了一個 「WPopupMenu」。微信
話很少說,先上圖:markdown
仍是老樣子,咱們先來看構造函數:函數
WPopupMenu({
@required this.onValueChanged,
@required this.actions,
@required this.child,
this.pressType = PressType.longPress,
this.pageMaxChildCount = 5,
}) : assert(onValueChanged != null),
assert(actions != null && actions.length > 0),
assert(child != null);
複製代碼
解釋一下參數:ui
直接在須要使用該控件的地方套上,就能使用了,簡單代碼以下:this
WPopupMenu(
onValueChanged: (int value) {
/// showSnackBar
},
actions: actions,
child: Container(
/// 省略...
),
),
複製代碼
代碼文件名叫:「widget_w_popup_menu.dart
」,spa
具體 Demo 在:「popup_route_page.dart
」。3d
後面我會出一篇關於該組件的封裝邏輯,敬請期待。code
關於該組件,還有幾處未完善:
完整代碼已經傳至GitHub:github.com/wanglu1209/…