fix:修复商场无法回退的问题

This commit is contained in:
anfe 2024-04-29 11:25:39 +08:00
parent 4a18988613
commit 9cefd84f50
4 changed files with 51 additions and 34 deletions

View File

@ -56,7 +56,7 @@ class _StarLockMainXHJPageState extends State<StarLockMainXHJPage>
widget: SafeArea( widget: SafeArea(
bottom: false, bottom: false,
child: LockMallPage( child: LockMallPage(
showAppBar: false, allowReturn: false,
), ),
), ),
logic: logic, logic: logic,

View File

@ -17,7 +17,7 @@ class LockMallLogic extends BaseGetXController {
late LockMallState state; late LockMallState state;
LockMallLogic({required bool allowReturn}) LockMallLogic({required bool allowReturn})
: state = LockMallState(allowReturn: allowReturn); : state = LockMallState(allowReturn: allowReturn );
// //
Future<void> getMallURLRequest() async { Future<void> getMallURLRequest() async {
@ -35,6 +35,7 @@ class LockMallLogic extends BaseGetXController {
}, },
onPageFinished: (String url) { onPageFinished: (String url) {
state.webProgress.value = 1.0; state.webProgress.value = 1.0;
refreshGoBack();
}, },
onWebResourceError: (WebResourceError error) {}, onWebResourceError: (WebResourceError error) {},
onNavigationRequest: (NavigationRequest request) async { onNavigationRequest: (NavigationRequest request) async {
@ -99,12 +100,25 @@ class LockMallLogic extends BaseGetXController {
bool canGoBack = await state.mallWebView.canGoBack(); bool canGoBack = await state.mallWebView.canGoBack();
if (canGoBack) { if (canGoBack) {
await state.mallWebView.goBack(); await state.mallWebView.goBack();
} else { } else if (state.allowReturn) {
if (state.allowReturn) Get.back(); Get.back();
} }
refreshGoBack();
return false; return false;
} }
//
void refreshGoBack(){
//退
if(state.allowReturn){
return;
}
state.mallWebView.canGoBack().then((value) {
state.canGoBack = value;
update();
});
}
@override @override
Future<void> onReady() async { Future<void> onReady() async {
super.onReady(); super.onReady();

View File

@ -30,36 +30,38 @@ class _LockMallPageState extends State<LockMallPage> {
return GetBuilder<LockMallLogic>( return GetBuilder<LockMallLogic>(
init: LockMallLogic(allowReturn: widget.allowReturn), init: LockMallLogic(allowReturn: widget.allowReturn),
builder: (LockMallLogic logic) { builder: (LockMallLogic logic) {
return PopScope( return Scaffold(
onPopInvoked: logic.canGoBack, resizeToAvoidBottomInset: false,
canPop: false, backgroundColor: const Color(0xFFFFFFFF),
child: Scaffold( appBar: widget.showAppBar
resizeToAvoidBottomInset: false, ? TitleAppBar(
backgroundColor: const Color(0xFFFFFFFF), barTitle: getWebTitle(logic),
appBar: widget.showAppBar haveBack: logic.state.canGoBack || logic.state.allowReturn,
? TitleAppBar( backgroundColor: AppColors.mainColor,
barTitle: getWebTitle(logic), backAction: () => logic.canGoBack(false),
haveBack: true, )
backgroundColor: AppColors.mainColor, : null,
) body: Obx(() => Column(
: null, children: <Widget>[
body: Obx(() => Column( PopScope(
children: <Widget>[ onPopInvoked: logic.canGoBack,
Container( canPop: false,
padding: EdgeInsets.only(bottom: 10.w), child: SizedBox(),
child: LinearProgressIndicator( ),
value: logic.state.webProgress.value, Container(
backgroundColor: Colors.grey, padding: EdgeInsets.only(bottom: 10.w),
valueColor: AlwaysStoppedAnimation<Color>( child: LinearProgressIndicator(
AppColors.mainColor), value: logic.state.webProgress.value,
), backgroundColor: Colors.grey,
), valueColor:
Expanded( AlwaysStoppedAnimation<Color>(AppColors.mainColor),
child: WebViewWidget( ),
controller: logic.state.mallWebView), ),
), Expanded(
], child: WebViewWidget(controller: logic.state.mallWebView),
))), ),
],
)),
); );
}); });
} }

View File

@ -9,6 +9,7 @@ class LockMallState {
var lockMallUrl = "".obs; var lockMallUrl = "".obs;
var webProgress = 0.0.obs; var webProgress = 0.0.obs;
bool allowReturn; bool allowReturn;
bool canGoBack = false;
late WebViewController mallWebView = initWebViewController(); late WebViewController mallWebView = initWebViewController();
//webView控制器 //webView控制器