Stripe支付链接在Flutter的Web视图中未加载。

huangapple go评论68阅读模式
英文:

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&lt;ConsumerStatefulWidget&gt; createState() =&gt; _RemittanceWebviewState();
}
class _RemittanceWebviewState extends ConsumerState&lt;RemittanceWebview&gt; {
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(&quot;finished loading $_&quot;);
},
onWebResourceError: (WebResourceError error) {
Helpers.logc(error.errorType ?? &quot;&quot;, 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(
&quot;Close&quot;,
style: semiBoldStyle(16, AppColors.grey59Color),
),
),
),
),
SizedBox(
height: screenHeight(context, percent: 0.8),
child: WebViewWidget(controller: _controller),
),
],
),
)
],
),
);
}
}

Stripe支付链接在Flutter的Web视图中未加载。

答案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.

huangapple
  • 本文由 发表于 2023年3月7日 19:43:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661547.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定