global_web_page.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:plugin_basic/utils/ext_get_nav.dart';
  4. import 'package:router/path/router_path.dart';
  5. import 'package:shared/utils/log_utils.dart';
  6. import 'package:shared/utils/screen_util.dart';
  7. import 'package:widgets/my_appbar.dart';
  8. import 'package:widgets/widget_export.dart';
  9. import '../base/base_stateless_page.dart';
  10. import '../widget/webview_page.dart';
  11. /*
  12. * 全局的公共Web页面
  13. */
  14. class GlobalWebPage extends BaseStatelessPage {
  15. GlobalWebPage({super.key});
  16. //启动当前页面
  17. static void startInstance(
  18. String title,
  19. String url, {
  20. bool isShowAppBar = true,
  21. bool isNeedEncodeFull = true,
  22. }) {
  23. return Get.start(RouterPath.globalWeb, arguments: {'title': title, 'initialUrl': isNeedEncodeFull?Uri.encodeFull(url):url, 'isShowAppBar': isShowAppBar});
  24. }
  25. @override
  26. GetxController createRawController() {
  27. throw UnimplementedError();
  28. }
  29. @override
  30. void initState() {}
  31. @override
  32. Widget buildWidget(BuildContext context) {
  33. bool isShowAppBar = Get.arguments['isShowAppBar'];
  34. String initialUrl = Get.arguments['initialUrl'];
  35. String title = Get.arguments['title'];
  36. Log.d("GlobalWebPage 的参数 isShowAppBar:$isShowAppBar title:$title initialUrl:$initialUrl ");
  37. if (initialUrl.startsWith('http') || initialUrl.startsWith('https')) {
  38. //网页加载
  39. return WebViewPage(
  40. showAppbar: isShowAppBar,
  41. initialUrl: initialUrl,
  42. arguments: {'title': title},
  43. );
  44. } else {
  45. //富文本加载
  46. return SafeArea(
  47. bottom: MediaQuery.of(context).padding.bottom > 38,
  48. top: false,
  49. child: Container(
  50. width: double.infinity,
  51. height: double.infinity,
  52. padding: EdgeInsets.only(top: ScreenUtil.getStatusBarH(context)),
  53. decoration: const BoxDecoration(
  54. gradient: LinearGradient(
  55. colors: [
  56. Color(0xFF091D44),
  57. Color(0xFF245A8A),
  58. Color(0xFF7F7CEC),
  59. ],
  60. begin: Alignment.topCenter,
  61. end: Alignment.bottomCenter,
  62. ),
  63. ),
  64. child: Column(
  65. children: [
  66. MyAppBar.titleBar(context, title),
  67. SingleChildScrollView(
  68. scrollDirection: Axis.vertical,
  69. physics: const BouncingScrollPhysics(),
  70. child: Html(data: initialUrl).paddingOnly(left: 10, right: 10),
  71. )
  72. ],
  73. ),
  74. ),
  75. );
  76. }
  77. }
  78. }