album_engine.dart 3.0 KB

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