show static method
void
show(
- BuildContext context, {
- required List<
VGuideTarget> targets, - required Widget contentBuilder(),
- List<
int> ? initialHighlights, - Offset? offsetLT,
- Offset? offsetRB,
- bool cancelable = true,
- bool outsideTouchCancelable = true,
- double? opacity,
- Duration duration = const Duration(milliseconds: 30),
- VoidCallback? onPopupShow,
- VoidCallback? onPopupDismiss,
- Color? holeBorderColor = Colors.white,
- double holeBorderWidth = 2,
展示引导蒙层
targets 需要挖洞高亮的 widget(用 GlobalKey 描述),组件内部自动换算屏幕坐标
contentBuilder 浮层内容构造器,入参 rects 是组件算好的各 target 屏幕坐标,
顺序与 targets 一一对应;浮层据此定位文案(如放在某个洞下方)。不需要坐标时忽略入参即可。
initialHighlights 初始挖洞的 target 索引列表,null 表示全部高亮;
步步引导通常传 0(先只高亮第一步),后续用 setHighlights 切换。
offsetLT / offsetRB 遮罩区域的左上 / 右下偏移
cancelable 是否响应系统返回键关闭
outsideTouchCancelable 点击蒙层空白区域是否关闭
opacity 遮罩透明度 0.0, 1.0,默认 0.6
duration 淡入淡出动画时长
holeBorderColor 挖洞高亮描边颜色,默认白色,传 null 不描边
holeBorderWidth 挖洞高亮描边宽度,默认 2
Implementation
static void show(
BuildContext context, {
required List<VGuideTarget> targets,
required Widget Function(List<RRect> rects) contentBuilder,
List<int>? initialHighlights,
Offset? offsetLT,
Offset? offsetRB,
bool cancelable = true,
bool outsideTouchCancelable = true,
double? opacity,
Duration duration = const Duration(milliseconds: 30),
VoidCallback? onPopupShow,
VoidCallback? onPopupDismiss,
Color? holeBorderColor = Colors.white,
double holeBorderWidth = 2,
}) {
// 把 targets 换算成屏幕坐标(目标 widget 此时已完成布局)
final rects = targets
.map((t) => _rectFromKey(t.key, padding: t.padding, radius: t.radius))
.toList();
// 初始挖洞区域:未指定则全部高亮,否则按索引挑选
final initial = initialHighlights == null
? rects
: initialHighlights.map((i) => rects[i]).toList();
Navigator.of(context).push(
VGuideRoute(
// 把算好的坐标回传给浮层,浮层据此定位文案
child: contentBuilder(rects),
offsetLT: offsetLT,
offsetRB: offsetRB,
cancelable: cancelable,
outsideTouchCancelable: outsideTouchCancelable,
duration: duration,
highlights: initial,
opacity: opacity ?? 0.6,
onPopupShow: onPopupShow,
onPopupDismiss: onPopupDismiss,
holeBorderColor: holeBorderColor,
holeBorderWidth: holeBorderWidth),
);
}