英文:
Stripe checkout link not loading in Flutter's webview
问题
这是我的webview插件的实现:
class RemittanceWebview extends ConsumerStatefulWidget {
final String url;
final int id;
const RemittanceWebview({
Key? key,
required this.url,
required this.id,
}) : super(key: key);
@override
ConsumerState<ConsumerStatefulWidget> createState() => _RemittanceWebviewState();
}
class _RemittanceWebviewState extends ConsumerState<RemittanceWebview> {
late WebViewController _controller;
@override
void initState() {
super.initState();
_controller = WebViewController()
..clearCache()
..runJavaScript(widget.url)
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {},
onPageStarted: (String url) {},
onPageFinished: (_) {
Helpers.logc("finished loading $_");
},
onWebResourceError: (WebResourceError error) {
Helpers.logc(error.errorType ?? "", error: true);
},
),
)
..loadRequest(Uri.parse(widget.url));
}
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
color: AppColors.whiteColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
),
child: Wrap(
children: [
SizedBox(
height: screenHeight(context, percent: 0.9),
width: double.maxFinite,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.topRight,
child: IconButton(
padding: EdgeInsets.zero,
onPressed: () {
Navigator.of(context).pop();
},
icon: Text(
"Close",
style: semiBoldStyle(16, AppColors.grey59Color),
),
),
),
),
SizedBox(
height: screenHeight(context, percent: 0.8),
child: WebViewWidget(controller: _controller),
),
],
),
)
],
),
);
}
}
希望这有助于解决你的问题。如果还有其他需要,请告诉我。
英文:
I am opening a stripe checkout link with Flutter's web view plugin webview_flutter, but the site keeps on loading without any result. Opening the link on my phone's web browser(chrome or the native Samsung browser) works fine and the site loads up properly.
I need help figuring out why it's not loading in my app's web view.
This is my implementation of the web view plugin:
class RemittanceWebview extends ConsumerStatefulWidget {
final String url;
final int id;
const RemittanceWebview({
Key? key,
required this.url,
required this.id,
}) : super(key: key);
@override
ConsumerState<ConsumerStatefulWidget> createState() => _RemittanceWebviewState();
}
class _RemittanceWebviewState extends ConsumerState<RemittanceWebview> {
late WebViewController _controller;
@override
void initState() {
super.initState();
_controller = WebViewController()
..clearCache()
..runJavaScript(widget.url)
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {},
onPageStarted: (String url) {},
onPageFinished: (_) {
Helpers.logc("finished loading $_");
},
onWebResourceError: (WebResourceError error) {
Helpers.logc(error.errorType ?? "", error: true);
},
),
)
..loadRequest(Uri.parse(widget.url));
}
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
color: AppColors.whiteColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
),
),
child: Wrap(
children: [
SizedBox(
height: screenHeight(context, percent: 0.9),
width: double.maxFinite,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.topRight,
child: IconButton(
padding: EdgeInsets.zero,
onPressed: () {
Navigator.of(context).pop();
},
icon: Text(
"Close",
style: semiBoldStyle(16, AppColors.grey59Color),
),
),
),
),
SizedBox(
height: screenHeight(context, percent: 0.8),
child: WebViewWidget(controller: _controller),
),
],
),
)
],
),
);
}
}
答案1
得分: 0
后端生成的 Stripe 收银台页面链接末尾多了一个问号,因此删除问号后网页视图中的收银台页面显示正常。对于任何遇到这种问题的人,请确保生成的链接中没有奇怪的字符。
英文:
The link to the stripe checkout page being generated by my backend had a ? at the end of it, so removing the ? made the checkout page in the webview.
To anyone facing this kind of issue, please make sure the link generated doesn't have any weird characters in it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论