album_engine.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. const Color themeColor = Color(0xff00bc56);
  20. FilterOptionGroup filterOptions = FilterOptionGroup()
  21. ..setOption(
  22. AssetType.image,
  23. FilterOption(
  24. sizeConstraint: SizeConstraint(
  25. minWidth: filterMinWidth,
  26. maxWidth: filterMaxWidth,
  27. minHeight: filterMinHeight,
  28. maxHeight: filterMaxHeight,
  29. ),
  30. ),
  31. );
  32. return AssetPicker.pickAssets(
  33. context,
  34. pickerConfig: AssetPickerConfig(
  35. requestType: RequestType.image,
  36. selectedAssets: selected,
  37. maxAssets: maxAssets,
  38. filterOptions: filterOptions,
  39. gridCount: 4,
  40. pageSize: 40,
  41. pickerTheme: ThemeData(
  42. primaryColor: themeColor,
  43. primaryColorDark: Colors.white,
  44. primaryColorLight: themeColor,
  45. brightness: Brightness.dark,
  46. primarySwatch: _createMaterialColor(themeColor),
  47. textSelectionTheme: const TextSelectionThemeData(cursorColor: themeColor),
  48. appBarTheme: AppBarTheme(
  49. systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  50. statusBarColor: Colors.transparent,
  51. statusBarBrightness: Brightness.dark,
  52. statusBarIconBrightness: Brightness.light,
  53. ),
  54. ),
  55. ),
  56. ),
  57. );
  58. }
  59. static MaterialColor _createMaterialColor(Color color) {
  60. final strengths = <double>[.05];
  61. final swatch = <int, Color>{};
  62. for (int i = 1; i < 10; i++) {
  63. strengths.add(0.1 * i);
  64. }
  65. for (final strength in strengths) {
  66. final double ds = 0.5 - strength;
  67. swatch[(strength * 1000).round()] = Color.fromRGBO(
  68. color.red + ((ds < 0 ? color.red : (255 - color.red)) * ds).round(),
  69. color.green + ((ds < 0 ? color.green : (255 - color.green)) * ds).round(),
  70. color.blue + ((ds < 0 ? color.blue : (255 - color.blue)) * ds).round(),
  71. 1,
  72. );
  73. }
  74. return MaterialColor(color.value, swatch);
  75. }
  76. /// 选择视频
  77. // static Future<List<AssetEntity>?> selectVideo(
  78. // BuildContext context, {
  79. // int maxAssets = 1,
  80. // List<AssetEntity>? selected,
  81. // int filterMinWidth = 100,
  82. // int filterMaxWidth = 100000,
  83. // int filterMinHeight = 100,
  84. // int filterMaxHeight = 100000,
  85. // int filterMaxSeconds = 60, //默认能选择60秒以内的视频
  86. // }) async {
  87. // FilterOptionGroup filterOptions = FilterOptionGroup()
  88. // ..setOption(
  89. // AssetType.video,
  90. // FilterOption(
  91. // sizeConstraint: SizeConstraint(
  92. // minWidth: filterMinWidth,
  93. // maxWidth: filterMaxWidth,
  94. // minHeight: filterMinHeight,
  95. // maxHeight: filterMaxHeight,
  96. // ),
  97. // durationConstraint: DurationConstraint(max: Duration(seconds: filterMaxSeconds))),
  98. // );
  99. //
  100. // return AssetPicker.pickAssets(
  101. // context,
  102. // pickerConfig: AssetPickerConfig(
  103. // requestType: RequestType.video,
  104. // selectedAssets: selected,
  105. // maxAssets: maxAssets,
  106. // filterOptions: filterOptions,
  107. // gridCount: 4,
  108. // pageSize: 40,
  109. // pickerTheme: ThemeData(
  110. // brightness: Brightness.dark,
  111. // appBarTheme: AppBarTheme(
  112. // systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  113. // statusBarColor: Colors.transparent,
  114. // statusBarBrightness: Brightness.dark,
  115. // statusBarIconBrightness: Brightness.light,
  116. // ),
  117. // ),
  118. // ),
  119. // ),
  120. // );
  121. // }
  122. }