help_dialog.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:fis_common/logger/logger.dart';
  5. import 'package:get/get.dart';
  6. import 'package:vitalapp/components/alert_dialog.dart';
  7. class HelpDialog extends StatefulWidget {
  8. const HelpDialog({super.key});
  9. @override
  10. State<StatefulWidget> createState() => _HelpDialogState();
  11. static void show() {
  12. Get.dialog(
  13. const VAlertDialog(
  14. width: 520,
  15. title: "帮助中心",
  16. contentPadding: EdgeInsets.symmetric(horizontal: 24),
  17. content: SizedBox(
  18. height: 280,
  19. child: HelpDialog(),
  20. ),
  21. // showCancel: false,
  22. ),
  23. barrierDismissible: true,
  24. );
  25. }
  26. }
  27. class _HelpDialogState extends State<HelpDialog> {
  28. List<Map<String, dynamic>>? _items;
  29. @override
  30. void initState() {
  31. super.initState();
  32. WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
  33. _loadItems();
  34. });
  35. }
  36. Future<void> _loadItems() async {
  37. try {
  38. final jsonText = await rootBundle.loadString("assets/docs/help.json");
  39. final jsonMap = jsonDecode(jsonText);
  40. setState(() {
  41. _items =
  42. (jsonMap as List).map((e) => e as Map<String, dynamic>).toList();
  43. });
  44. } catch (e) {
  45. logger.e("HelpDialog - _loadItems error.", e);
  46. }
  47. }
  48. @override
  49. Widget build(BuildContext context) {
  50. if (_items == null) {
  51. return const Center(
  52. child: SizedBox(
  53. width: 60,
  54. height: 60,
  55. child: CircularProgressIndicator(),
  56. ),
  57. );
  58. }
  59. final children = <Widget>[];
  60. final count = _items!.length;
  61. for (int i = 0; i < count; i++) {
  62. if (i > 0) {
  63. children.add(const SizedBox(height: 12));
  64. }
  65. final e = _items![i];
  66. children.add(HelpCenterItem(e));
  67. }
  68. return ListView(
  69. shrinkWrap: false,
  70. padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 12),
  71. children: children,
  72. );
  73. }
  74. }
  75. class HelpCenterItem extends StatelessWidget {
  76. final Map<String, dynamic> itemMap;
  77. const HelpCenterItem(this.itemMap, {super.key});
  78. @override
  79. Widget build(BuildContext context) {
  80. final title = itemMap['title'];
  81. final content = itemMap['content'];
  82. return Column(
  83. mainAxisSize: MainAxisSize.min,
  84. mainAxisAlignment: MainAxisAlignment.start,
  85. crossAxisAlignment: CrossAxisAlignment.start,
  86. children: [
  87. HelpDialogItemTitle(title: title),
  88. const SizedBox(height: 4),
  89. HelpDialogItemContnt(content: content),
  90. ],
  91. );
  92. }
  93. }
  94. class HelpDialogItemTitle extends StatelessWidget {
  95. final String title;
  96. const HelpDialogItemTitle({super.key, required this.title});
  97. @override
  98. Widget build(BuildContext context) {
  99. return Text(
  100. title,
  101. style: const TextStyle(fontSize: 20),
  102. );
  103. }
  104. }
  105. class HelpDialogItemContnt extends StatelessWidget {
  106. final String content;
  107. const HelpDialogItemContnt({super.key, required this.content});
  108. @override
  109. Widget build(BuildContext context) {
  110. return Padding(
  111. padding: const EdgeInsets.only(left: 12.0),
  112. child: Text(
  113. content,
  114. style: const TextStyle(fontSize: 16),
  115. ),
  116. );
  117. }
  118. }