代码优化2

This commit is contained in:
DelLevin-Home
2026-06-27 19:20:03 +08:00
parent bcff4f6c01
commit a1fe0a23ef
31 changed files with 285 additions and 162 deletions

View File

@@ -89,7 +89,7 @@ class _BookSharePageState extends State<BookSharePage> {
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
color: Colors.black.withValues(alpha: 0.1),
blurRadius: 20,
offset: const Offset(0, 10),
),

View File

@@ -104,7 +104,7 @@ class _HomePageState extends State<HomePage> {
right: Radius.circular(28)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
color: Colors.black.withValues(alpha: 0.08),
blurRadius: 20,
offset: const Offset(0, 4),
spreadRadius: 0,

View File

@@ -91,15 +91,26 @@ class _MediaCalendarPageState extends State<MediaCalendarPage> {
_buildMonthHeader(colors),
_buildWeekdayLabels(colors),
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
_buildCalendarGrid(colors, today),
if (_selectedDay != null) _buildSelectedDayDetail(colors),
const SizedBox(height: 80),
],
),
),
child: _selectedDay != null && (_dayItems[_selectedDay]?.isNotEmpty ?? false)
? Column(
children: [
SingleChildScrollView(
child: _buildCalendarGrid(colors, today),
),
Expanded(
child: _buildSelectedDayDetail(colors),
),
],
)
: SingleChildScrollView(
child: Column(
children: [
_buildCalendarGrid(colors, today),
if (_selectedDay != null) _buildSelectedDayDetail(colors),
const SizedBox(height: 80),
],
),
),
),
],
),
@@ -299,7 +310,6 @@ class _MediaCalendarPageState extends State<MediaCalendarPage> {
}
return Container(
constraints: const BoxConstraints(maxHeight: 200),
decoration: BoxDecoration(
border: Border(top: BorderSide(color: colors.outlineVariant, width: 0.5)),
),
@@ -322,9 +332,8 @@ class _MediaCalendarPageState extends State<MediaCalendarPage> {
],
),
),
Flexible(
Expanded(
child: ListView.separated(
shrinkWrap: true,
padding: const EdgeInsets.symmetric(horizontal: 16),
itemCount: items.length,
separatorBuilder: (_, __) => Divider(height: 0.5, color: colors.outlineVariant),

View File

@@ -99,7 +99,7 @@ class _DoubanWebViewPageState extends State<DoubanWebViewPage> {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.3),
color: Colors.black.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(8),
),
child: Material(
@@ -130,7 +130,7 @@ class _DoubanWebViewPageState extends State<DoubanWebViewPage> {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.9),
color: Colors.white.withValues(alpha: 0.9),
borderRadius: BorderRadius.circular(8),
),
child: Material(

View File

@@ -147,7 +147,7 @@ class _MoviePostersPageState extends State<MoviePostersPage> {
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
color: Colors.black.withValues(alpha: 0.08),
blurRadius: 8,
offset: const Offset(0, 2),
),
@@ -176,7 +176,7 @@ class _MoviePostersPageState extends State<MoviePostersPage> {
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.3),
Colors.black.withValues(alpha: 0.3),
],
),
),

View File

@@ -76,7 +76,7 @@ class _PosterGalleryPageState extends State<PosterGalleryPage> {
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.black.withOpacity(0.7),
Colors.black.withValues(alpha: 0.7),
Colors.transparent,
],
),
@@ -126,7 +126,7 @@ class _PosterGalleryPageState extends State<PosterGalleryPage> {
shape: BoxShape.circle,
color: index == _currentIndex
? Colors.white
: Colors.white.withOpacity(0.4),
: Colors.white.withValues(alpha: 0.4),
),
),
),

View File

@@ -33,6 +33,7 @@ class _NoteFormPageState extends State<NoteFormPage> {
String? _tempNoteId; // 新建模式时使用的临时笔记ID
String _editorMode = 'edit'; // 'edit' | 'preview'
Timer? _autoSaveTimer;
Timer? _saveStatusTimer;
String _saveStatus = ''; // '', 'saved'
Note? _savedNote; // 新建模式首次自动保存后的笔记引用
@@ -56,6 +57,7 @@ class _NoteFormPageState extends State<NoteFormPage> {
@override
void dispose() {
_autoSaveTimer?.cancel();
_saveStatusTimer?.cancel();
_titleController.dispose();
_contentController.dispose();
super.dispose();
@@ -116,7 +118,8 @@ class _NoteFormPageState extends State<NoteFormPage> {
}
if (mounted) {
setState(() => _saveStatus = 'saved');
Timer(const Duration(seconds: 3), () {
_saveStatusTimer?.cancel();
_saveStatusTimer = Timer(const Duration(seconds: 3), () {
if (mounted && _saveStatus == 'saved') setState(() => _saveStatus = '');
});
}
@@ -875,7 +878,7 @@ class _NoteFormPageState extends State<NoteFormPage> {
builder: (context) => GestureDetector(
onTap: () => Navigator.pop(context),
child: Container(
color: Colors.black.withOpacity(0.9),
color: Colors.black.withValues(alpha: 0.9),
child: Center(
child: InteractiveViewer(
panEnabled: true,

View File

@@ -95,7 +95,7 @@ class _NoteSharePageState extends State<NoteSharePage> {
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
color: Colors.black.withValues(alpha: 0.1),
blurRadius: 20,
offset: const Offset(0, 10),
),

View File

@@ -24,8 +24,10 @@ class NotePlusDetailPage extends StatelessWidget {
builder: (context, provider, _) {
final doc = provider.currentDocument;
if (doc == null || doc.id != documentId) {
// 加载文档
provider.loadDocumentById(documentId);
// 加载文档(延迟到 build 完成后执行,避免副作用)
WidgetsBinding.instance.addPostFrameCallback((_) {
provider.loadDocumentById(documentId);
});
return Scaffold(
backgroundColor: colors.surface,
body: const Center(child: CircularProgressIndicator()),

View File

@@ -1660,7 +1660,7 @@ class _SettingsPageState extends State<SettingsPage> {
value: value,
onChanged: onChanged,
activeColor: colors.primary,
activeTrackColor: colors.primary.withOpacity(0.3),
activeTrackColor: colors.primary.withValues(alpha: 0.3),
inactiveThumbColor: colors.surface,
inactiveTrackColor: colors.outline),
],
@@ -2110,7 +2110,7 @@ class _MainContentSettingsPageState extends State<MainContentSettingsPage> {
value: value,
onChanged: onChanged,
activeColor: colors.primary,
activeTrackColor: colors.primary.withOpacity(0.3),
activeTrackColor: colors.primary.withValues(alpha: 0.3),
inactiveThumbColor: colors.surface,
inactiveTrackColor: colors.outline),
);