routes.dart 3.65 KB
import 'dart:io';

import 'package:appframe/ui/pages/adv_page.dart';
import 'package:appframe/ui/pages/im_page.dart';
import 'package:appframe/ui/pages/link_page.dart';
import 'package:appframe/ui/pages/login_main_page.dart';
import 'package:appframe/ui/pages/login_phone_page.dart';
import 'package:appframe/ui/pages/login_qr_page.dart';
import 'package:appframe/ui/pages/reload_page.dart';
import 'package:appframe/ui/pages/scan_code_page.dart';
import 'package:appframe/ui/pages/setting/account_page.dart';
import 'package:appframe/ui/pages/setting/account_phone_page.dart';
import 'package:appframe/ui/pages/web_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

// iOS平台使用Cupertino转场动画以支持侧滑返回手势
Page<dynamic> _buildPageWithTransition({
  required Widget child,
  required GoRouterState state,
}) {
  if (Platform.isIOS) {
    return CupertinoPage(
      key: state.pageKey,
      child: child,
    );
  }
  return MaterialPage(
    key: state.pageKey,
    child: child,
  );
}

final GoRouter router = GoRouter(
  initialLocation: '/web',
  routes: <RouteBase>[
    GoRoute(
      path: '/web',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const WebPage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/scanCode',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const ScanCodePage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/link',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const LinkPage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/loginMain',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const LoginMainPage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/loginPhone',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const LoginPhonePage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/loginQr',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const LoginQrPage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/account',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const AccountPage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/account/phone',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const AccountPhonePage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/adv',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const AdvPage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/im',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const ImPage(),
          state: state,
        );
      },
    ),
    GoRoute(
      path: '/reload',
      pageBuilder: (BuildContext context, GoRouterState state) {
        return _buildPageWithTransition(
          child: const ReloadPage(),
          state: state,
        );
      },
    ),
  ],
);