Commit 4180acb3 by tanghuan

测试iso返回手势

1 parent 6b074f28
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';
......@@ -9,76 +11,127 @@ 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',
builder: (BuildContext context, GoRouterState state) {
return const WebPage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const WebPage(),
state: state,
);
},
),
GoRoute(
path: '/scanCode',
builder: (BuildContext context, GoRouterState state) {
return const ScanCodePage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const ScanCodePage(),
state: state,
);
},
),
GoRoute(
path: '/link',
builder: (BuildContext context, GoRouterState state) {
return const LinkPage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const LinkPage(),
state: state,
);
},
),
GoRoute(
path: '/loginMain',
builder: (BuildContext context, GoRouterState state) {
return const LoginMainPage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const LoginMainPage(),
state: state,
);
},
),
GoRoute(
path: '/loginPhone',
builder: (BuildContext context, GoRouterState state) {
return const LoginPhonePage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const LoginPhonePage(),
state: state,
);
},
),
GoRoute(
path: '/loginQr',
builder: (BuildContext context, GoRouterState state) {
return const LoginQrPage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const LoginQrPage(),
state: state,
);
},
),
GoRoute(
path: '/account',
builder: (BuildContext context, GoRouterState state) {
return const AccountPage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const AccountPage(),
state: state,
);
},
),
GoRoute(
path: '/account/phone',
builder: (BuildContext context, GoRouterState state) {
return const AccountPhonePage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const AccountPhonePage(),
state: state,
);
},
),
GoRoute(
path: '/adv',
builder: (BuildContext context, GoRouterState state) {
return const AdvPage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const AdvPage(),
state: state,
);
},
),
GoRoute(
path: '/im',
builder: (BuildContext context, GoRouterState state) {
return const ImPage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const ImPage(),
state: state,
);
},
),
GoRoute(
path: '/reload',
builder: (BuildContext context, GoRouterState state) {
return const ReloadPage();
pageBuilder: (BuildContext context, GoRouterState state) {
return _buildPageWithTransition(
child: const ReloadPage(),
state: state,
);
},
),
],
......
import 'package:appframe/bloc/link_cubit.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
......@@ -19,12 +17,7 @@ class LinkPage extends StatelessWidget {
create: (context) => LinkCubit(LinkState(loaded: false, url: url!)),
child: BlocConsumer<LinkCubit, LinkState>(
builder: (ctx, state) {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
ctx.read<LinkCubit>().handleBack(ctx);
},
child: Scaffold(
final scaffold = Scaffold(
appBar: AppBar(
title: Text(title ?? '', style: TextStyle(color: Colors.white, fontSize: 18)),
centerTitle: true,
......@@ -36,19 +29,19 @@ class LinkPage extends StatelessWidget {
height: MediaQuery.of(ctx).size.height - 120, // 减去100像素留空
child: WebViewWidget(
controller: ctx.read<LinkCubit>().controller,
gestureRecognizers: {
// 允许所有手势
Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer(),
),
Factory<HorizontalDragGestureRecognizer>(
() => HorizontalDragGestureRecognizer(),
),
},
),
)
: const Center(child: CircularProgressIndicator()),
),
: const Center(child: CircularProgressIndicator(color: Color(0xFF7691fa))),
);
// 为所有平台添加PopScope支持
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) async {
// if (didPop) return;
await ctx.read<LinkCubit>().handleBack(ctx);
},
child: scaffold,
);
},
listener: (context, state) {},
......
......@@ -4,8 +4,6 @@ import 'package:appframe/config/env_config.dart';
import 'package:appframe/config/locator.dart';
import 'package:appframe/config/routes.dart';
import 'package:appframe/ui/widgets/tip_overlay_widget.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
......@@ -51,17 +49,10 @@ class WebPage extends StatelessWidget {
),
child: BlocConsumer<WebCubit, WebState>(
builder: (ctx, state) {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
ctx.read<WebCubit>().handleBack();
},
child: Scaffold(
final scaffold = Scaffold(
appBar: _buildAppBar(ctx, state),
endDrawer: _buildDrawer(ctx, state),
body: Stack(
children: [
state.loaded
body: state.loaded
? SizedBox(
height: MediaQuery.of(ctx).size.height - 60, // 减去100像素留空
child: WebViewWidget(controller: ctx.read<WebCubit>().controller),
......@@ -76,23 +67,6 @@ class WebPage extends StatelessWidget {
],
),
),
// 添加升级遮罩层
if (state.isUpgrading)
Container(
color: Colors.black54,
child: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(color: Color(0xFF7691fa)),
SizedBox(height: 16),
Text('资源更新中...', style: TextStyle(color: Colors.white)),
],
),
),
),
],
),
bottomNavigationBar: state.showBottomNavBar
? BottomNavigationBar(
type: BottomNavigationBarType.fixed,
......@@ -123,8 +97,16 @@ class WebPage extends StatelessWidget {
),
],
)
: null,
),
: const SizedBox.shrink(),
);
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) async {
//if (didPop) return;
await ctx.read<WebCubit>().handleBack();
},
child: scaffold,
);
},
listener: (context, state) {
......@@ -169,7 +151,7 @@ class WebPage extends StatelessWidget {
ctx.read<WebCubit>().handleHome();
},
)
: null),
: const SizedBox.shrink()),
);
}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!