Skip to content

Commit 3e2a165

Browse files
committed
修复跳页错误,现在点击取消不会出错了,且如果跳转的页面是现在显示的页面,则不会再次跳转。
修复部分漫画因为结果缺少键值而导致的报错。
1 parent 89c8039 commit 3e2a165

7 files changed

+135
-63
lines changed

lib/page/mainPage/search/page/comic_info_page.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ class _ComicInfoPageState extends State<ComicInfoPage>
116116
if (snapshot.data!['comic']['_creator']['slogan'] == null) {
117117
snapshot.data!['comic']['_creator']['slogan'] = "";
118118
}
119+
// title,这里做个判断,防止报错
120+
if (snapshot.data!['comic']['_creator']['title'] == null) {
121+
snapshot.data!['comic']['_creator']['title'] = '';
122+
}
119123
// 部分上传者没有verified,这里做个判断,防止报错
120124
if (snapshot.data!['comic']['_creator']['verified'] == null) {
121125
snapshot.data!['comic']['_creator']['verified'] = false;
@@ -129,7 +133,15 @@ class _ComicInfoPageState extends State<ComicInfoPage>
129133
snapshot.data!['comic']['totalComments'] =
130134
snapshot.data!['comic']['commentsCount'] = 0;
131135
}
132-
comicInfo = ComicInfo.fromJson(snapshot.data!);
136+
// 部分漫画没有totalComments,这里做个判断,防止报错
137+
if (snapshot.data!['comic']['author'] == null) {
138+
snapshot.data!['comic']['author'] = '';
139+
}
140+
try {
141+
comicInfo = ComicInfo.fromJson(snapshot.data!);
142+
} catch (e) {
143+
debugPrint(e.toString());
144+
}
133145
return SingleChildScrollView(
134146
// 添加滚动视图
135147
physics: const ClampingScrollPhysics(), // 滚动物理,根据需要可以调整

lib/page/mainPage/search/page/comic_search_page.dart

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ class _ComicSearchPageState extends ConsumerState<ComicSearchPage> {
4646
final ValueNotifier<int> _totalCountNotifier = ValueNotifier<int>(0);
4747
int totalCount = 0;
4848

49+
late TextEditingController inputController;
50+
late FocusNode focusNode;
51+
late FocusScopeNode focusScopeNode;
52+
4953
// 仅作为跳页使用
5054
int pageSkip = 0;
5155

5256
@override
5357
void initState() {
58+
super.initState();
5459
_localEnter = enter;
5560
_keyword = enter.keyword;
5661
_sort = enter.sort;
@@ -95,14 +100,19 @@ class _ComicSearchPageState extends ConsumerState<ComicSearchPage> {
95100
debugPrint("Dart Map: $_shieldCategoriesMap");
96101
}
97102

98-
super.initState();
103+
inputController = TextEditingController();
104+
focusNode = FocusNode();
105+
focusScopeNode = FocusScopeNode();
99106
}
100107

101108
@override
102109
void dispose() {
103110
_controller.dispose();
104-
super.dispose();
105111
_realm.close();
112+
inputController.dispose();
113+
focusNode.dispose();
114+
focusScopeNode.dispose();
115+
super.dispose();
106116
}
107117

108118
Future<void> _showCategoryDialog(BuildContext context) {
@@ -259,44 +269,63 @@ class _ComicSearchPageState extends ConsumerState<ComicSearchPage> {
259269
}
260270

261271
Future<void> _showNumberInputDialog() async {
262-
TextEditingController inputController = TextEditingController(); // 创建控制器实例
272+
bool isDialogOpen = true;
273+
// 在显示对话框之前清空输入控制器的内容
274+
inputController.clear();
263275

264-
return showDialog(
276+
return showDialog<void>(
265277
context: context,
266-
builder: (BuildContext context) {
278+
builder: (BuildContext innerContext) {
279+
// 在AlertDialog构建时立即请求焦点
280+
FocusScope.of(innerContext).requestFocus(focusNode);
281+
267282
return AlertDialog(
268283
title: Text('输入页数'),
269284
content: TextField(
285+
focusNode: focusNode,
270286
keyboardType: TextInputType.number,
271287
inputFormatters: <TextInputFormatter>[
272288
FilteringTextInputFormatter.digitsOnly
273-
], // 只允许输入数字
289+
],
274290
decoration: InputDecoration(hintText: '请输入页数(仅支持数字)'),
275-
controller: inputController, // 将控制器与文本字段关联
291+
controller: inputController,
292+
onSubmitted: (value) {
293+
if (value.isNotEmpty) {
294+
String number = inputController.text;
295+
pageSkip = int.parse(number);
296+
debugPrint('输入的数字是: $number');
297+
}
298+
isDialogOpen = false;
299+
Navigator.of(innerContext).pop();
300+
},
276301
),
277302
actions: <Widget>[
278303
TextButton(
279304
child: Text('取消'),
280305
onPressed: () {
281-
Navigator.of(context).pop();
306+
isDialogOpen = false;
307+
pageSkip = 0;
308+
Navigator.of(innerContext).pop();
282309
},
283310
),
284311
TextButton(
285312
child: Text('确定'),
286313
onPressed: () {
287-
// 获取输入框的值
288314
String number = inputController.text;
289-
pageSkip = int.parse(number);
290-
debugPrint('输入的数字是: $number');
291-
Navigator.of(context).pop();
315+
if (number.isNotEmpty) {
316+
pageSkip = int.parse(number);
317+
debugPrint('输入的数字是: $number');
318+
}
319+
isDialogOpen = false;
320+
Navigator.of(innerContext).pop();
292321
},
293322
),
294323
],
295324
);
296325
},
297-
).then((value) {
298-
if (value != null) {
299-
debugPrint('Checkbox values: $value');
326+
).then((_) {
327+
if (isDialogOpen) {
328+
focusNode.dispose();
300329
}
301330
});
302331
}
@@ -580,16 +609,18 @@ class _ComicSearchPageState extends ConsumerState<ComicSearchPage> {
580609
floatingActionButton: FloatingActionButton.extended(
581610
onPressed: () {
582611
_showNumberInputDialog().then((_) {
583-
setState(
584-
() {
585-
_localEnter = SearchEnter(
586-
keyword: _keyword,
587-
sort: _sort,
588-
pageCount: pageSkip,
589-
categories: _categories,
590-
);
591-
},
592-
);
612+
if (_pageCount != pageSkip && pageSkip != 0) {
613+
setState(
614+
() {
615+
_localEnter = SearchEnter(
616+
keyword: _keyword,
617+
sort: _sort,
618+
pageCount: pageSkip,
619+
categories: _categories,
620+
);
621+
},
622+
);
623+
}
593624
});
594625
},
595626
label: Text('跳页'),

lib/page/mainPage/search/widget/comic_entry_widget.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ class _ComicEntryWidgetState extends ConsumerState<ComicEntryWidget> {
2727
Doc get doc => widget.doc;
2828

2929
String _getCategories(List<String>? categories) {
30+
int count = 0;
31+
int mainCount = 8;
3032
if (categories == null) {
3133
return "";
3234
} else {
3335
String temp = "";
3436
for (var category in categories) {
3537
temp += "$category ";
38+
count++;
39+
if (count == mainCount) {
40+
break;
41+
}
3642
}
3743
return "分类: $temp";
3844
}
@@ -112,15 +118,17 @@ class _ComicEntryWidgetState extends ConsumerState<ComicEntryWidget> {
112118
],
113119
),
114120
),
115-
const SizedBox(height: 5),
116-
Text(
117-
doc.author.toString(),
118-
style: TextStyle(
119-
color: colorNotifier.themeType
120-
? Colors.red
121-
: Colors.yellow,
121+
if (doc.author.toString() != '') ...[
122+
const SizedBox(height: 5),
123+
Text(
124+
_getLimitedTitle(doc.author.toString(), 40),
125+
style: TextStyle(
126+
color: colorNotifier.themeType
127+
? Colors.red
128+
: Colors.yellow,
129+
),
122130
),
123-
),
131+
],
124132
const SizedBox(height: 5),
125133
Text(
126134
_getCategories(doc.categories),

lib/page/mainPage/search/widget/comic_info/comic_particulars_widget.dart

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,37 +68,41 @@ class _ComicParticularsWidgetState extends ConsumerState<ComicParticularsWidget>
6868
fontSize: 18,
6969
),
7070
),
71-
const SizedBox(height: 2),
72-
InkWell(
73-
onTap: () {
74-
// 点击时触发的事件
75-
var enter = SearchEnter();
76-
enter.keyword = comicInfo.comic.author;
77-
navigateTo(context, '/search', extra: enter);
78-
},
79-
onLongPress: () {
80-
// 长按时触发的事件
81-
Clipboard.setData(
82-
ClipboardData(text: comicInfo.comic.author));
83-
CherryToast.success(
84-
description: Text(
85-
"已将${comicInfo.comic.author}复制到剪贴板",
86-
style: TextStyle(color: colorNotifier.defaultTextColor),
71+
if (comicInfo.comic.author != '') ...[
72+
const SizedBox(height: 2),
73+
InkWell(
74+
onTap: () {
75+
// 点击时触发的事件
76+
var enter = SearchEnter();
77+
enter.keyword = comicInfo.comic.author;
78+
navigateTo(context, '/search', extra: enter);
79+
},
80+
onLongPress: () {
81+
// 长按时触发的事件
82+
Clipboard.setData(
83+
ClipboardData(text: comicInfo.comic.author));
84+
CherryToast.success(
85+
description: Text(
86+
"已将${comicInfo.comic.author}复制到剪贴板",
87+
style:
88+
TextStyle(color: colorNotifier.defaultTextColor),
89+
),
90+
animationType: AnimationType.fromTop,
91+
toastDuration: const Duration(seconds: 2),
92+
autoDismiss: true,
93+
backgroundColor: colorNotifier.defaultBackgroundColor,
94+
).show(context);
95+
},
96+
child: Text(
97+
'作者:${comicInfo.comic.author}',
98+
style: TextStyle(
99+
color: colorNotifier.themeType
100+
? Colors.red
101+
: Colors.yellow,
87102
),
88-
animationType: AnimationType.fromTop,
89-
toastDuration: const Duration(seconds: 2),
90-
autoDismiss: true,
91-
backgroundColor: colorNotifier.defaultBackgroundColor,
92-
).show(context);
93-
},
94-
child: Text(
95-
'作者:${comicInfo.comic.author}',
96-
style: TextStyle(
97-
color:
98-
colorNotifier.themeType ? Colors.red : Colors.yellow,
99103
),
100104
),
101-
),
105+
],
102106
const SizedBox(height: 2),
103107
if (comicInfo.comic.chineseTeam != "") ...[
104108
InkWell(

lib/page/mainPage/search/widget/comic_info/creator_info_widget.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,17 @@ class _ImagerWidgetState extends ConsumerState<ImagerWidget> {
161161
if (snapshot.connectionState == ConnectionState.done) {
162162
if (snapshot.hasError) {
163163
if (snapshot.error.toString().contains('404')) {
164-
return Image.asset('asset/image/error_image/404.png');
164+
return ClipRRect(
165+
borderRadius: BorderRadius.circular(25),
166+
child: SizedBox(
167+
width: 50,
168+
height: 50,
169+
child: Image.asset(
170+
'asset/image/error_image/404.png',
171+
fit: BoxFit.cover,
172+
),
173+
),
174+
);
165175
} else {
166176
// 如果有错误,显示错误信息和一个重新加载的按钮
167177
return InkWell(

lib/page/mainPage/search/widget/comic_info/tags_categories_widget.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,9 @@ String processText(String text) {
132132
text = text.replaceAll('\r', '');
133133
}
134134

135+
if (text.contains(' ')) {
136+
text = text.replaceAll(' ', '');
137+
}
138+
135139
return text;
136140
}

lib/page/mainPage/search/widget/comic_list_widget.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ class _ComicListWidgetState extends State<ComicListWidget> {
187187
if (doc['chineseTeam'] == null) {
188188
doc['chineseTeam'] = "";
189189
}
190+
if (doc['author'] == null) {
191+
doc['author'] = "";
192+
}
190193
if (doc['likesCount'] is String) {
191194
doc['likesCount'] = int.parse(doc['likesCount']);
192195
}

0 commit comments

Comments
 (0)