Blame view

lib/pages/video/zone/video_zone_item.dart 1.28 KB
383462ef   吴启风   feat: 新增视频专区列表与播放功能
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  class VideoZoneItem {
    const VideoZoneItem({
      required this.id,
      required this.name,
      required this.coverUrl,
      required this.videoUrl,
      required this.accessible,
      required this.completed,
      required this.durationSeconds,
      required this.progressSeconds,
      required this.lastPlayTime,
    });
  
    factory VideoZoneItem.fromJson(Map<String, dynamic> json) {
      int toInt(dynamic value) =>
          value is num ? value.toInt() : int.tryParse('$value') ?? 0;
      bool toBool(dynamic value) =>
          value == true || value == 1 || value?.toString() == 'true';
  
      return VideoZoneItem(
        id: toInt(json['id']),
        name: json['name']?.toString() ?? '',
        coverUrl: json['coverUrl']?.toString() ?? '',
        videoUrl: json['videoUrl']?.toString() ?? '',
        accessible: toBool(json['accessible']),
        completed: toBool(json['completed']),
        durationSeconds: toInt(json['durationSeconds']),
        progressSeconds: toInt(json['progressSeconds']),
        lastPlayTime: json['lastPlayTime']?.toString() ?? '',
      );
    }
  
    final int id;
    final String name;
    final String coverUrl;
    final String videoUrl;
    final bool accessible;
    final bool completed;
    final int durationSeconds;
    final int progressSeconds;
    final String lastPlayTime;
  
    String get title => name;
  }