cover_image_item.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:flutter/material.dart';
  2. class CoverImageItem extends StatelessWidget {
  3. final double width;
  4. final String coverUrl;
  5. final int duration;
  6. const CoverImageItem(
  7. {Key key, this.width: 0, this.coverUrl, this.duration: -1})
  8. : super(key: key);
  9. @override
  10. Widget build(BuildContext context) {
  11. var coverImageWidget = Container(
  12. width: width == 0 ? double.infinity : width,
  13. height: (width == 0 ? MediaQuery.of(context).size.width : width) * 0.5,
  14. decoration: ShapeDecoration(
  15. image: DecorationImage(
  16. image: NetworkImage(coverUrl),
  17. fit: BoxFit.cover,
  18. ),
  19. shape: RoundedRectangleBorder(
  20. borderRadius: BorderRadius.circular(5),
  21. ),
  22. ),
  23. );
  24. if (duration >= 0) {
  25. var tvTimeLabel = Container(
  26. decoration: ShapeDecoration(
  27. color: Color(0xff333333),
  28. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(3)),
  29. ),
  30. child: Padding(
  31. padding: const EdgeInsets.only(left: 6, top: 1, right: 6, bottom: 1),
  32. child: Text(
  33. getTimeLabel(duration),
  34. style: TextStyle(
  35. fontSize: 12,
  36. fontWeight: FontWeight.bold,
  37. fontFamily: 'Oswald-Regular',
  38. color: Color(0xffffffff),
  39. ),
  40. ),
  41. ),
  42. );
  43. return Stack(
  44. alignment: AlignmentDirectional.bottomEnd,
  45. children: <Widget>[
  46. coverImageWidget,
  47. Positioned(
  48. child: tvTimeLabel,
  49. bottom: 3,
  50. right: 3,
  51. ),
  52. ],
  53. );
  54. }
  55. return coverImageWidget;
  56. }
  57. String getTimeLabel(int duration) {
  58. if (duration < 60) {
  59. return "00 : $duration";
  60. } else if (duration >= 60) {
  61. int minute = duration ~/ 60;
  62. int second = duration % 60;
  63. String minuteStr = minute < 10 ? "0$minute" : "$minute";
  64. String secondStr = second < 10 ? "0$second" : "$second";
  65. return "$minuteStr : $secondStr";
  66. }
  67. return "00 : 00";
  68. }
  69. }