feat: 接入起卦后端流程并完善积分扣减链路
This commit is contained in:
@@ -2,6 +2,7 @@ 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';
|
||||
|
||||
@@ -15,9 +16,23 @@ class LegalDocumentScreen extends StatelessWidget {
|
||||
final String title;
|
||||
final String assetPath;
|
||||
|
||||
Future<String> _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(
|
||||
@@ -27,8 +42,43 @@ class LegalDocumentScreen extends StatelessWidget {
|
||||
surfaceTintColor: colors.surfaceContainerLow,
|
||||
),
|
||||
body: FutureBuilder<String>(
|
||||
future: rootBundle.loadString(assetPath),
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user