@@ -38,7 +38,6 @@ class _SubjectState extends State<SubjectPage> {
38
38
late String _apiBaseUrl;
39
39
late Subject _subject;
40
40
late List <Episode > _episodes = [];
41
- late final Map <int , List <EpisodeResource >> _episodeResourcesMap = {};
42
41
late SubjectCollection ? _subjectCollection;
43
42
late CollectionType _collectionType;
44
43
@@ -268,24 +267,16 @@ class _SubjectState extends State<SubjectPage> {
268
267
mainAxisAlignment: MainAxisAlignment .end,
269
268
children: [
270
269
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 ("选集" ),
289
280
),
290
281
const SizedBox (width: 2 ),
291
282
_buildCollectOperateWidget (),
@@ -416,51 +407,73 @@ class _SubjectState extends State<SubjectPage> {
416
407
return episodes;
417
408
}
418
409
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
+
419
472
Widget _getEpisodesTabViewByGroup (String group) {
420
473
var buttons = _getEpisodesByGroup (group)
421
474
? .map ((ep) => Container (
422
475
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)),
464
477
))
465
478
.toList ();
466
479
@@ -471,13 +484,6 @@ class _SubjectState extends State<SubjectPage> {
471
484
);
472
485
}
473
486
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
-
481
487
TabBarView _buildEpisodeSelectTabView () {
482
488
var groups = _getEpisodeGroupEnums ();
483
489
var tabViews =
@@ -499,19 +505,9 @@ class _SubjectState extends State<SubjectPage> {
499
505
print ("获取条目剧集失败" );
500
506
}
501
507
502
- await _fetchEpisodeResourcesMap ();
503
-
504
508
setState (() {});
505
509
}
506
510
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
- }
515
511
516
512
Future <void > _fetchSubjectCollection () async {
517
513
_subjectCollection = await SubjectCollectionApi ()
0 commit comments