ar_tourism_flutter_unity/lib/pages/mine/help/help.dart
2025-05-14 17:04:13 +08:00

74 lines
1.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../../../components/appbar.dart';
class HelpPage extends StatefulWidget {
const HelpPage({super.key});
@override
State<HelpPage> createState() => _HelpPageState();
}
class _HelpPageState extends State<HelpPage> with AutomaticKeepAliveClientMixin {
// 添加静态 controller
static WebViewController? _staticController;
late final WebViewController _controller;
bool _isLoading = true;
@override
void initState() {
super.initState();
// 如果已经有静态 controller直接使用
if (_staticController != null) {
_controller = _staticController!;
_isLoading = false;
} else {
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(Colors.white)
..setNavigationDelegate(
NavigationDelegate(
onPageFinished: (String url) {
if (mounted) {
setState(() {
_isLoading = false;
});
}
},
onNavigationRequest: (NavigationRequest request) {
return NavigationDecision.navigate;
},
),
)
..loadFlutterAsset('assets/chatwoot.html');
// 保存到静态变量
_staticController = _controller;
}
}
@override
Widget build(BuildContext context) {
// 必须调用 super.build
super.build(context);
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: const CustomAppBar(title: '帮助中心'),
body: Stack(
children: [
WebViewWidget(controller: _controller),
if (_isLoading)
const Center(
child: CircularProgressIndicator(),
),
],
),
);
}
// 实现 wantKeepAlive
@override
bool get wantKeepAlive => true;
}