generated from dellevin/template
218 lines
7.1 KiB
Dart
218 lines
7.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'dart:io' show Platform;
|
|
import '../providers/app_provider.dart';
|
|
import '../utils/user_prefs.dart';
|
|
import '../widgets/app_overlay.dart';
|
|
|
|
/// 新增记录弹窗 — 供底部导航栏和 NavigationRail 共用
|
|
|
|
void showQuickAddSheet(BuildContext context, AppProvider provider) {
|
|
final currentTab = provider.mainTabIndex;
|
|
switch (currentTab) {
|
|
case 0:
|
|
final statusMap = {0: 'watched', 1: 'watching', 2: 'want_to_watch'};
|
|
final currentStatus =
|
|
statusMap[provider.movieStatusIndex] ?? 'want_to_watch';
|
|
Navigator.pushNamed(context, '/movie-form',
|
|
arguments: {'initialStatus': currentStatus});
|
|
case 1:
|
|
final statusMap = {0: 'read', 1: 'reading', 2: 'want_to_read', 3: 'abandoned'};
|
|
final currentStatus =
|
|
statusMap[provider.bookStatusIndex] ?? 'want_to_read';
|
|
Navigator.pushNamed(context, '/book-form',
|
|
arguments: {'initialStatus': currentStatus});
|
|
case 2:
|
|
Navigator.pushNamed(context, '/note-form');
|
|
case 3:
|
|
final statusMap = {0: 'completed', 1: 'playing', 2: 'want_to_play', 3: 'abandoned'};
|
|
final currentStatus =
|
|
statusMap[provider.gameStatusIndex] ?? 'want_to_play';
|
|
Navigator.pushNamed(context, '/game-form',
|
|
arguments: {'initialStatus': currentStatus});
|
|
default:
|
|
showAddSheet(context, provider);
|
|
}
|
|
}
|
|
|
|
void showAddSheet(BuildContext context, AppProvider provider) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
final outerContext = context;
|
|
final userPrefs = UserPrefs();
|
|
|
|
final options = <Widget>[];
|
|
if (userPrefs.showMovieTab) {
|
|
options.add(_buildOption(
|
|
colors: colors,
|
|
icon: Icons.movie_outlined,
|
|
title: '添加观影',
|
|
subtitle: '记录你看过的电影',
|
|
onTap: () {
|
|
Navigator.pop(outerContext);
|
|
final statusMap = {0: 'watched', 1: 'watching', 2: 'want_to_watch'};
|
|
final s = statusMap[provider.movieStatusIndex] ?? 'want_to_watch';
|
|
Navigator.pushNamed(outerContext, '/movie-form',
|
|
arguments: {'initialStatus': s});
|
|
},
|
|
));
|
|
}
|
|
if (userPrefs.showBookTab) {
|
|
options.add(_buildOption(
|
|
colors: colors,
|
|
icon: Icons.menu_book_outlined,
|
|
title: '添加阅读',
|
|
subtitle: '记录你读过的书',
|
|
onTap: () {
|
|
Navigator.pop(outerContext);
|
|
final statusMap = {0: 'read', 1: 'reading', 2: 'want_to_read', 3: 'abandoned'};
|
|
final s = statusMap[provider.bookStatusIndex] ?? 'want_to_read';
|
|
Navigator.pushNamed(outerContext, '/book-form',
|
|
arguments: {'initialStatus': s});
|
|
},
|
|
));
|
|
}
|
|
if (userPrefs.showNoteTab) {
|
|
options.add(_buildOption(
|
|
colors: colors,
|
|
icon: Icons.sticky_note_2_outlined,
|
|
title: '添加笔记',
|
|
subtitle: '记录你的想法和笔记',
|
|
onTap: () {
|
|
Navigator.pop(outerContext);
|
|
Navigator.pushNamed(outerContext, '/note-form');
|
|
},
|
|
));
|
|
}
|
|
if (userPrefs.showGameTab) {
|
|
options.add(_buildOption(
|
|
colors: colors,
|
|
icon: Icons.sports_esports_outlined,
|
|
title: '添加游戏',
|
|
subtitle: '记录你玩过的游戏',
|
|
onTap: () {
|
|
Navigator.pop(outerContext);
|
|
final statusMap = {0: 'completed', 1: 'playing', 2: 'want_to_play', 3: 'abandoned'};
|
|
final s = statusMap[provider.gameStatusIndex] ?? 'want_to_play';
|
|
Navigator.pushNamed(outerContext, '/game-form',
|
|
arguments: {'initialStatus': s});
|
|
},
|
|
));
|
|
}
|
|
|
|
if (Platform.isWindows) {
|
|
appDialog(
|
|
context: context,
|
|
builder: (ctx) {
|
|
final bc = Theme.of(ctx).colorScheme;
|
|
return AlertDialog(
|
|
backgroundColor: bc.surface,
|
|
elevation: 0,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
|
titlePadding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 8),
|
|
title: Text('新增记录',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: bc.onSurface)),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: options,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
} else {
|
|
appModalBottomSheet(
|
|
context: context,
|
|
backgroundColor: colors.surface,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
),
|
|
builder: (ctx) {
|
|
final bc = Theme.of(ctx).colorScheme;
|
|
return SafeArea(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
width: 32,
|
|
height: 3,
|
|
decoration: BoxDecoration(
|
|
color: bc.onSurface.withValues(alpha: 0.15),
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: Row(
|
|
children: [
|
|
Text('新增记录',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: bc.onSurface)),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
...options,
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget _buildOption({
|
|
required ColorScheme colors,
|
|
required IconData icon,
|
|
required String title,
|
|
required String subtitle,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
return InkWell(
|
|
onTap: onTap,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 36,
|
|
height: 36,
|
|
decoration: BoxDecoration(
|
|
color: colors.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Icon(icon, size: 18, color: colors.onSurface.withValues(alpha: 0.6)),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(title,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
color: colors.onSurface)),
|
|
const SizedBox(height: 1),
|
|
Text(subtitle,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: colors.onSurface.withValues(alpha: 0.4))),
|
|
],
|
|
),
|
|
),
|
|
Icon(Icons.chevron_right,
|
|
color: colors.onSurface.withValues(alpha: 0.25), size: 18),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|