説明なし

badge_delegate.dart 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:flutter/material.dart';
  2. import 'package:photo_manager/photo_manager.dart';
  3. abstract class BadgeDelegate {
  4. const BadgeDelegate();
  5. Widget buildBadge(BuildContext context, AssetType type, Duration duration);
  6. }
  7. class DefaultBadgeDelegate extends BadgeDelegate {
  8. final AlignmentGeometry alignment;
  9. const DefaultBadgeDelegate({
  10. this.alignment = Alignment.topLeft,
  11. });
  12. @override
  13. Widget buildBadge(BuildContext context, AssetType type, Duration duration) {
  14. if (type == AssetType.video) {
  15. return Padding(
  16. padding: const EdgeInsets.all(2.0),
  17. child: Align(
  18. alignment: alignment,
  19. child: Container(
  20. decoration: BoxDecoration(
  21. color: Theme.of(context).primaryColor,
  22. borderRadius: BorderRadius.circular(3.0),
  23. ),
  24. child: Text(
  25. "video",
  26. style: const TextStyle(
  27. fontSize: 12.0,
  28. color: Colors.white,
  29. ),
  30. ),
  31. padding: const EdgeInsets.all(4.0),
  32. ),
  33. ),
  34. );
  35. }
  36. return Container();
  37. }
  38. }
  39. class DurationBadgeDelegate extends BadgeDelegate {
  40. final AlignmentGeometry alignment;
  41. const DurationBadgeDelegate({this.alignment = Alignment.bottomRight});
  42. @override
  43. Widget buildBadge(BuildContext context, AssetType type, Duration duration) {
  44. if (type == AssetType.video) {
  45. var s = duration.inSeconds;
  46. var m = duration.inMinutes;
  47. var h = duration.inHours;
  48. String text =
  49. "$h:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}";
  50. return Padding(
  51. padding: const EdgeInsets.all(2.0),
  52. child: Align(
  53. alignment: alignment,
  54. child: Container(
  55. decoration: BoxDecoration(
  56. color: Theme.of(context).primaryColor.withOpacity(0.65),
  57. ),
  58. child: Text(
  59. text,
  60. style: const TextStyle(
  61. fontSize: 12.0,
  62. color: Colors.white,
  63. ),
  64. ),
  65. padding: const EdgeInsets.all(4.0),
  66. ),
  67. ),
  68. );
  69. }
  70. return Container();
  71. }
  72. }