【问题标题】:flutter paypal via webview通过 webview 扑动贝宝
【发布时间】:2019-01-09 20:16:35
【问题描述】:

我正在尝试通过 webview 为我的 Flutter 应用集成 paypal 支付。

return new MaterialApp(
routes: {
"/": (_) => new WebviewScaffold(
  url: "https://www.paypal.com/cgi-bin/webscr?    business=xxxx.com&cmd=_xclick&item_name=Hot+Sauce-12oz.+Bottle&amount=5.95&currency_code=USD",
  appBar: new AppBar(
    title: new Text(
      "Payment",
    ),
  ),
)
},
);

当我运行页面时,应用程序意外关闭并显示错误消息

Unsupported value: <FlutterError: 0x1c422d200> of type FlutterError Lost connection to device.

这是我的颤振医生。

Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.1 17B1003, locale en-HK)
[✓] Android toolchain - develop for Android devices (Android SDK 26.0.2)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
[✓] Android Studio (version 3.1)
[✓] Connected devices (3 available)

【问题讨论】:

  • 你是否让 PayPal 与 Flutter 一起工作?

标签: paypal webview flutter


【解决方案1】:

您忘记了 MaterialApp 中的 initialRoute 参数 正确的做法是:

return new MaterialApp(
       initialRoute: '/',
       routes: {
        "/": (_) => new WebviewScaffold(
              url: "https://www.paypal.com/",
              appBar: new AppBar(
                title: new Text(
                  "Payment",
                ),
              ),
            )
        },
);

【讨论】:

    【解决方案2】:

    您可以尝试我的插件flutter_inappwebview,通过 WebView 为您的 Flutter 应用集成 PayPal 支付。

    您的示例网址示例:

    import 'dart:async';
    
    import 'package:flutter/material.dart';
    
    import 'package:flutter_inappwebview/flutter_inappwebview.dart';
    
    Future main() async {
      runApp(new MyApp());
    }
    
    class MyApp extends StatefulWidget {
      @override
      _MyAppState createState() => new _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
    
      @override
      void initState() {
        super.initState();
      }
    
      @override
      void dispose() {
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
            home: InAppWebViewPage()
        );
      }
    }
    
    class InAppWebViewPage extends StatefulWidget {
      @override
      _InAppWebViewPageState createState() => new _InAppWebViewPageState();
    }
    
    class _InAppWebViewPageState extends State<InAppWebViewPage> {
      InAppWebViewController webView;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
                title: Text("InAppWebView")
            ),
            body: Container(
                child: Column(children: <Widget>[
                  Expanded(
                    child: Container(
                      child: InAppWebView(
                        initialUrl: "https://www.paypal.com/cgi-bin/webscr?business=xxxx.com&cmd=_xclick&item_name=Hot+Sauce-12oz.+Bottle&amount=5.95&currency_code=USD",
                        initialHeaders: {},
                        initialOptions: InAppWebViewWidgetOptions(
                          inAppWebViewOptions: InAppWebViewOptions(
                            debuggingEnabled: true,
                          ),
                        ),
                        onWebViewCreated: (InAppWebViewController controller) {
                          webView = controller;
                        },
                        onLoadStart: (InAppWebViewController controller, String url) {
    
                        },
                        onLoadStop: (InAppWebViewController controller, String url) {
    
                        },
                      ),
                    ),
                  ),
                ]))
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-03-29
      • 2012-11-23
      • 2011-09-22
      • 1970-01-01
      • 2019-10-03
      • 2017-07-04
      • 2013-08-26
      • 2012-04-20
      • 1970-01-01
      相关资源
      最近更新 更多