album_engine.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:get/get.dart';
  4. import 'package:wechat_assets_picker/wechat_assets_picker.dart';
  5. /*
  6. * 本地图库的引擎封装,目前用的 wechat_assets_picker 插件
  7. */
  8. class AlbumEngine {
  9. /// 选择图片
  10. static Future<List<AssetEntity>?> selectImage(
  11. BuildContext context, {
  12. int maxAssets = 9,
  13. List<AssetEntity>? selected,
  14. int filterMinWidth = 100,
  15. int filterMaxWidth = 100000,
  16. int filterMinHeight = 100,
  17. int filterMaxHeight = 100000,
  18. }) async {
  19. FilterOptionGroup filterOptions = FilterOptionGroup()
  20. ..setOption(
  21. AssetType.image,
  22. FilterOption(
  23. sizeConstraint: SizeConstraint(
  24. minWidth: filterMinWidth,
  25. maxWidth: filterMaxWidth,
  26. minHeight: filterMinHeight,
  27. maxHeight: filterMaxHeight,
  28. ),
  29. ),
  30. );
  31. return AssetPicker.pickAssets(
  32. context,
  33. pickerConfig: AssetPickerConfig(
  34. requestType: RequestType.image,
  35. selectedAssets: selected,
  36. maxAssets: maxAssets,
  37. filterOptions: filterOptions,
  38. gridCount: 4,
  39. pageSize: 40,
  40. pickerTheme: ThemeData(
  41. brightness: Brightness.dark,
  42. appBarTheme: AppBarTheme(
  43. systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  44. statusBarColor: Colors.transparent,
  45. statusBarBrightness: Brightness.dark,
  46. statusBarIconBrightness: Brightness.light,
  47. ),
  48. ),
  49. ),
  50. ),
  51. );
  52. }
  53. /// 选择视频
  54. static Future<List<AssetEntity>?> selectVideo(
  55. BuildContext context, {
  56. int maxAssets = 1,
  57. List<AssetEntity>? selected,
  58. int filterMinWidth = 100,
  59. int filterMaxWidth = 100000,
  60. int filterMinHeight = 100,
  61. int filterMaxHeight = 100000,
  62. int filterMaxSeconds = 60, //默认能选择60秒以内的视频
  63. }) async {
  64. FilterOptionGroup filterOptions = FilterOptionGroup()
  65. ..setOption(
  66. AssetType.video,
  67. FilterOption(
  68. sizeConstraint: SizeConstraint(
  69. minWidth: filterMinWidth,
  70. maxWidth: filterMaxWidth,
  71. minHeight: filterMinHeight,
  72. maxHeight: filterMaxHeight,
  73. ),
  74. durationConstraint: DurationConstraint(max: Duration(seconds: filterMaxSeconds))),
  75. );
  76. return AssetPicker.pickAssets(
  77. context,
  78. pickerConfig: AssetPickerConfig(
  79. requestType: RequestType.video,
  80. selectedAssets: selected,
  81. maxAssets: maxAssets,
  82. filterOptions: filterOptions,
  83. gridCount: 4,
  84. pageSize: 40,
  85. pickerTheme: ThemeData(
  86. brightness: Brightness.dark,
  87. appBarTheme: AppBarTheme(
  88. systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  89. statusBarColor: Colors.transparent,
  90. statusBarBrightness: Brightness.dark,
  91. statusBarIconBrightness: Brightness.light,
  92. ),
  93. ),
  94. ),
  95. ),
  96. );
  97. }
  98. }