album_engine.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'package:cs_resources/theme/app_colors_theme.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.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. primaryColor: AppColorsTheme.colorPrimary,
  42. brightness: Brightness.dark,
  43. colorScheme: const ColorScheme.dark(
  44. primary: AppColorsTheme.colorPrimary,
  45. secondary: AppColorsTheme.colorPrimary, //内部按钮是这个颜色
  46. ),
  47. primarySwatch: _createMaterialColor(AppColorsTheme.colorPrimary),
  48. textSelectionTheme: const TextSelectionThemeData(cursorColor: AppColorsTheme.colorPrimary),
  49. appBarTheme: AppBarTheme(
  50. systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  51. statusBarColor: Colors.transparent,
  52. statusBarBrightness: Brightness.dark,
  53. statusBarIconBrightness: Brightness.light,
  54. ),
  55. ),
  56. ),
  57. ),
  58. );
  59. }
  60. static MaterialColor _createMaterialColor(Color color) {
  61. final strengths = <double>[.05];
  62. final swatch = <int, Color>{};
  63. for (int i = 1; i < 10; i++) {
  64. strengths.add(0.1 * i);
  65. }
  66. for (final strength in strengths) {
  67. final double ds = 0.5 - strength;
  68. swatch[(strength * 1000).round()] = Color.fromRGBO(
  69. color.red + ((ds < 0 ? color.red : (255 - color.red)) * ds).round(),
  70. color.green + ((ds < 0 ? color.green : (255 - color.green)) * ds).round(),
  71. color.blue + ((ds < 0 ? color.blue : (255 - color.blue)) * ds).round(),
  72. 1,
  73. );
  74. }
  75. return MaterialColor(color.value, swatch);
  76. }
  77. /// 选择视频
  78. // static Future<List<AssetEntity>?> selectVideo(
  79. // BuildContext context, {
  80. // int maxAssets = 1,
  81. // List<AssetEntity>? selected,
  82. // int filterMinWidth = 100,
  83. // int filterMaxWidth = 100000,
  84. // int filterMinHeight = 100,
  85. // int filterMaxHeight = 100000,
  86. // int filterMaxSeconds = 60, //默认能选择60秒以内的视频
  87. // }) async {
  88. // FilterOptionGroup filterOptions = FilterOptionGroup()
  89. // ..setOption(
  90. // AssetType.video,
  91. // FilterOption(
  92. // sizeConstraint: SizeConstraint(
  93. // minWidth: filterMinWidth,
  94. // maxWidth: filterMaxWidth,
  95. // minHeight: filterMinHeight,
  96. // maxHeight: filterMaxHeight,
  97. // ),
  98. // durationConstraint: DurationConstraint(max: Duration(seconds: filterMaxSeconds))),
  99. // );
  100. //
  101. // return AssetPicker.pickAssets(
  102. // context,
  103. // pickerConfig: AssetPickerConfig(
  104. // requestType: RequestType.video,
  105. // selectedAssets: selected,
  106. // maxAssets: maxAssets,
  107. // filterOptions: filterOptions,
  108. // gridCount: 4,
  109. // pageSize: 40,
  110. // pickerTheme: ThemeData(
  111. // brightness: Brightness.dark,
  112. // appBarTheme: AppBarTheme(
  113. // systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  114. // statusBarColor: Colors.transparent,
  115. // statusBarBrightness: Brightness.dark,
  116. // statusBarIconBrightness: Brightness.light,
  117. // ),
  118. // ),
  119. // ),
  120. // ),
  121. // );
  122. // }
  123. }