Files
ReelShort/lib/pages/settings/legal_links_card.dart
T

118 lines
3.1 KiB
Dart

// Author: fruit.com.cn
import 'dart:async';
import 'package:flutter/material.dart';
import '../../core/legal/legal_opener.dart';
import '../../core/legal/legal_page.dart';
import '../../core/theme/app_colors.dart';
import '../../core/theme/app_dimens.dart';
import '../../l10n/app_localizations.dart';
/// 设置页里的服务条款和隐私协议。点一行就打开当前语言的公开页。
class LegalLinksCard extends StatelessWidget {
const LegalLinksCard({super.key, this.open});
final Future<void> Function(String url)? open;
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final rows = <_LegalRow>[
_LegalRow(
key: const Key('settings-terms'),
title: l10n.legalTerms,
path: legalTermsPath,
icon: Icons.article_outlined,
),
_LegalRow(
key: const Key('settings-privacy'),
title: l10n.legalPrivacy,
path: legalPrivacyPath,
icon: Icons.shield_outlined,
),
];
return Material(
color: AppColors.contentSurface,
clipBehavior: Clip.antiAlias,
child: Column(
children: [
for (var index = 0; index < rows.length; index++) ...[
if (index > 0)
const Divider(
height: AppDimens.mineGridDividerWidth,
thickness: AppDimens.mineGridDividerWidth,
color: AppColors.contentBorder,
),
_tile(context, rows[index]),
],
],
),
);
}
Widget _tile(BuildContext context, _LegalRow row) {
return InkWell(
key: row.key,
onTap: () => _open(context, row.path),
child: SizedBox(
height: AppDimens.mineMoreRowHeight,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: AppDimens.spaceLg),
child: Row(
children: [
Icon(
row.icon,
color: AppColors.textSecondary,
size: 20,
),
const SizedBox(width: 10),
Expanded(
child: Text(
row.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.textPrimary,
fontSize: AppDimens.listTitle,
),
),
),
const Icon(
Icons.chevron_right_rounded,
color: AppColors.textSecondary,
size: AppDimens.accountIcon,
),
],
),
),
),
);
}
void _open(BuildContext context, String path) {
final url = legalPageUrl(path, Localizations.localeOf(context));
final custom = open;
if (custom != null) {
unawaited(custom(url));
return;
}
unawaited(openLegalUrlOrNotify(context, url));
}
}
class _LegalRow {
const _LegalRow({
required this.key,
required this.title,
required this.path,
required this.icon,
});
final Key key;
final String title;
final String path;
final IconData icon;
}