67 lines
1.9 KiB
Dart
67 lines
1.9 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
import 'package:webview_flutter_android/webview_flutter_android.dart';
|
|
|
|
import '../../core/theme/app_colors.dart';
|
|
import '../../shared/widgets/top_nav_bar.dart';
|
|
|
|
/// 三方支付成功后在应用内打开 convert 链接的 WebView 页面
|
|
class PaymentWebViewScreen extends StatefulWidget {
|
|
const PaymentWebViewScreen({super.key, required this.paymentUrl});
|
|
|
|
final String paymentUrl;
|
|
|
|
@override
|
|
State<PaymentWebViewScreen> createState() => _PaymentWebViewScreenState();
|
|
}
|
|
|
|
class _PaymentWebViewScreenState extends State<PaymentWebViewScreen> {
|
|
late final WebViewController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = WebViewController()
|
|
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
|
..setNavigationDelegate(
|
|
NavigationDelegate(
|
|
onPageStarted: (_) {},
|
|
onPageFinished: (_) {},
|
|
onWebResourceError: (e) {},
|
|
),
|
|
)
|
|
..loadRequest(Uri.parse(widget.paymentUrl));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.surface,
|
|
appBar: PreferredSize(
|
|
preferredSize: const Size.fromHeight(56),
|
|
child: TopNavBar(
|
|
title: 'Payment',
|
|
showBackButton: true,
|
|
onBack: () => Navigator.of(context).pop(),
|
|
),
|
|
),
|
|
body: SafeArea(
|
|
child: _buildWebView(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildWebView() {
|
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
|
return WebViewWidget.fromPlatformCreationParams(
|
|
params: AndroidWebViewWidgetCreationParams(
|
|
controller: _controller.platform as AndroidWebViewController,
|
|
displayWithHybridComposition: true,
|
|
),
|
|
);
|
|
}
|
|
return WebViewWidget(controller: _controller);
|
|
}
|
|
}
|