92 lines
2.6 KiB
Dart
92 lines
2.6 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../core/data/services/auth_controller.dart';
|
|
import '../../core/theme/app_colors.dart';
|
|
import '../../core/theme/app_theme.dart';
|
|
import '../../core/widgets/auth_gate.dart';
|
|
import '../../l10n/app_localizations.dart';
|
|
import '../account/account_entry_card.dart';
|
|
import '../notices/notices_page.dart';
|
|
|
|
/// 设置页:收纳账号、通知与登录态,不提供手动语言切换。
|
|
class SettingsPage extends StatelessWidget {
|
|
const SettingsPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
final auth = context.watch<AuthController>();
|
|
return Theme(
|
|
data: AppTheme.dark(),
|
|
child: Scaffold(
|
|
key: const Key('settings-page'),
|
|
backgroundColor: AppColors.ink,
|
|
appBar: AppBar(
|
|
backgroundColor: AppColors.ink,
|
|
foregroundColor: AppColors.onSurface,
|
|
title: Text(l10n.settings),
|
|
),
|
|
body: SafeArea(
|
|
top: false,
|
|
child: ListView(
|
|
padding: const EdgeInsets.fromLTRB(14, 12, 14, 28),
|
|
children: [
|
|
if (auth.isSignedIn) ...[
|
|
const AccountEntryCard(),
|
|
const SizedBox(height: 12),
|
|
],
|
|
_noticesTile(context, l10n),
|
|
const SizedBox(height: 24),
|
|
_authAction(context, l10n, auth),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _noticesTile(BuildContext context, AppLocalizations l10n) {
|
|
return Material(
|
|
color: AppColors.card,
|
|
borderRadius: BorderRadius.circular(14),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: ListTile(
|
|
key: const Key('settings-notices'),
|
|
leading: const Icon(
|
|
Icons.notifications_none_rounded,
|
|
color: AppColors.blueSoft,
|
|
),
|
|
title: Text(l10n.notices),
|
|
trailing: const Icon(Icons.chevron_right_rounded),
|
|
onTap: () => Navigator.of(
|
|
context,
|
|
).push<void>(MaterialPageRoute(builder: (_) => const NoticesPage())),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _authAction(
|
|
BuildContext context,
|
|
AppLocalizations l10n,
|
|
AuthController auth,
|
|
) {
|
|
if (auth.isSignedIn) {
|
|
return OutlinedButton(
|
|
key: const Key('settings-sign-out'),
|
|
onPressed: () => unawaited(auth.signOut()),
|
|
child: Text(l10n.signOut),
|
|
);
|
|
}
|
|
return FilledButton(
|
|
key: const Key('settings-sign-in'),
|
|
onPressed: () => unawaited(openAuthPage(context)),
|
|
child: Text(l10n.signIn),
|
|
);
|
|
}
|
|
}
|