|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:new_fl/models/video_model.dart'; |
| 3 | +import 'package:new_fl/util/format_util.dart'; |
| 4 | + |
| 5 | +class VideoCard extends StatelessWidget { |
| 6 | + const VideoCard({Key? key, required this.model}) : super(key: key); |
| 7 | + |
| 8 | + final VideoModel model; |
| 9 | + |
| 10 | + @override |
| 11 | + Widget build(BuildContext context) { |
| 12 | + return InkWell( |
| 13 | + onTap: () { |
| 14 | + print(' tap video ${model.shortLink}'); |
| 15 | + }, |
| 16 | + child: SizedBox( |
| 17 | + height: 300, |
| 18 | + child: Card( |
| 19 | + margin: EdgeInsets.only(left: 4, right: 4, bottom: 8), |
| 20 | + child: ClipRRect( |
| 21 | + borderRadius: BorderRadius.circular(5), |
| 22 | + child: Column( |
| 23 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 24 | + children: [_itemImage(), Flexible(child: _infoTxt())], |
| 25 | + ), |
| 26 | + )), |
| 27 | + ), |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + Widget _itemImage() { |
| 32 | + return Stack( |
| 33 | + children: [ |
| 34 | + Image.network( |
| 35 | + model.pic, |
| 36 | + height: 120, |
| 37 | + ), |
| 38 | + Positioned( |
| 39 | + left: 0, |
| 40 | + right: 0, |
| 41 | + bottom: 0, |
| 42 | + child: Container( |
| 43 | + padding: EdgeInsets.only(left: 8, right: 8, bottom: 3, top: 5), |
| 44 | + decoration: BoxDecoration( |
| 45 | + gradient: LinearGradient( |
| 46 | + colors: [Colors.black54, Colors.transparent], |
| 47 | + begin: Alignment.bottomCenter, |
| 48 | + end: Alignment.topCenter)), |
| 49 | + child: Row( |
| 50 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 51 | + children: [ |
| 52 | + _iconTxt(Icons.ondemand_video, model.stat?.view ?? 0), |
| 53 | + _iconTxt(Icons.favorite_border, model.stat?.favorite ?? 0), |
| 54 | + _iconTxt(null, model.duration), |
| 55 | + ], |
| 56 | + ), |
| 57 | + ), |
| 58 | + ) |
| 59 | + ], |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + Widget _iconTxt(IconData? iconData, int count) { |
| 64 | + var str = ''; |
| 65 | + if (iconData != null) { |
| 66 | + str = countFormat(count); |
| 67 | + } else { |
| 68 | + str = time2String(model.duration); |
| 69 | + } |
| 70 | + return Row( |
| 71 | + children: [ |
| 72 | + if (iconData != null) |
| 73 | + Icon( |
| 74 | + iconData, |
| 75 | + color: Colors.white, |
| 76 | + size: 12, |
| 77 | + ), |
| 78 | + Padding( |
| 79 | + padding: EdgeInsets.only(left: 3), |
| 80 | + child: Text(str, |
| 81 | + style: TextStyle(color: Colors.white, fontSize: 10), |
| 82 | + overflow: TextOverflow.ellipsis), |
| 83 | + ) |
| 84 | + ], |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + Widget _infoTxt() { |
| 89 | + return Expanded( |
| 90 | + child: Container( |
| 91 | + padding: EdgeInsets.only(top: 5, left: 8, right: 8, bottom: 5), |
| 92 | + child: Column( |
| 93 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 94 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 95 | + children: [ |
| 96 | + Text( |
| 97 | + model.title, |
| 98 | + maxLines: 2, |
| 99 | + overflow: TextOverflow.ellipsis, |
| 100 | + style: TextStyle(fontSize: 12, color: Colors.black87), |
| 101 | + ), |
| 102 | + // _owner() |
| 103 | + ], |
| 104 | + ), |
| 105 | + )); |
| 106 | + } |
| 107 | + |
| 108 | + Widget _owner() { |
| 109 | + var owner = model.owner; |
| 110 | + return Row( |
| 111 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 112 | + children: [ |
| 113 | + Row( |
| 114 | + children: [ |
| 115 | + ClipOval( |
| 116 | + child: Image.network( |
| 117 | + model.owner?.face ?? '', |
| 118 | + height: 24, |
| 119 | + width: 24, |
| 120 | + ), |
| 121 | + ), |
| 122 | + Padding( |
| 123 | + padding: EdgeInsets.only(left: 8), |
| 124 | + child: Text(model.owner?.name ?? '', |
| 125 | + style: TextStyle(fontSize: 11, color: Colors.black87)), |
| 126 | + ) |
| 127 | + ], |
| 128 | + ), |
| 129 | + Icon(Icons.more_vert_sharp, size: 15, color: Colors.grey) |
| 130 | + ], |
| 131 | + ); |
| 132 | + } |
| 133 | +} |
0 commit comments