help_detail_screen.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import 'package:flutter/material.dart';
  2. import '../../../core/l10n/app_localizations.dart';
  3. import '../../../core/theme/app_colors.dart';
  4. import 'package:flutter_riverpod/flutter_riverpod.dart';
  5. import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
  6. import 'package:go_router/go_router.dart';
  7. import '../../../providers/help_center_provider.dart';
  8. class HelpDetailScreen extends ConsumerWidget {
  9. const HelpDetailScreen({super.key, required this.id});
  10. final String id;
  11. @override
  12. Widget build(BuildContext context, WidgetRef ref) {
  13. final cs = Theme.of(context).colorScheme;
  14. final isDark = Theme.of(context).brightness == Brightness.dark;
  15. final asyncDetail = ref.watch(helpDetailProvider(id));
  16. return Scaffold(
  17. appBar: AppBar(
  18. elevation: 0,
  19. leading: IconButton(
  20. icon: const Icon(Icons.chevron_left, size: 28),
  21. onPressed: () => context.pop(),
  22. ),
  23. title: Text(
  24. AppLocalizations.of(context)!.helpDetail,
  25. style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
  26. ),
  27. centerTitle: true,
  28. ),
  29. body: asyncDetail.when(
  30. loading: () => const Center(child: CircularProgressIndicator()),
  31. error: (e, _) => Center(
  32. child: Text(AppLocalizations.of(context)!.loadFailed,
  33. style: TextStyle(color: cs.onSurface.withAlpha(153))),
  34. ),
  35. data: (detail) {
  36. if (detail == null) {
  37. return Center(
  38. child: Text(AppLocalizations.of(context)!.contentNotFound,
  39. style: TextStyle(color: cs.onSurface.withAlpha(153))),
  40. );
  41. }
  42. return SingleChildScrollView(
  43. padding: const EdgeInsets.all(16),
  44. child: Column(
  45. crossAxisAlignment: CrossAxisAlignment.start,
  46. children: [
  47. // 标题
  48. Container(
  49. width: double.infinity,
  50. padding: const EdgeInsets.all(16),
  51. decoration: BoxDecoration(
  52. color: isDark ? AppColors.darkBgSecondary : AppColors.lightBgSecondary,
  53. borderRadius: BorderRadius.circular(10),
  54. ),
  55. child: Text(
  56. detail.title,
  57. style: TextStyle(
  58. color: cs.onSurface,
  59. fontSize: 15,
  60. fontWeight: FontWeight.w600,
  61. ),
  62. ),
  63. ),
  64. const SizedBox(height: 16),
  65. // HTML 正文
  66. HtmlWidget(
  67. detail.content,
  68. textStyle: TextStyle(
  69. color: cs.onSurface,
  70. fontSize: 14,
  71. height: 1.7,
  72. ),
  73. ),
  74. ],
  75. ),
  76. );
  77. },
  78. ),
  79. );
  80. }
  81. }