feat:配件商城webview新增路由回退机制

This commit is contained in:
anfe 2024-04-08 14:48:16 +08:00
parent 8494144e0e
commit 784dcbdb60
3 changed files with 40 additions and 26 deletions

View File

@ -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();
} }

View File

@ -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() {

View File

@ -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);