123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import 'package:cs_resources/theme/app_colors_theme.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:wechat_assets_picker/wechat_assets_picker.dart';
- /*
- * 本地图库的引擎封装,目前用的 wechat_assets_picker 插件
- */
- class AlbumEngine {
- /// 选择图片
- static Future<List<AssetEntity>?> selectImage(
- BuildContext context, {
- int maxAssets = 9,
- List<AssetEntity>? selected,
- int filterMinWidth = 100,
- int filterMaxWidth = 100000,
- int filterMinHeight = 100,
- int filterMaxHeight = 100000,
- }) async {
- const Color themeColor = Color(0xff00bc56);
- FilterOptionGroup filterOptions = FilterOptionGroup()
- ..setOption(
- AssetType.image,
- FilterOption(
- sizeConstraint: SizeConstraint(
- minWidth: filterMinWidth,
- maxWidth: filterMaxWidth,
- minHeight: filterMinHeight,
- maxHeight: filterMaxHeight,
- ),
- ),
- );
- return AssetPicker.pickAssets(
- context,
- pickerConfig: AssetPickerConfig(
- requestType: RequestType.image,
- selectedAssets: selected,
- maxAssets: maxAssets,
- filterOptions: filterOptions,
- gridCount: 4,
- pageSize: 40,
- pickerTheme: ThemeData(
- primaryColor: themeColor,
- primaryColorDark: Colors.white,
- primaryColorLight: themeColor,
- brightness: Brightness.dark,
- primarySwatch: _createMaterialColor(themeColor),
- textSelectionTheme: const TextSelectionThemeData(cursorColor: themeColor),
- appBarTheme: AppBarTheme(
- systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
- statusBarColor: Colors.transparent,
- statusBarBrightness: Brightness.dark,
- statusBarIconBrightness: Brightness.light,
- ),
- ),
- ),
- ),
- );
- }
- static MaterialColor _createMaterialColor(Color color) {
- final strengths = <double>[.05];
- final swatch = <int, Color>{};
- for (int i = 1; i < 10; i++) {
- strengths.add(0.1 * i);
- }
- for (final strength in strengths) {
- final double ds = 0.5 - strength;
- swatch[(strength * 1000).round()] = Color.fromRGBO(
- color.red + ((ds < 0 ? color.red : (255 - color.red)) * ds).round(),
- color.green + ((ds < 0 ? color.green : (255 - color.green)) * ds).round(),
- color.blue + ((ds < 0 ? color.blue : (255 - color.blue)) * ds).round(),
- 1,
- );
- }
- return MaterialColor(color.value, swatch);
- }
- /// 选择视频
- // static Future<List<AssetEntity>?> selectVideo(
- // BuildContext context, {
- // int maxAssets = 1,
- // List<AssetEntity>? selected,
- // int filterMinWidth = 100,
- // int filterMaxWidth = 100000,
- // int filterMinHeight = 100,
- // int filterMaxHeight = 100000,
- // int filterMaxSeconds = 60, //默认能选择60秒以内的视频
- // }) async {
- // FilterOptionGroup filterOptions = FilterOptionGroup()
- // ..setOption(
- // AssetType.video,
- // FilterOption(
- // sizeConstraint: SizeConstraint(
- // minWidth: filterMinWidth,
- // maxWidth: filterMaxWidth,
- // minHeight: filterMinHeight,
- // maxHeight: filterMaxHeight,
- // ),
- // durationConstraint: DurationConstraint(max: Duration(seconds: filterMaxSeconds))),
- // );
- //
- // return AssetPicker.pickAssets(
- // context,
- // pickerConfig: AssetPickerConfig(
- // requestType: RequestType.video,
- // selectedAssets: selected,
- // maxAssets: maxAssets,
- // filterOptions: filterOptions,
- // gridCount: 4,
- // pageSize: 40,
- // pickerTheme: ThemeData(
- // brightness: Brightness.dark,
- // appBarTheme: AppBarTheme(
- // systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
- // statusBarColor: Colors.transparent,
- // statusBarBrightness: Brightness.dark,
- // statusBarIconBrightness: Brightness.light,
- // ),
- // ),
- // ),
- // ),
- // );
- // }
- }
|