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,36 +17,31 @@ class LinkPage extends StatelessWidget {
create: (context) => LinkCubit(LinkState(loaded: false, url: url!)),
child: BlocConsumer<LinkCubit, LinkState>(
builder: (ctx, state) {
final scaffold = Scaffold(
appBar: AppBar(
title: Text(title ?? '', style: TextStyle(color: Colors.white, fontSize: 18)),
centerTitle: true,
backgroundColor: Color(0xFF7691FA),
iconTheme: IconThemeData(color: Colors.white),
),
body: state.loaded
? SizedBox(
height: MediaQuery.of(ctx).size.height - 120, // 减去100像素留空
child: WebViewWidget(
controller: ctx.read<LinkCubit>().controller,
),
)
: const Center(child: CircularProgressIndicator(color: Color(0xFF7691fa))),
);
// 为所有平台添加PopScope支持
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
ctx.read<LinkCubit>().handleBack(ctx);
onPopInvokedWithResult: (didPop, result) async {
// if (didPop) return;
await ctx.read<LinkCubit>().handleBack(ctx);
},
child: Scaffold(
appBar: AppBar(
title: Text(title ?? '', style: TextStyle(color: Colors.white, fontSize: 18)),
centerTitle: true,
backgroundColor: Color(0xFF7691FA),
iconTheme: IconThemeData(color: Colors.white),
),
body: state.loaded
? SizedBox(
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()),
),
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,80 +49,64 @@ class WebPage extends StatelessWidget {
),
child: BlocConsumer<WebCubit, WebState>(
builder: (ctx, state) {
final scaffold = Scaffold(
appBar: _buildAppBar(ctx, state),
endDrawer: _buildDrawer(ctx, state),
body: state.loaded
? SizedBox(
height: MediaQuery.of(ctx).size.height - 60, // 减去100像素留空
child: WebViewWidget(controller: ctx.read<WebCubit>().controller),
)
: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(color: Color(0xFF7691fa)),
SizedBox(height: 16),
Text('加载中...'),
],
),
),
bottomNavigationBar: state.showBottomNavBar
? BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: state.selectedIndex,
selectedItemColor: Color(0xFF7691fa),
unselectedItemColor: Color(0xFF969799),
onTap: (index) {
// 更新选中索引
ctx.read<WebCubit>().updateSelectedIndex(index);
// 根据 index 执行相应的操作
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home, size: 32),
label: '我的班级',
),
BottomNavigationBarItem(
icon: Icon(Icons.contact_page, size: 32),
label: '通讯录',
),
BottomNavigationBarItem(
icon: Icon(Icons.find_in_page, size: 32),
label: '发现',
),
BottomNavigationBarItem(
icon: Icon(Icons.person, size: 32),
label: '我的',
),
],
)
: const SizedBox.shrink(),
);
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
ctx.read<WebCubit>().handleBack();
onPopInvokedWithResult: (didPop, result) async {
//if (didPop) return;
await ctx.read<WebCubit>().handleBack();
},
child: Scaffold(
appBar: _buildAppBar(ctx, state),
endDrawer: _buildDrawer(ctx, state),
body: Stack(
children: [
state.loaded
? SizedBox(
height: MediaQuery.of(ctx).size.height - 60, // 减去100像素留空
child: WebViewWidget(controller: ctx.read<WebCubit>().controller),
)
: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(color: Color(0xFF7691fa)),
SizedBox(height: 16),
Text('加载中...'),
],
),
),
// 添加升级遮罩层
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,
currentIndex: state.selectedIndex,
selectedItemColor: Color(0xFF7691fa),
unselectedItemColor: Color(0xFF969799),
onTap: (index) {
// 更新选中索引
ctx.read<WebCubit>().updateSelectedIndex(index);
// 根据 index 执行相应的操作
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home, size: 32),
label: '我的班级',
),
BottomNavigationBarItem(
icon: Icon(Icons.contact_page, size: 32),
label: '通讯录',
),
BottomNavigationBarItem(
icon: Icon(Icons.find_in_page, size: 32),
label: '发现',
),
BottomNavigationBarItem(
icon: Icon(Icons.person, size: 32),
label: '我的',
),
],
)
: null,
),
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!