76 lines
2.2 KiB
Dart
76 lines
2.2 KiB
Dart
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_state.dart';
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
import 'package:star_lock/webview/webview_logic.dart';
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
import '../../tools/baseGetXController.dart';
|
|
|
|
class LockMallLogic extends BaseGetXController {
|
|
final LockMallState state = LockMallState();
|
|
|
|
//获取商城跳转地址
|
|
Future<void> getMallURLRequest() async {
|
|
LockMallDataEntity entity = await ApiRepository.to.getMallURLData();
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
state.lockMallUrl.value = entity.data!.url!;
|
|
state.mallWebView.setNavigationDelegate(
|
|
NavigationDelegate(
|
|
onProgress: (int progress) {
|
|
// Update loading bar.
|
|
state.webProgress.value = progress / 100;
|
|
},
|
|
onPageStarted: (String url) {
|
|
state.webProgress.value = 0.0;
|
|
},
|
|
onPageFinished: (String url) {
|
|
state.webProgress.value = 1.0;
|
|
},
|
|
onWebResourceError: (WebResourceError error) {},
|
|
onNavigationRequest: (NavigationRequest request) async {
|
|
//路由跳转逻辑
|
|
if (WebViewLogic.judgePaySchemes(request.url)) {
|
|
await WebViewLogic.runScheme(request.url);
|
|
return NavigationDecision.prevent;
|
|
}
|
|
return NavigationDecision.navigate;
|
|
},
|
|
),
|
|
);
|
|
state.mallWebView.loadRequest(Uri.parse(state.lockMallUrl.value));
|
|
}
|
|
}
|
|
|
|
//判断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
|
|
Future<void> onReady() async {
|
|
print("ready home");
|
|
super.onReady();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
print("init home");
|
|
super.onInit();
|
|
getMallURLRequest();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
print("close home");
|
|
super.onClose();
|
|
}
|
|
}
|