【发布时间】:2021-09-29 20:44:26
【问题描述】:
我正在尝试在我的 Flutter 项目中运行 mercado_pago_mobile_checkout 的实现。我在Android Emulator中运行时,StartCheckout函数正常工作,但在iOS版本中,调用StartCheckout函数时,出现此错误:
2021-07-22 11:39:14.504430-0300 Runner[31296:218261] Could not cast value of type 'FlutterViewController' (0x10b5bab60) to 'UINavigationController' (0x128b638f0).
似乎被破坏的代码是 AppDelegate.swift:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
var navigationController: UINavigationController?;
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let flutterViewController: FlutterViewController = window?.rootViewController as! FlutterViewController
GeneratedPluginRegistrant.register(with: self)
self.navigationController = UINavigationController(rootViewController: flutterViewController);
self.navigationController?.setNavigationBarHidden(true, animated: false);
self.window = UIWindow(frame: UIScreen.main.bounds);
self.window.rootViewController = self.navigationController;
self.window.makeKeyAndVisible();
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
函数StartCheckout的代码为:
PaymentResult result = await MercadoPagoMobileCheckout.startCheckout(
publicKey,
_idCompra,
// ignore: missing_return
).then((result) async {
if (result.status != null) {
bd
.collection("bagagens")
.document(_bagagem.id)
.setData(_bagagem.toMap())
.then((_) {
bd
.collection("minhas_bagagens")
.document(_bagagem.idUsuario)
.collection("bagagens")
.document(_bagagem.id)
.setData(_bagagem.toMap())
.then((_) {
// cria a bagagem comprada
bd
.collection("minhas_bagagens_compradas")
.document(idUsuarioLogado)
.collection("bagagens_compradas")
.document(_bagagemComprada.id)
.setData(_bagagemComprada.toMap())
.then((_) {
//salvar bagagem pública
bd
.collection("bagagens_compradas")
.document(_bagagemComprada.id)
.setData(_bagagemComprada.toMap())
.then((_) async {
if (_compraComSaldo) {
Map<String, dynamic> dadosAtualizados = {"saldo": "0.00"};
bd
.collection("usuarios")
.document(_idUsuarioLogado)
.updateData(dadosAtualizados);
}
Navigator.pop(_dialogContext);
Navigator.push(context,
MaterialPageRoute(builder: (context) => BarraPrincipal(0)));
/// Notificação para o usuário vendedor
await notificarUsuario([
_idOneSignal
], "Um usuário solicitou a compra de sua bagagem no voo ${_bagagem.identificadorVoo}.",
"Bagagem Solicitada");
/// End Notificação
});
});
});
});
} else {
Navigator.pop(_dialogContext);
}
});
有人知道如何解决这个错误吗?感谢您的关注。
【问题讨论】:
-
你好伙伴你有解决方案吗?
标签: ios flutter uinavigationcontroller