Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 5c38bf5a
authored
2025-12-25 09:45:33 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
ios手势测试
1 parent
7374fbfe
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
36 deletions
lib/bloc/link_cubit.dart
lib/bloc/web_cubit.dart
lib/ui/pages/link_page.dart
lib/ui/pages/web_page.dart
lib/ui/widgets/ios_edge_swipe_detector.dart
lib/bloc/link_cubit.dart
View file @
5c38bf5
import
'dart:io'
;
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/ui/widgets/ios_edge_swipe_detector.dart'
;
import
'package:equatable/equatable.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
...
...
@@ -16,7 +19,6 @@ class LinkState extends Equatable {
}
@override
// TODO: implement props
List
<
Object
?>
get
props
=>
[
loaded
,
url
];
}
...
...
@@ -26,6 +28,17 @@ class LinkCubit extends Cubit<LinkState> {
WebViewController
get
controller
=>
_controller
;
LinkCubit
(
super
.
initialState
)
{
// 初始化 iOS 边缘滑动监听
if
(
Platform
.
isIOS
)
{
IosEdgeSwipeDetector
.
init
();
IosEdgeSwipeDetector
.
onEdgeSwipe
(()
{
debugPrint
(
""
);
debugPrint
(
"link page 检测到左边缘滑动,Flutter 收到通知"
);
debugPrint
(
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
""
);
});
}
_controller
=
WebViewController
()
..
setJavaScriptMode
(
JavaScriptMode
.
unrestricted
)
..
setNavigationDelegate
(
...
...
@@ -41,7 +54,6 @@ class LinkCubit extends Cubit<LinkState> {
),
)
..
loadRequest
(
Uri
.
parse
(
state
.
url
));
}
void
_finishLoading
()
{
...
...
lib/bloc/web_cubit.dart
View file @
5c38bf5
...
...
@@ -12,6 +12,7 @@ import 'package:appframe/services/im_service.dart';
import
'package:appframe/services/local_server_service.dart'
;
import
'package:appframe/services/player_service.dart'
;
import
'package:appframe/services/recorder_service.dart'
;
import
'package:appframe/ui/widgets/ios_edge_swipe_detector.dart'
;
import
'package:device_info_plus/device_info_plus.dart'
;
import
'package:dio/dio.dart'
;
import
'package:equatable/equatable.dart'
;
...
...
@@ -211,6 +212,17 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
// 添加生命周期观察者
WidgetsBinding
.
instance
.
addObserver
(
this
);
// 初始化 iOS 边缘滑动监听
if
(
Platform
.
isIOS
)
{
IosEdgeSwipeDetector
.
init
();
IosEdgeSwipeDetector
.
onEdgeSwipe
(()
{
debugPrint
(
""
);
debugPrint
(
"web page 检测到左边缘滑动,Flutter 收到通知"
);
debugPrint
(
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
""
);
});
}
// 没有登录数据,跳转到登录页面
if
(
state
.
sessionCode
==
null
||
state
.
sessionCode
==
''
)
{
WidgetsBinding
.
instance
.
addPostFrameCallback
((
_
)
{
...
...
lib/ui/pages/link_page.dart
View file @
5c38bf5
import
'dart:io'
;
import
'package:appframe/bloc/link_cubit.dart'
;
import
'package:appframe/ui/widgets/ios_edge_swipe_detector.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:go_router/go_router.dart'
;
...
...
@@ -16,20 +15,6 @@ class LinkPage extends StatelessWidget {
final
String
?
url
=
extraData
?[
'url'
];
final
String
?
title
=
extraData
?[
'title'
];
if
(
Platform
.
isIOS
)
{
// 初始化 iOS 边缘滑动监听
IosEdgeSwipeDetector
.
init
();
// 设置滑动回调
IosEdgeSwipeDetector
.
onEdgeSwipe
(()
{
debugPrint
(
""
);
debugPrint
(
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
"检测到左边缘滑动,Flutter 收到通知"
);
debugPrint
(
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
""
);
});
}
return
BlocProvider
(
create:
(
context
)
=>
LinkCubit
(
LinkState
(
loaded:
false
,
url:
url
!)),
child:
BlocConsumer
<
LinkCubit
,
LinkState
>(
...
...
@@ -59,6 +44,9 @@ class LinkPage extends StatelessWidget {
canPop:
false
,
onPopInvokedWithResult:
(
didPop
,
result
)
async
{
// if (didPop) return;
debugPrint
(
""
);
debugPrint
(
"^^^^^^^^^^^^^^ Link page PopScope ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
""
);
await
ctx
.
read
<
LinkCubit
>().
handleBack
(
ctx
);
},
child:
scaffold
,
...
...
lib/ui/pages/web_page.dart
View file @
5c38bf5
...
...
@@ -5,7 +5,6 @@ import 'package:appframe/config/constant.dart';
import
'package:appframe/config/env_config.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/ui/widgets/ios_edge_swipe_detector.dart'
;
import
'package:appframe/ui/widgets/tip_overlay_widget.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
...
...
@@ -39,20 +38,6 @@ class WebPage extends StatelessWidget {
stuId
=
sharedPreferences
.
getString
(
'auth_stuId'
);
}
if
(
Platform
.
isIOS
)
{
// 初始化 iOS 边缘滑动监听
IosEdgeSwipeDetector
.
init
();
// 设置滑动回调
IosEdgeSwipeDetector
.
onEdgeSwipe
(()
{
debugPrint
(
""
);
debugPrint
(
"^^^^^^^^^^^^^^web_page^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
"web_page 检测到左边缘滑动,Flutter 收到通知"
);
debugPrint
(
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
""
);
});
}
return
BlocProvider
(
create:
(
context
)
=>
WebCubit
(
WebState
(
...
...
@@ -125,7 +110,9 @@ class WebPage extends StatelessWidget {
canPop:
false
,
onPopInvokedWithResult:
(
didPop
,
result
)
async
{
//if (didPop) return;
debugPrint
(
"^^^^^^^^^^^^^^PopScope^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
""
);
debugPrint
(
"^^^^^^^^^^^^^^ Web page PopScope ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
);
debugPrint
(
""
);
await
ctx
.
read
<
WebCubit
>().
handleBack
();
},
child:
scaffold
,
...
...
lib/ui/widgets/ios_edge_swipe_detector.dart
View file @
5c38bf5
import
'package:flutter/foundation.dart'
;
import
'package:flutter/services.dart'
;
class
IosEdgeSwipeDetector
{
static
const
MethodChannel
_channel
=
MethodChannel
(
'ios_edge_swipe'
);
/// 初始化监听器(调用 iOS 注册边缘滑动监听)
/// 初始化边缘滑动检测器
/// 调用原生iOS代码注册边缘滑动监听
static
Future
<
void
>
init
()
async
{
try
{
await
_channel
.
invokeMethod
(
'initSwipeListener'
);
}
catch
(
_
)
{}
}
catch
(
e
)
{
// 记录错误信息以便调试
debugPrint
(
'初始化边缘滑动监听失败:
$e
'
);
}
}
/// 注册 Flutter 层监听器
/// 注册边缘滑动事件回调
/// [onSwipeDetected] 当检测到边缘滑动时的回调函数
static
void
onEdgeSwipe
(
VoidCallback
onSwipeDetected
)
{
_channel
.
setMethodCallHandler
((
call
)
async
{
if
(
call
.
method
==
'onEdgeSwipe'
)
{
onSwipeDetected
();
}
else
{
debugPrint
(
'方法
${call.method}
未实现'
);
}
});
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment