diff --git a/CHANGELOG.md b/CHANGELOG.md index e7a46f43..ae757417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,26 @@ that can be found in the LICENSE file. --> See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions. -## Unchanged +## 8.9.0-dev.1 -- Bump photo_manager to 3.x version. -- Include photo_manager_image_provider. +### Breaking changes + +- Bump `photo_manager` to v3.x. +- Export `photo_manager_image_provider`. + +## 8.8.0 + +### New features + +- Add Korean language support. (#494) + +### Improvements + +- Use `viewAsset` in the preview button. + +### Fixes + +- Fix disposed provider throwing error when fetching assets. (#493) ## 8.7.1 diff --git a/README-ZH.md b/README-ZH.md index 1aaa46cc..e396fdd9 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -220,11 +220,6 @@ import 'package:wechat_assets_picker/wechat_assets_picker.dart'; 如果该行以 `#` (注释) 开头,请把 `#` 删除。 2. 将以下内容添加至 `Info.plist`。 ``` -NSAppTransportSecurity - - NSAllowsArbitraryLoads - - NSPhotoLibraryUsageDescription 你的相册权限描述 ``` diff --git a/README.md b/README.md index 1674132a..0a34d5e4 100644 --- a/README.md +++ b/README.md @@ -226,11 +226,6 @@ consider declare only relevant permission in your apps, more specifically: Remove the `#` heading if the line starts with it. 2. Add the following content to `Info.plist`. ``` -NSAppTransportSecurity - - NSAllowsArbitraryLoads - - NSPhotoLibraryUsageDescription Replace with your permission description. ``` diff --git a/example/ios/Podfile b/example/ios/Podfile index fb9d86a0..0cf927fd 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -46,8 +46,12 @@ def install_plugin_pods(application_path = nil, relative_symlink_dir, platform) plugin_pods.each do |plugin_hash| plugin_name = plugin_hash['name'] plugin_path = plugin_hash['path'] + # iOS and macOS code can be shared in "darwin" directory, otherwise + # respectively in "ios" or "macos" directories. + shared_darwin_source = plugin_hash.fetch('shared_darwin_source', false) + platform_directory = shared_darwin_source ? 'darwin' : platform if (plugin_name && plugin_path) - specPath = "#{plugin_path}/#{platform}/#{plugin_name}.podspec" + specPath = "#{plugin_path}/#{platform_directory}/#{plugin_name}.podspec" pod plugin_name, :path => specPath end end diff --git a/example/macos/Podfile b/example/macos/Podfile index 5bf4307c..9ce47397 100644 --- a/example/macos/Podfile +++ b/example/macos/Podfile @@ -9,74 +9,63 @@ project 'Runner', { 'Release' => :release, } -def parse_KV_file(file, separator='=') - file_abs_path = File.expand_path(file) - if !File.exists? file_abs_path - return []; +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" end - pods_ary = [] - skip_line_start_symbols = ["#", "/"] - File.foreach(file_abs_path) { |line| - next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } - plugin = line.split(pattern=separator) - if plugin.length == 2 - podname = plugin[0].strip() - path = plugin[1].strip() - podpath = File.expand_path("#{path}", file_abs_path) - pods_ary.push({:name => podname, :path => podpath}); - else - puts "Invalid plugin specification: #{line}" - end - } - return pods_ary -end -def pubspec_supports_macos(file) - file_abs_path = File.expand_path(file) - if !File.exists? file_abs_path - return false; + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches end - File.foreach(file_abs_path) { |line| - return true if line =~ /^\s*macos:/ - } - return false + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" end -target 'Runner' do - use_frameworks! - use_modular_headers! +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +def install_plugin_pods(application_path = nil, relative_symlink_dir, platform) + # defined_in_file is set by CocoaPods and is a Pathname to the Podfile. + application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file) + raise 'Could not find application path' unless application_path # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock # referring to absolute paths on developers' machines. - ephemeral_dir = File.join('Flutter', 'ephemeral') - symlink_dir = File.join(ephemeral_dir, '.symlinks') - symlink_plugins_dir = File.join(symlink_dir, 'plugins') - system("rm -rf #{symlink_dir}") - system("mkdir -p #{symlink_plugins_dir}") - # Flutter Pods - generated_xcconfig = parse_KV_file(File.join(ephemeral_dir, 'Flutter-Generated.xcconfig')) - if generated_xcconfig.empty? - puts "Flutter-Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first." - end - generated_xcconfig.map { |p| - if p[:name] == 'FLUTTER_FRAMEWORK_DIR' - symlink = File.join(symlink_dir, 'flutter') - File.symlink(File.dirname(p[:path]), symlink) - pod 'FlutterMacOS', :path => File.join(symlink, File.basename(p[:path])) - end - } + symlink_dir = File.expand_path(relative_symlink_dir, application_path) + system('rm', '-rf', symlink_dir) # Avoid the complication of dependencies like FileUtils. + + symlink_plugins_dir = File.expand_path('plugins', symlink_dir) + system('mkdir', '-p', symlink_plugins_dir) - # Plugin Pods - plugin_pods = parse_KV_file('../.flutter-plugins') - plugin_pods.map { |p| - symlink = File.join(symlink_plugins_dir, p[:name]) - File.symlink(p[:path], symlink) - if pubspec_supports_macos(File.join(symlink, 'pubspec.yaml')) - pod p[:name], :path => File.join(symlink, 'macos') + plugins_file = File.join(application_path, '..', '.flutter-plugins-dependencies') + plugin_pods = flutter_parse_plugins_file(plugins_file, platform) + plugin_pods.each do |plugin_hash| + plugin_name = plugin_hash['name'] + plugin_path = plugin_hash['path'] + # iOS and macOS code can be shared in "darwin" directory, otherwise + # respectively in "ios" or "macos" directories. + shared_darwin_source = plugin_hash.fetch('shared_darwin_source', false) + platform_directory = shared_darwin_source ? 'darwin' : platform + if (plugin_name && plugin_path) + specPath = "#{plugin_path}/#{platform_directory}/#{plugin_name}.podspec" + pod plugin_name, :path => specPath end - } + end end -# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system. -install! 'cocoapods', :disable_input_output_paths => true +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_macos_engine_pod(File.dirname(File.realpath(__FILE__))) + install_plugin_pods(File.dirname(File.realpath(__FILE__)), '.symlinks', 'macos') +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_macos_build_settings(target) + end +end diff --git a/example/pubspec.yaml b/example/pubspec.yaml index f96b56ec..cc0eb2b7 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: wechat_assets_picker_demo description: The demo project for the wechat_assets_picker package. -version: 8.7.1+45 +version: 8.8.0+47 publish_to: none environment: diff --git a/lib/src/delegates/asset_picker_builder_delegate.dart b/lib/src/delegates/asset_picker_builder_delegate.dart index ded43b43..66ccd85c 100644 --- a/lib/src/delegates/asset_picker_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_builder_delegate.dart @@ -876,19 +876,16 @@ class DefaultAssetPickerBuilderDelegate ) async { final DefaultAssetPickerProvider provider = context.read(); - bool selectedAllAndNotSelected() => - !provider.selectedAssets.contains(currentAsset) && - provider.selectedMaximumAssets; - bool selectedPhotosAndIsVideo() => - isWeChatMoment && - currentAsset.type == AssetType.video && - provider.selectedAssets.isNotEmpty; - // When we reached the maximum select count and the asset - // is not selected, do nothing. - // When the special type is WeChat Moment, pictures and videos cannot - // be selected at the same time. Video select should be banned if any - // pictures are selected. - if (selectedAllAndNotSelected() || selectedPhotosAndIsVideo()) { + // - When we reached the maximum select count and the asset is not selected, + // do nothing. + // - When the special type is WeChat Moment, pictures and videos cannot + // be selected at the same time. Video select should be banned if any + // pictures are selected. + if ((!provider.selectedAssets.contains(currentAsset) && + provider.selectedMaximumAssets) || + (isWeChatMoment && + currentAsset.type == AssetType.video && + provider.selectedAssets.isNotEmpty)) { return; } final List current; @@ -1925,33 +1922,6 @@ class DefaultAssetPickerBuilderDelegate @override Widget previewButton(BuildContext context) { - Future onTap() async { - final DefaultAssetPickerProvider p = - context.read(); - final List selectedAssets = p.selectedAssets; - final List selected; - if (isWeChatMoment) { - selected = selectedAssets - .where((AssetEntity e) => e.type == AssetType.image) - .toList(); - } else { - selected = selectedAssets; - } - final List? result = await AssetPickerViewer.pushToViewer( - context, - previewAssets: selected, - previewThumbnailSize: previewThumbnailSize, - selectPredicate: selectPredicate, - selectedAssets: selected, - selectorProvider: provider, - themeData: theme, - maxAssets: p.maxAssets, - ); - if (result != null) { - Navigator.of(context).maybePop(result); - } - } - return Consumer( builder: (_, DefaultAssetPickerProvider p, Widget? child) { return ValueListenableBuilder( @@ -1966,8 +1936,10 @@ class DefaultAssetPickerBuilderDelegate ); }, child: Consumer( - builder: (_, DefaultAssetPickerProvider p, __) => GestureDetector( - onTap: p.isSelectedNotEmpty ? onTap : null, + builder: (context, DefaultAssetPickerProvider p, __) => GestureDetector( + onTap: p.isSelectedNotEmpty + ? () => viewAsset(context, 0, p.selectedAssets.first) + : null, child: Selector( selector: (_, DefaultAssetPickerProvider p) => p.selectedDescriptions, diff --git a/pubspec.yaml b/pubspec.yaml index d6b507f7..49491d29 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: wechat_assets_picker -version: 8.7.1 +version: 8.8.0 description: | An image picker (also with videos and audio) for Flutter projects based on WeChat's UI,