feat(mine): 重做我的页会员卡与功能宫格布局
This commit is contained in:
1 parent
e7399fa3fd
commit
53e8c924a6
12 files changed
+1969
-513
No files matched your search
@@ -31,8 +31,10 @@ import '../watch_records/watch_records_page.dart';
|
||||
import 'mine_binding.dart';
|
||||
import 'mine_logic.dart';
|
||||
import 'mine_types.dart';
|
||||
import 'widgets/mine_action_grid.dart';
|
||||
import 'widgets/mine_header.dart';
|
||||
import 'widgets/mine_menu.dart';
|
||||
import 'widgets/mine_stats_panel.dart';
|
||||
|
||||
/// K28-B 我的页。
|
||||
class MyPage extends StatefulWidget {
|
||||
@@ -84,7 +86,9 @@ class _MyPageState extends State<MyPage> {
|
||||
_activationRefreshScheduled = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_activationRefreshScheduled = false;
|
||||
if (mounted) unawaited(_favorites.load());
|
||||
if (!mounted) return;
|
||||
unawaited(_favorites.load());
|
||||
_refreshWallet(onlyIfMissing: true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -96,9 +100,17 @@ class _MyPageState extends State<MyPage> {
|
||||
if (!mounted || !widget.active) return;
|
||||
logic.syncPage(active: true, wasActive: false);
|
||||
unawaited(_favorites.load());
|
||||
_refreshWallet();
|
||||
});
|
||||
}
|
||||
|
||||
void _refreshWallet({bool onlyIfMissing = false}) {
|
||||
if (!_auth.isSignedIn) return;
|
||||
final wallet = context.read<WalletController>();
|
||||
if (wallet.loading || (onlyIfMissing && wallet.snapshot != null)) return;
|
||||
unawaited(wallet.load());
|
||||
}
|
||||
|
||||
void _onAuthChanged() {
|
||||
final signedIn = _auth.isSignedIn;
|
||||
if (signedIn == _wasSignedIn) return;
|
||||
@@ -165,78 +177,62 @@ class _MyPageState extends State<MyPage> {
|
||||
}
|
||||
|
||||
Widget _body(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return ListView(
|
||||
key: const Key('mine-page-scroll'),
|
||||
padding: const EdgeInsets.only(bottom: AppDimens.spaceXl),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimens.pageHorizontal,
|
||||
),
|
||||
child: MineHeader(
|
||||
_section(
|
||||
MineHeader(
|
||||
onLogin: _openLogin,
|
||||
onEdit: () => _push(const AccountProfilePage()),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimens.spaceSm),
|
||||
_section(_statsPanel()),
|
||||
const SizedBox(height: AppDimens.spaceMd),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimens.pageHorizontal,
|
||||
),
|
||||
child: MineVipBanner(
|
||||
onOpen: () => _openDestination(MineDestination.vip),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimens.mineSectionGap),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimens.pageHorizontal,
|
||||
),
|
||||
child: MineQuickActions(
|
||||
onWallet: () => _openDestination(MineDestination.wallet),
|
||||
onFavorites: () => _push(const FavoritesPage()),
|
||||
onDownloads: () => _openDestination(MineDestination.downloads),
|
||||
onHistory: () => _openDestination(MineDestination.history),
|
||||
),
|
||||
_section(
|
||||
MineVipBanner(onOpen: () => _openDestination(MineDestination.vip)),
|
||||
),
|
||||
const SizedBox(height: AppDimens.mineSectionGap),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimens.mineGridHorizontal,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.moreServices,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textTertiary,
|
||||
fontSize: AppDimens.mineSectionTitle,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimens.spaceSm),
|
||||
MineServiceList(
|
||||
onOpen: _openDestination,
|
||||
onLanguage: _openLanguage,
|
||||
languageName: _languageName(context),
|
||||
),
|
||||
],
|
||||
child: MineActionGrid(
|
||||
primaryActions: MinePrimaryActions(
|
||||
onWallet: () => _openDestination(MineDestination.wallet),
|
||||
onFavorites: () => unawaited(_openFavoritesPage()),
|
||||
onDownloads: () => _openDestination(MineDestination.downloads),
|
||||
onHistory: () => _openDestination(MineDestination.history),
|
||||
),
|
||||
serviceActions: MineServiceActions(
|
||||
onOpen: _openDestination,
|
||||
onLanguage: _openLanguage,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 语言设置行右侧展示的当前语言名。
|
||||
String _languageName(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final code = context.read<LocaleController>().locale?.languageCode;
|
||||
return switch (code) {
|
||||
'en' => l10n.english,
|
||||
'id' => l10n.bahasaIndonesia,
|
||||
_ => l10n.simplifiedChinese,
|
||||
};
|
||||
Widget _section(Widget child) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppDimens.pageHorizontal),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _statsPanel() {
|
||||
return MineStatsSection(
|
||||
watchRecordCount: logic.recentError == null
|
||||
? logic.watchRecordTotal
|
||||
: null,
|
||||
actions: MineStatsActions(
|
||||
onWallet: () => _openDestination(MineDestination.wallet),
|
||||
onHistory: () => _openDestination(MineDestination.history),
|
||||
onFavorites: () => unawaited(_openFavoritesPage()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _openDestination(MineDestination destination) {
|
||||
@@ -269,6 +265,11 @@ class _MyPageState extends State<MyPage> {
|
||||
if (mounted) unawaited(logic.refreshRecent());
|
||||
}
|
||||
|
||||
Future<void> _openFavoritesPage() async {
|
||||
await _push(const FavoritesPage());
|
||||
if (mounted) unawaited(_favorites.load());
|
||||
}
|
||||
|
||||
Future<void> _push(Widget page) {
|
||||
return Navigator.of(
|
||||
context,
|
||||
@@ -373,56 +374,56 @@ class _LanguageSheet extends StatelessWidget {
|
||||
type: MaterialType.transparency,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 14, 20, 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.language,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 14, 20, 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.language,
|
||||
style: const TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.close,
|
||||
onPressed: () => Navigator.pop(context),
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 32,
|
||||
minHeight: 32,
|
||||
IconButton(
|
||||
tooltip: l10n.close,
|
||||
onPressed: () => Navigator.pop(context),
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 32,
|
||||
minHeight: 32,
|
||||
),
|
||||
icon: const Icon(Icons.close_rounded, size: 20),
|
||||
),
|
||||
icon: const Icon(Icons.close_rounded, size: 20),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (final option in options)
|
||||
ListTile(
|
||||
key: option.$2,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
title: Text(option.$3),
|
||||
trailing: selected?.languageCode == option.$1.languageCode
|
||||
? const Icon(
|
||||
Icons.check_rounded,
|
||||
color: AppColors.textPrimary,
|
||||
)
|
||||
: null,
|
||||
onTap: () => Navigator.pop(context, option.$1),
|
||||
],
|
||||
),
|
||||
],
|
||||
for (final option in options)
|
||||
ListTile(
|
||||
key: option.$2,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
title: Text(option.$3),
|
||||
trailing: selected?.languageCode == option.$1.languageCode
|
||||
? const Icon(
|
||||
Icons.check_rounded,
|
||||
color: AppColors.textPrimary,
|
||||
)
|
||||
: null,
|
||||
onTap: () => Navigator.pop(context, option.$1),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user