import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import '../../../../l10n/app_localizations.dart'; import '../../../../shared/theme/design_tokens.dart'; import '../../../../shared/widgets/app_loading_indicator.dart'; class LegalDocumentScreen extends StatelessWidget { const LegalDocumentScreen({ super.key, required this.title, required this.assetPath, }); final String title; final String assetPath; Future _loadAsset() async { try { final data = await rootBundle.loadString(assetPath); if (data.isEmpty) { throw Exception('Asset file is empty: $assetPath'); } return data; } catch (e) { debugPrint('Failed to load asset: $assetPath, error: $e'); rethrow; } } @override Widget build(BuildContext context) { final colors = Theme.of(context).colorScheme; final l10n = AppLocalizations.of(context)!; return Scaffold( backgroundColor: colors.surfaceContainerLow, appBar: AppBar( title: Text(title), centerTitle: true, backgroundColor: colors.surfaceContainerLow, surfaceTintColor: colors.surfaceContainerLow, ), body: FutureBuilder( future: _loadAsset(), builder: (context, snapshot) { if (snapshot.hasError) { return Center( child: Padding( padding: const EdgeInsets.all(AppSpacing.lg), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.error_outline, size: 48, color: colors.error), const SizedBox(height: AppSpacing.md), Text( l10n.legalDocumentLoadFailedTitle, style: Theme.of(context).textTheme.titleMedium, ), const SizedBox(height: AppSpacing.sm), Text( '${l10n.legalDocumentLoadFailedPathPrefix}: $assetPath', style: Theme.of( context, ).textTheme.bodySmall?.copyWith(color: colors.error), textAlign: TextAlign.center, ), const SizedBox(height: AppSpacing.xs), Text( '${l10n.legalDocumentLoadFailedErrorPrefix}: ${snapshot.error}', style: Theme.of( context, ).textTheme.bodySmall?.copyWith(color: colors.error), textAlign: TextAlign.center, ), ], ), ), ); } if (!snapshot.hasData) { return const Center( child: AppLoadingIndicator(variant: AppLoadingVariant.surface), ); } return Markdown( data: snapshot.data!, padding: const EdgeInsets.all(AppSpacing.lg), styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context)) .copyWith( p: Theme.of( context, ).textTheme.bodyMedium?.copyWith(height: 1.7), h1: Theme.of(context).textTheme.titleLarge, h2: Theme.of(context).textTheme.titleMedium, h3: Theme.of( context, ).textTheme.titleMedium?.copyWith(color: colors.primary), blockSpacing: AppSpacing.lg, ), ); }, ), ); } }