Skip to content

Commit 0f78301

Browse files
committed
修复选集状态显示不对 #30
1 parent de22746 commit 0f78301

File tree

3 files changed

+79
-78
lines changed

3 files changed

+79
-78
lines changed

CHANGELOG.MD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。
44

5+
# 17.1.4
6+
7+
- 修复选集状态显示不对 #30
8+
9+
510
# 17.1.3
611

712
- 修复重复跳转的问题

lib/subject/subject.dart

Lines changed: 73 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class _SubjectState extends State<SubjectPage> {
3838
late String _apiBaseUrl;
3939
late Subject _subject;
4040
late List<Episode> _episodes = [];
41-
late final Map<int, List<EpisodeResource>> _episodeResourcesMap = {};
4241
late SubjectCollection? _subjectCollection;
4342
late CollectionType _collectionType;
4443

@@ -268,24 +267,16 @@ class _SubjectState extends State<SubjectPage> {
268267
mainAxisAlignment: MainAxisAlignment.end,
269268
children: [
270269
ElevatedButton(
271-
onPressed: _episodeResourcesMap.isNotEmpty
272-
? () async {
273-
bool? cancel = await showEpisodesDialog();
274-
// ignore: unnecessary_null_comparison
275-
if (cancel == null) {
276-
print("返回");
277-
} else {
278-
print("确认");
279-
}
280-
}
281-
: null,
282-
child: _episodeResourcesMap.isEmpty
283-
? const SizedBox(
284-
width: 20, // 控制宽度
285-
height: 20, // 控制高度
286-
child: CircularProgressIndicator(),
287-
)
288-
: const Text("选集"),
270+
onPressed: () async {
271+
bool? cancel = await showEpisodesDialog();
272+
// ignore: unnecessary_null_comparison
273+
if (cancel == null) {
274+
print("返回");
275+
} else {
276+
print("确认");
277+
}
278+
},
279+
child: const Text("选集"),
289280
),
290281
const SizedBox(width: 2),
291282
_buildCollectOperateWidget(),
@@ -416,51 +407,73 @@ class _SubjectState extends State<SubjectPage> {
416407
return episodes;
417408
}
418409

410+
Widget _buildEpisodeButtonWidget(Episode ep) {
411+
return FutureBuilder(
412+
future: EpisodeApi().getEpisodeResourcesRefs(ep.id),
413+
builder: (BuildContext context,
414+
AsyncSnapshot<List<EpisodeResource>> snapshot) {
415+
if (snapshot.connectionState == ConnectionState.done) {
416+
if (snapshot.hasError) {
417+
return Text(
418+
"Load EpisodeApi getEpisodeResourcesRefs error: ${snapshot.error}");
419+
} else {
420+
List<EpisodeResource> epResList = snapshot.data ?? List.empty();
421+
return GestureDetector(
422+
onLongPress: () async {
423+
bool isFinish = _episodeIsFinish(ep.id);
424+
await EpisodeCollectionApi()
425+
.updateCollectionFinish(ep.id, !isFinish);
426+
Toast.show(context, "更新剧集收藏状态为: ${isFinish ? "未看" : "看完"}");
427+
Navigator.pop(context);
428+
Navigator.pushReplacement(
429+
context,
430+
MaterialPageRoute(
431+
builder: (context) =>
432+
SubjectPage(id: widget.id.toString())),
433+
);
434+
},
435+
child: ElevatedButton(
436+
style: ElevatedButton.styleFrom(
437+
backgroundColor: _episodeIsFinish(ep.id)
438+
? Colors.green
439+
: Colors.lightBlueAccent,
440+
disabledBackgroundColor: Colors.grey[400],
441+
disabledForegroundColor: Colors.grey[600],
442+
),
443+
onPressed: epResList.isEmpty
444+
? null
445+
: () {
446+
Toast.show(context, "已自动加载第一个附件,剧集加载比较耗时,请耐心等待");
447+
Navigator.of(context).push(MaterialPageRoute(
448+
builder: (context) => SubjectEpisodePage(
449+
episode: ep,
450+
subject: _subject,
451+
)));
452+
},
453+
child: Text(
454+
"${ep.sequence} : ${ep.name}",
455+
overflow: TextOverflow.ellipsis,
456+
),
457+
),
458+
);
459+
}
460+
} else {
461+
return const Center(
462+
child: SizedBox(
463+
width: 20, // 控制宽度
464+
height: 20, // 控制高度
465+
child: CircularProgressIndicator(),
466+
),
467+
);
468+
}
469+
});
470+
}
471+
419472
Widget _getEpisodesTabViewByGroup(String group) {
420473
var buttons = _getEpisodesByGroup(group)
421474
?.map((ep) => Container(
422475
margin: const EdgeInsets.fromLTRB(0, 2, 0, 2),
423-
child: SizedBox(
424-
height: 40,
425-
child: GestureDetector(
426-
onLongPress: () async {
427-
bool isFinish = _episodeIsFinish(ep.id);
428-
await EpisodeCollectionApi()
429-
.updateCollectionFinish(ep.id, !isFinish);
430-
Toast.show(
431-
context, "更新剧集收藏状态为: ${isFinish ? "未看" : "看完"}");
432-
Navigator.pop(context);
433-
Navigator.pushReplacement(
434-
context,
435-
MaterialPageRoute(
436-
builder: (context) =>
437-
SubjectPage(id: widget.id.toString())),
438-
);
439-
},
440-
child: ElevatedButton(
441-
style: ElevatedButton.styleFrom(
442-
backgroundColor: _episodeIsFinish(ep.id)
443-
? Colors.green
444-
: Colors.lightBlueAccent,
445-
disabledBackgroundColor: Colors.grey[400],
446-
disabledForegroundColor: Colors.grey[600],
447-
),
448-
onPressed: _episodeHasResource(ep)
449-
? null
450-
: () {
451-
Toast.show(context, "已自动加载第一个附件,剧集加载比较耗时,请耐心等待");
452-
Navigator.of(context).push(MaterialPageRoute(
453-
builder: (context) => SubjectEpisodePage(
454-
episode: ep,
455-
subject: _subject,
456-
)));
457-
},
458-
child: Text(
459-
"${ep.sequence} : ${ep.name}",
460-
overflow: TextOverflow.ellipsis,
461-
),
462-
),
463-
)),
476+
child: SizedBox(height: 40, child: _buildEpisodeButtonWidget(ep)),
464477
))
465478
.toList();
466479

@@ -471,13 +484,6 @@ class _SubjectState extends State<SubjectPage> {
471484
);
472485
}
473486

474-
bool _episodeHasResource(Episode e) {
475-
if (_episodeResourcesMap.isEmpty) return false;
476-
if (!_episodeResourcesMap.containsKey(e.id)) return false;
477-
List<EpisodeResource> resList = _episodeResourcesMap[e.id] ?? List.empty();
478-
return resList.isEmpty;
479-
}
480-
481487
TabBarView _buildEpisodeSelectTabView() {
482488
var groups = _getEpisodeGroupEnums();
483489
var tabViews =
@@ -499,19 +505,9 @@ class _SubjectState extends State<SubjectPage> {
499505
print("获取条目剧集失败");
500506
}
501507

502-
await _fetchEpisodeResourcesMap();
503-
504508
setState(() {});
505509
}
506510

507-
Future<void> _fetchEpisodeResourcesMap() async {
508-
for (Episode e in _episodes) {
509-
var id = e.id;
510-
List<EpisodeResource> epResList =
511-
await EpisodeApi().getEpisodeResourcesRefs(id);
512-
_episodeResourcesMap.putIfAbsent(e.id, () => epResList);
513-
}
514-
}
515511

516512
Future<void> _fetchSubjectCollection() async {
517513
_subjectCollection = await SubjectCollectionApi()

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: ikaros
22
description: ikaros app by flutter
3-
version: 17.1.3
3+
version: 17.1.4
44

55
environment:
66
sdk: '>=2.18.4 <=3.10.5'

0 commit comments

Comments
 (0)