Skip to content

Commit 222eaad

Browse files
committed
🐛 修复标题更新失败,优化标题更新逻辑
1 parent c462c48 commit 222eaad

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

Diff for: lib/database/app/app_bmf.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ class BtsAppBmf {
9191
// 因为这边有个自增ID, 所以不能直接 toJson及调用insert
9292
if (result.isEmpty) {
9393
await _instance.sqlite.db.rawInsert(
94-
'INSERT INTO $_tableName (subject, rss, download) VALUES (?, ?, ?)',
95-
[model.subject, model.rss, model.download]);
94+
'INSERT INTO $_tableName (subject, rss, download,title) '
95+
'VALUES (?, ?, ?, ?)',
96+
[model.subject, model.rss, model.download, model.title]);
9697
} else {
9798
await _instance.sqlite.db.rawUpdate(
98-
'UPDATE $_tableName SET rss = ?, download = ? WHERE subject = ?',
99-
[model.rss, model.download, model.subject],
99+
'UPDATE $_tableName SET rss = ?, download = ?, title = ? '
100+
'WHERE subject = ?',
101+
[model.rss, model.download, model.title, model.subject],
100102
);
101103
}
102104
BTLogTool.info('Write $_tableName subject: ${model.subject}');

Diff for: lib/widgets/bangumi/subject_detail/bsd_bmf.dart

+24-17
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,26 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
125125
/// 标题检测
126126
Future<void> titleCheck() async {
127127
if (bmf.title != null && bmf.title!.isNotEmpty) return;
128-
var confirm = await showConfirm(
129-
context,
130-
title: '尝试获取标题?',
131-
content: '检测到标题为空',
132-
);
133-
if (!confirm) return;
128+
if (bmf.id != -1) {
129+
var confirm = await showConfirm(
130+
context,
131+
title: '尝试获取标题?',
132+
content: '检测到标题为空',
133+
);
134+
if (!confirm) return;
135+
}
134136
var title = await getTitle();
135137
if (title != null) bmf.title = title;
136138
setState(() {});
137139
await sqliteBmf.write(bmf);
138-
if (mounted) {
140+
if (mounted && bmf.id != -1) {
139141
await BtInfobar.success(context, '[${bmf.subject}]已设置标题:${bmf.title}');
140142
}
141143
}
142144

143145
/// 更新标题
144146
Future<void> updateTitle() async {
145-
var hasTitle = bmf.title != null && bmf.rss!.isNotEmpty;
147+
var hasTitle = bmf.title != null && bmf.title!.isNotEmpty;
146148
var title = bmf.title;
147149
if (!hasTitle) title = await getTitle();
148150
title ??= "";
@@ -157,6 +159,12 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
157159
setState(() {
158160
bmf.title = title;
159161
});
162+
await sqliteBmf.write(bmf);
163+
var read = await sqliteBmf.read(bmf.subject);
164+
if (read != null) {
165+
bmf = read;
166+
setState(() {});
167+
}
160168
if (mounted) {
161169
await BtInfobar.success(
162170
context,
@@ -221,7 +229,7 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
221229

222230
/// buildHeaderActTitle
223231
Widget buildHeaderActTitle(BuildContext context) {
224-
var hasTitle = bmf.title != null && bmf.rss!.isNotEmpty;
232+
var hasTitle = bmf.title != null && bmf.title!.isNotEmpty;
225233
return Tooltip(
226234
message: hasTitle ? '修改标题' : '设置标题',
227235
child: IconButton(
@@ -281,8 +289,10 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
281289
Widget buildHeaderAction(BuildContext context) {
282290
return Row(
283291
children: [
284-
buildHeaderActTitle(context),
285-
SizedBox(width: 12.w),
292+
if (bmf.id != -1) ...[
293+
buildHeaderActTitle(context),
294+
SizedBox(width: 12.w)
295+
],
286296
buildHeaderActRss(context),
287297
SizedBox(width: 12.w),
288298
buildHeaderActFile(context),
@@ -314,16 +324,13 @@ class _BsdBmfWidgetState extends State<BsdBmfWidget>
314324
trailing: buildHeaderAction(context),
315325
);
316326
}
327+
var title = '${bmf.title ?? ''}(${bmf.subject})';
328+
if (!widget.isConfig) title = 'BMF Config - $title';
317329
return Padding(
318330
padding: EdgeInsets.only(right: 12.w),
319331
child: Expander(
320332
leading: BsdBmfLeading(widget.isConfig, bmf),
321-
header: widget.isConfig
322-
? Text(
323-
'${bmf.title ?? ''}(${bmf.subject})',
324-
style: TextStyle(fontSize: 24.sp),
325-
)
326-
: Text('BMF Config', style: TextStyle(fontSize: 24.sp)),
333+
header: Text(title, style: TextStyle(fontSize: 24.sp)),
327334
content: Column(
328335
crossAxisAlignment: CrossAxisAlignment.start,
329336
mainAxisAlignment: MainAxisAlignment.start,

0 commit comments

Comments
 (0)