feat:配件商城webview新增路由回退机制
This commit is contained in:
parent
8494144e0e
commit
784dcbdb60
@ -1,3 +1,5 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
import 'package:star_lock/mine/mall/lockMall_entity.dart';
|
import 'package:star_lock/mine/mall/lockMall_entity.dart';
|
||||||
import 'package:star_lock/mine/mall/lockMall_state.dart';
|
import 'package:star_lock/mine/mall/lockMall_state.dart';
|
||||||
import 'package:star_lock/network/api_repository.dart';
|
import 'package:star_lock/network/api_repository.dart';
|
||||||
@ -41,6 +43,17 @@ class LockMallLogic extends BaseGetXController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//判断webview 是否可以有路由可以回退,无则退出当前页面
|
||||||
|
Future<bool> canGoBack(bool didPop) async {
|
||||||
|
bool canGoBack = await state.mallWebView.canGoBack();
|
||||||
|
if (canGoBack) {
|
||||||
|
await state.mallWebView.goBack();
|
||||||
|
} else {
|
||||||
|
Get.back();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onReady() async {
|
Future<void> onReady() async {
|
||||||
print("ready home");
|
print("ready home");
|
||||||
@ -51,7 +64,6 @@ class LockMallLogic extends BaseGetXController {
|
|||||||
void onInit() {
|
void onInit() {
|
||||||
print("init home");
|
print("init home");
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
|
||||||
getMallURLRequest();
|
getMallURLRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import 'package:star_lock/mine/mall/lockMall_logic.dart';
|
|||||||
import 'package:star_lock/tools/titleAppBar.dart';
|
import 'package:star_lock/tools/titleAppBar.dart';
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
import 'package:webview_flutter/webview_flutter.dart';
|
||||||
|
|
||||||
|
|
||||||
class LockMallPage extends StatefulWidget {
|
class LockMallPage extends StatefulWidget {
|
||||||
const LockMallPage({Key? key}) : super(key: key);
|
const LockMallPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@ -28,30 +27,33 @@ class _LockMallPageState extends State<LockMallPage> {
|
|||||||
// FIXME 如果未登录状态,应先跳转登录页
|
// FIXME 如果未登录状态,应先跳转登录页
|
||||||
// FIXME url应该使用接口获取,接口名称 “获取商城跳转地址:/mall/getUrl“ POST请求,无参数,需要登录
|
// FIXME url应该使用接口获取,接口名称 “获取商城跳转地址:/mall/getUrl“ POST请求,无参数,需要登录
|
||||||
// String url = 'https://ge.mall.star-lock.cn/quick_login?id=4&key=1ffb9d37109b8351ebb04ccfcca02c8e';
|
// String url = 'https://ge.mall.star-lock.cn/quick_login?id=4&key=1ffb9d37109b8351ebb04ccfcca02c8e';
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
resizeToAvoidBottomInset: false,
|
onPopInvoked: logic.canGoBack,
|
||||||
backgroundColor: const Color(0xFFFFFFFF),
|
canPop: false,
|
||||||
appBar: TitleAppBar(
|
child: Scaffold(
|
||||||
barTitle: getWebTitle(),
|
resizeToAvoidBottomInset: false,
|
||||||
haveBack: true,
|
backgroundColor: const Color(0xFFFFFFFF),
|
||||||
backgroundColor: AppColors.mainColor,
|
appBar: TitleAppBar(
|
||||||
),
|
barTitle: getWebTitle(),
|
||||||
body: Obx(() => Column(
|
haveBack: true,
|
||||||
children: <Widget>[
|
backgroundColor: AppColors.mainColor,
|
||||||
Container(
|
),
|
||||||
padding: EdgeInsets.only(bottom: 10.w),
|
body: Obx(() => Column(
|
||||||
child: LinearProgressIndicator(
|
children: <Widget>[
|
||||||
value: state.webProgress.value,
|
Container(
|
||||||
backgroundColor: Colors.grey,
|
padding: EdgeInsets.only(bottom: 10.w),
|
||||||
valueColor:
|
child: LinearProgressIndicator(
|
||||||
AlwaysStoppedAnimation<Color>(AppColors.mainColor),
|
value: state.webProgress.value,
|
||||||
|
backgroundColor: Colors.grey,
|
||||||
|
valueColor: AlwaysStoppedAnimation<Color>(AppColors.mainColor),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
Expanded(
|
||||||
Expanded(
|
child: WebViewWidget(controller: state.mallWebView),
|
||||||
child: WebViewWidget(controller: state.mallWebView),
|
),
|
||||||
),
|
],
|
||||||
],
|
))),
|
||||||
)));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getWebTitle() {
|
String getWebTitle() {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ class LockMallState {
|
|||||||
var webProgress = 0.0.obs;
|
var webProgress = 0.0.obs;
|
||||||
late WebViewController mallWebView = initWebViewController();
|
late WebViewController mallWebView = initWebViewController();
|
||||||
|
|
||||||
//初始化webview控制器
|
//初始化webView控制器
|
||||||
WebViewController initWebViewController() {
|
WebViewController initWebViewController() {
|
||||||
WebViewController allWebView = WebViewController();
|
WebViewController allWebView = WebViewController();
|
||||||
allWebView.setJavaScriptMode(JavaScriptMode.unrestricted);
|
allWebView.setJavaScriptMode(JavaScriptMode.unrestricted);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user