shouldOverrideUrlLoading: (controller, navigationAction) async {
global.webViewController = controller;
var url = navigationAction.request.url;
if (!navigationAction.isForMainFrame && url != null && url.host == 'https://accounts.google.com/') {
await controller.stopLoading();
}
if (url != null) {
// 팝업이 열려있고, 목표 URL이 'dev.metapocket.io'인 경우 팝업 닫기
if (isPopupOpened && url.host == 'dev.metapocket.io') {
await controller.goBack();
isPopupOpened = false;
return NavigationActionPolicy.CANCEL;
}
// 구글 로그인 사용자 설정 변경
var googleOauth = 'https://accounts.google.com/';
var myUrl = 'https://dev.metapocket.io/';
print('before: $url.host');
if (url.host.contains('accounts.google')) {
print('after : $url.host');
controller?.setOptions(options: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent: 'random',
resourceCustomSchemes: ['intent']
),
));
// 추가된 부분: WebView Controller 실행 여부 확인
await controller?.reload();
}
if (url.host.contains('dev.metapocket.io') == myUrl) {
// 추가된 부분: URL이 https://dev.metapocket.io/ 인 경우 Android User Agent로 변경
controller?.setOptions(options: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent: 'Mozilla/5.0 (Linux; Android 13; Build/UPP1.230113.010; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/120.0.6099.144 Mobile Safari/537.36',
resourceCustomSchemes: ['intent']
),
));
print('URL이 https://dev.metapocket.io/ 인 경우 Android User Agent로 변경됨.');
// 여기에 추가: 특정 동작 수행 또는 추가적인 로직 적용
}
await controller?.reload();
}
return NavigationActionPolicy.ALLOW;
},
My code is not working properly What is the problem? After changing the userAgent, I initialize the userAgent when it is in the existing domain again, and then an error appears that I can't find it when I go to the payment window