Flutter实现弹窗拦截器的示例代码

  class TipsIntercept extends InterceptChain {

  @override

  void intercept(DialogPass data) {

  SmartDialog.show(

  usePenetrate: false,

  builder: (context) =>

  AppDefaultDialog(

  "你确定要发送验证码吗?",

  confirmAction: () {

  super.intercept(data);

  },

  ),

  );

  }

  }

  class VerifyIntercept extends InterceptChain {

  @override

  void intercept(DialogPass data) {

  SmartDialog.show(

  usePenetrate: false,

  builder: (context) => VerifyCodeDialog(

  confirmAction: () {

  super.intercept(data);

  },

  ),

  );

  }

  }

  class OneIntercept extends InterceptChain {

  @override

  void intercept(DialogPass data) {

  if (data != null) {

  final interceptData = '当前的Data1:${data.msg}';

  print(interceptData);

  if (data.passType == 1) {

  // 弹窗1

  SmartDialog.show(

  usePenetrate: false,

  builder: (context) => AppDefaultDialog(

  data.msg ?? "",

  confirmAction: () {

  data.passType = 2;

  super.intercept(data);

  },

  ),

  );

  } else {

  super.intercept(data);

  }

  } else {

  super.intercept(data);

  }

  }

  }

  class TwoIntercept extends InterceptChain {

  @override

  void intercept(DialogPass data) {

  if (data != null) {

  final interceptData = '当前的Data2:${data.msg}';

  print(interceptData);

  if (data.passType == 2) {

  // 弹窗2

  SmartDialog.show(

  usePenetrate: false,

  clickMaskDismiss: false,

  builder: (context) => PrivacyPolicyDialog(

  confirmAction: () {

  data.passType = 3;

  super.intercept(data);

  },

  cancelAction: () {

  super.intercept(data);

  },

  ),

  );

  } else {

  super.intercept(data);

  }

  } else {

  super.intercept(data);

  }

  }

  }

  class ThreeIntercept extends InterceptChain {

  @override

  void intercept(DialogPass data) {

  if (data != null) {

  final interceptData = '当前的Data3:${data.msg}';

  print(interceptData);

  if (data.passType == 3) {

  // 弹窗2

  DataPickerUtil.showCupertinoDataPicker(

  items: ["全部","等待确认", "已完成"],

  onPickerChanged: (list, position) {

  super.intercept(data);

  },

  );

  } else {

  super.intercept(data);

  }

  } else {

  super.intercept(data);

  }

  }

  }