import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class PopRoute extends PopupRoute {
  final Duration _duration = const Duration(milliseconds: 350);
  final Widget child;

  PopRoute({required this.child});

  @override
  Color? get barrierColor => null;

  @override
  bool get barrierDismissible => false; // 改为 false

  @override
  String? get barrierLabel => null;

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation) {
    return child;
  }

  // 关键：添加这个方法来支持 iOS 手势
  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation, Widget child) {
    // 在 iOS 上使用 Cupertino 页面过渡
    if (Platform.isIOS) {
      return CupertinoPageTransition(
        primaryRouteAnimation: animation,
        secondaryRouteAnimation: secondaryAnimation,
        child: child,
        linearTransition: false,
      );
    }
    // 保持原有过渡（没有过渡）
    return child;
  }

  @override
  Duration get transitionDuration => _duration;
}