From 9a8c4c14747ff4c3e1ed40b34f4ed9a9ed590644 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Fri, 2 Feb 2024 18:06:19 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Use=20`wechat=5Fpicker=5Flibrary`?= =?UTF-8?q?=20(#543)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/runnable.yml | 1 - CHANGELOG.md | 6 + lib/src/constants/constants.dart | 4 - lib/src/constants/extensions.dart | 40 ------ lib/src/constants/typedefs.dart | 4 + .../asset_picker_builder_delegate.dart | 8 +- lib/src/delegates/asset_picker_delegate.dart | 1 + .../asset_picker_viewer_builder_delegate.dart | 6 +- .../{internal => internals}/singleton.dart | 0 lib/src/provider/asset_picker_provider.dart | 2 +- lib/src/widget/asset_picker_app_bar.dart | 3 +- .../asset_entity_grid_item_builder.dart | 4 +- .../widget/builder/audio_page_builder.dart | 5 +- .../widget/builder/image_page_builder.dart | 2 +- .../builder/locally_available_builder.dart | 135 ------------------ .../builder/value_listenable_builder_2.dart | 34 ----- .../widget/builder/video_page_builder.dart | 5 +- lib/src/widget/gaps.dart | 71 --------- .../widget/platform_progress_indicator.dart | 52 ------- lib/src/widget/scale_text.dart | 58 -------- pubspec.yaml | 4 +- 21 files changed, 27 insertions(+), 418 deletions(-) delete mode 100644 lib/src/constants/extensions.dart rename lib/src/{internal => internals}/singleton.dart (100%) delete mode 100644 lib/src/widget/builder/locally_available_builder.dart delete mode 100644 lib/src/widget/builder/value_listenable_builder_2.dart delete mode 100644 lib/src/widget/gaps.dart delete mode 100644 lib/src/widget/platform_progress_indicator.dart delete mode 100644 lib/src/widget/scale_text.dart diff --git a/.github/workflows/runnable.yml b/.github/workflows/runnable.yml index 8ca1a3c8..1faf9794 100644 --- a/.github/workflows/runnable.yml +++ b/.github/workflows/runnable.yml @@ -75,5 +75,4 @@ jobs: - run: dart --version - run: flutter --version - run: flutter pub get - - run: sudo echo "y" | sudo $ANDROID_HOME/tools/bin/sdkmanager "ndk;21.4.7075529" - run: cd example; flutter build apk --debug diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c23057b..6095243f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ that can be found in the LICENSE file. --> > [!IMPORTANT] > See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions. +## 9.0.0-dev.3 + +### Improvements + +- Use `wechat_picker_library`. + ## 9.0.0-dev.2 ### Fixes diff --git a/lib/src/constants/constants.dart b/lib/src/constants/constants.dart index dea20b98..f81990c0 100644 --- a/lib/src/constants/constants.dart +++ b/lib/src/constants/constants.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by an Apache license that can be found // in the LICENSE file. -import 'package:flutter/painting.dart'; import 'package:photo_manager/photo_manager.dart'; const String packageName = 'wechat_assets_picker'; @@ -10,8 +9,5 @@ const String packageName = 'wechat_assets_picker'; const int defaultAssetsPerPage = 80; const int defaultMaxAssetsCount = 9; -/// Default theme color from WeChat. -const Color defaultThemeColorWeChat = Color(0xff00bc56); - const ThumbnailSize defaultAssetGridPreviewSize = ThumbnailSize.square(200); const ThumbnailSize defaultPathThumbnailSize = ThumbnailSize.square(80); diff --git a/lib/src/constants/extensions.dart b/lib/src/constants/extensions.dart deleted file mode 100644 index 0e6df34b..00000000 --- a/lib/src/constants/extensions.dart +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2019 The FlutterCandies author. All rights reserved. -// Use of this source code is governed by an Apache license that can be found -// in the LICENSE file. - -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; - -typedef CNP = ChangeNotifierProvider; - -extension BuildContextExtension on BuildContext { - ThemeData get theme => Theme.of(this); - - IconThemeData get iconTheme => IconTheme.of(this); - - TextTheme get textTheme => Theme.of(this).textTheme; - - double get topPadding => MediaQuery.paddingOf(this).top; - - double get bottomPadding => MediaQuery.paddingOf(this).bottom; - - double get bottomInsets => MediaQuery.viewInsetsOf(this).bottom; -} - -extension BrightnessExtension on Brightness { - bool get isDark => this == Brightness.dark; - - bool get isLight => this == Brightness.light; - - Brightness get reverse => - this == Brightness.light ? Brightness.dark : Brightness.light; -} - -extension ColorExtension on Color { - bool get isTransparent => this == Colors.transparent || alpha == 0x00; -} - -extension ThemeDataExtension on ThemeData { - Brightness get effectiveBrightness => - appBarTheme.systemOverlayStyle?.statusBarBrightness ?? brightness; -} diff --git a/lib/src/constants/typedefs.dart b/lib/src/constants/typedefs.dart index f484d7a9..1d2c8689 100644 --- a/lib/src/constants/typedefs.dart +++ b/lib/src/constants/typedefs.dart @@ -6,6 +6,10 @@ import 'dart:async'; import 'package:flutter/widgets.dart'; import 'package:photo_manager/photo_manager.dart' show PermissionState; +import 'package:provider/provider.dart'; + +/// {@nodoc} +typedef CNP = ChangeNotifierProvider; /// {@template wechat_assets_picker.LoadingIndicatorBuilder} /// Build the loading indicator with the given [isAssetsEmpty]. diff --git a/lib/src/delegates/asset_picker_builder_delegate.dart b/lib/src/delegates/asset_picker_builder_delegate.dart index 6ef4cbd1..259a43e2 100644 --- a/lib/src/delegates/asset_picker_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_builder_delegate.dart @@ -14,23 +14,19 @@ import 'package:flutter/services.dart'; import 'package:photo_manager/photo_manager.dart'; import 'package:photo_manager_image_provider/photo_manager_image_provider.dart'; import 'package:provider/provider.dart'; +import 'package:wechat_picker_library/wechat_picker_library.dart'; import '../constants/constants.dart'; import '../constants/enums.dart'; -import '../constants/extensions.dart'; import '../constants/typedefs.dart'; import '../delegates/asset_picker_text_delegate.dart'; -import '../internal/singleton.dart'; +import '../internals/singleton.dart'; import '../models/path_wrapper.dart'; import '../provider/asset_picker_provider.dart'; import '../widget/asset_picker.dart'; import '../widget/asset_picker_app_bar.dart'; import '../widget/asset_picker_viewer.dart'; import '../widget/builder/asset_entity_grid_item_builder.dart'; -import '../widget/builder/value_listenable_builder_2.dart'; -import '../widget/gaps.dart'; -import '../widget/platform_progress_indicator.dart'; -import '../widget/scale_text.dart'; /// The delegate to build the whole picker's components. /// diff --git a/lib/src/delegates/asset_picker_delegate.dart b/lib/src/delegates/asset_picker_delegate.dart index 6c01b213..b8bb9731 100644 --- a/lib/src/delegates/asset_picker_delegate.dart +++ b/lib/src/delegates/asset_picker_delegate.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:photo_manager/photo_manager.dart'; +import 'package:wechat_picker_library/wechat_picker_library.dart'; import '../constants/config.dart'; import '../constants/constants.dart'; diff --git a/lib/src/delegates/asset_picker_viewer_builder_delegate.dart b/lib/src/delegates/asset_picker_viewer_builder_delegate.dart index 453239ce..86942db6 100644 --- a/lib/src/delegates/asset_picker_viewer_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_viewer_builder_delegate.dart @@ -12,13 +12,13 @@ import 'package:flutter/services.dart'; import 'package:photo_manager/photo_manager.dart'; import 'package:photo_manager_image_provider/photo_manager_image_provider.dart'; import 'package:provider/provider.dart'; +import 'package:wechat_picker_library/wechat_picker_library.dart'; import '../constants/custom_scroll_physics.dart'; import '../constants/enums.dart'; -import '../constants/extensions.dart'; import '../constants/typedefs.dart'; import '../delegates/asset_picker_text_delegate.dart'; -import '../internal/singleton.dart'; +import '../internals/singleton.dart'; import '../provider/asset_picker_provider.dart'; import '../provider/asset_picker_viewer_provider.dart'; import '../widget/asset_picker_app_bar.dart'; @@ -26,9 +26,7 @@ import '../widget/asset_picker_viewer.dart'; import '../widget/builder/audio_page_builder.dart'; import '../widget/builder/fade_image_builder.dart'; import '../widget/builder/image_page_builder.dart'; -import '../widget/builder/value_listenable_builder_2.dart'; import '../widget/builder/video_page_builder.dart'; -import '../widget/scale_text.dart'; abstract class AssetPickerViewerBuilderDelegate { AssetPickerViewerBuilderDelegate({ diff --git a/lib/src/internal/singleton.dart b/lib/src/internals/singleton.dart similarity index 100% rename from lib/src/internal/singleton.dart rename to lib/src/internals/singleton.dart diff --git a/lib/src/provider/asset_picker_provider.dart b/lib/src/provider/asset_picker_provider.dart index 77779770..3a726336 100644 --- a/lib/src/provider/asset_picker_provider.dart +++ b/lib/src/provider/asset_picker_provider.dart @@ -12,7 +12,7 @@ import 'package:provider/provider.dart'; import '../constants/constants.dart'; import '../delegates/sort_path_delegate.dart'; -import '../internal/singleton.dart'; +import '../internals/singleton.dart'; import '../models/path_wrapper.dart'; /// Helps the assets picker to manage [Path]s and [Asset]s. diff --git a/lib/src/widget/asset_picker_app_bar.dart b/lib/src/widget/asset_picker_app_bar.dart index 1b97aa48..d0a5fede 100644 --- a/lib/src/widget/asset_picker_app_bar.dart +++ b/lib/src/widget/asset_picker_app_bar.dart @@ -7,8 +7,7 @@ import 'dart:ui' as ui; import 'package:flutter/material.dart'; import 'package:flutter/semantics.dart'; import 'package:flutter/services.dart'; - -import '../constants/extensions.dart'; +import 'package:wechat_picker_library/wechat_picker_library.dart'; /// A custom app bar. /// 自定义的顶栏 diff --git a/lib/src/widget/builder/asset_entity_grid_item_builder.dart b/lib/src/widget/builder/asset_entity_grid_item_builder.dart index e087a40e..b36c41b8 100644 --- a/lib/src/widget/builder/asset_entity_grid_item_builder.dart +++ b/lib/src/widget/builder/asset_entity_grid_item_builder.dart @@ -5,9 +5,9 @@ import 'package:extended_image/extended_image.dart'; import 'package:flutter/material.dart'; import 'package:photo_manager_image_provider/photo_manager_image_provider.dart'; +import 'package:wechat_picker_library/wechat_picker_library.dart'; -import '../../internal/singleton.dart'; -import '../../widget/scale_text.dart'; +import '../../internals/singleton.dart'; class AssetEntityGridItemBuilder extends StatefulWidget { const AssetEntityGridItemBuilder({ diff --git a/lib/src/widget/builder/audio_page_builder.dart b/lib/src/widget/builder/audio_page_builder.dart index 53af742e..d122efa0 100644 --- a/lib/src/widget/builder/audio_page_builder.dart +++ b/lib/src/widget/builder/audio_page_builder.dart @@ -7,11 +7,10 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:photo_manager/photo_manager.dart'; import 'package:video_player/video_player.dart'; +import 'package:wechat_picker_library/wechat_picker_library.dart'; import '../../constants/constants.dart'; -import '../../constants/extensions.dart'; -import '../../internal/singleton.dart'; -import '../scale_text.dart'; +import '../../internals/singleton.dart'; class AudioPageBuilder extends StatefulWidget { const AudioPageBuilder({super.key, required this.asset}); diff --git a/lib/src/widget/builder/image_page_builder.dart b/lib/src/widget/builder/image_page_builder.dart index 315adbd9..893b86df 100644 --- a/lib/src/widget/builder/image_page_builder.dart +++ b/lib/src/widget/builder/image_page_builder.dart @@ -10,9 +10,9 @@ import 'package:flutter/services.dart'; import 'package:photo_manager/photo_manager.dart'; import 'package:photo_manager_image_provider/photo_manager_image_provider.dart'; import 'package:video_player/video_player.dart'; +import 'package:wechat_picker_library/wechat_picker_library.dart'; import '../../delegates/asset_picker_viewer_builder_delegate.dart'; -import 'locally_available_builder.dart'; class ImagePageBuilder extends StatefulWidget { const ImagePageBuilder({ diff --git a/lib/src/widget/builder/locally_available_builder.dart b/lib/src/widget/builder/locally_available_builder.dart deleted file mode 100644 index 36700ee5..00000000 --- a/lib/src/widget/builder/locally_available_builder.dart +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2019 The FlutterCandies author. All rights reserved. -// Use of this source code is governed by an Apache license that can be found -// in the LICENSE file. - -import 'dart:developer' as dev; -import 'dart:io'; - -import 'package:flutter/material.dart'; -import 'package:photo_manager/photo_manager.dart'; - -import '../../constants/extensions.dart'; -import '../scale_text.dart'; - -class LocallyAvailableBuilder extends StatefulWidget { - const LocallyAvailableBuilder({ - super.key, - required this.asset, - required this.builder, - this.isOriginal = true, - }); - - final AssetEntity asset; - final Widget Function(BuildContext context, AssetEntity asset) builder; - final bool isOriginal; - - @override - State createState() => - _LocallyAvailableBuilderState(); -} - -class _LocallyAvailableBuilderState extends State { - bool _isLocallyAvailable = false; - PMProgressHandler? _progressHandler; - - @override - void initState() { - super.initState(); - _checkLocallyAvailable(); - } - - @override - void didUpdateWidget(LocallyAvailableBuilder oldWidget) { - super.didUpdateWidget(oldWidget); - if (widget.asset != oldWidget.asset || - widget.isOriginal != oldWidget.isOriginal) { - _isLocallyAvailable = false; - _progressHandler = null; - _checkLocallyAvailable(); - } - } - - Future _checkLocallyAvailable() async { - _isLocallyAvailable = await widget.asset.isLocallyAvailable( - isOrigin: widget.isOriginal, - ); - if (!mounted) { - return; - } - setState(() {}); - if (!_isLocallyAvailable) { - _progressHandler = PMProgressHandler(); - Future(() async { - final File? file = await widget.asset.loadFile( - isOrigin: widget.isOriginal, - withSubtype: true, - progressHandler: _progressHandler, - ); - if (file != null) { - _isLocallyAvailable = true; - if (mounted) { - setState(() {}); - } - } - }); - } - _progressHandler?.stream.listen((PMProgressState s) { - assert(() { - dev.log('Handling progress: $s.'); - return true; - }()); - if (s.state == PMRequestState.success) { - _isLocallyAvailable = true; - if (mounted) { - setState(() {}); - } - } - }); - } - - Widget _indicator(BuildContext context) { - return StreamBuilder( - stream: _progressHandler!.stream, - initialData: const PMProgressState(0, PMRequestState.prepare), - builder: (BuildContext c, AsyncSnapshot s) { - if (s.hasData) { - final double progress = s.data!.progress; - final PMRequestState state = s.data!.state; - return Row( - mainAxisSize: MainAxisSize.min, - children: [ - Icon( - state == PMRequestState.failed - ? Icons.cloud_off - : Icons.cloud_queue, - color: context.iconTheme.color?.withOpacity(.4), - size: 28, - ), - if (state != PMRequestState.success && - state != PMRequestState.failed) - ScaleText( - ' iCloud ${(progress * 100).toInt()}%', - style: TextStyle( - color: context.textTheme.bodyMedium?.color - ?.withOpacity(.4), - ), - ), - ], - ); - } - return const SizedBox.shrink(); - }, - ); - } - - @override - Widget build(BuildContext context) { - if (_isLocallyAvailable) { - return widget.builder(context, widget.asset); - } - if (_progressHandler != null) { - return Center(child: _indicator(context)); - } - return const SizedBox.shrink(); - } -} diff --git a/lib/src/widget/builder/value_listenable_builder_2.dart b/lib/src/widget/builder/value_listenable_builder_2.dart deleted file mode 100644 index e23ef04f..00000000 --- a/lib/src/widget/builder/value_listenable_builder_2.dart +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2019 The FlutterCandies author. All rights reserved. -// Use of this source code is governed by an Apache license that can be found -// in the LICENSE file. - -import 'package:flutter/material.dart'; - -class ValueListenableBuilder2 extends StatelessWidget { - const ValueListenableBuilder2({ - super.key, - required this.firstNotifier, - required this.secondNotifier, - required this.builder, - this.child, - }); - - final ValueNotifier firstNotifier; - final ValueNotifier secondNotifier; - final Widget Function(BuildContext, A, B, Widget?) builder; - final Widget? child; - - @override - Widget build(BuildContext context) { - return ValueListenableBuilder( - valueListenable: firstNotifier, - builder: (_, A first, __) => ValueListenableBuilder( - valueListenable: secondNotifier, - builder: (BuildContext context, B second, Widget? w) { - return builder(context, first, second, w); - }, - child: child, - ), - ); - } -} diff --git a/lib/src/widget/builder/video_page_builder.dart b/lib/src/widget/builder/video_page_builder.dart index 3ed8b795..d2b2b796 100644 --- a/lib/src/widget/builder/video_page_builder.dart +++ b/lib/src/widget/builder/video_page_builder.dart @@ -7,12 +7,11 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:photo_manager/photo_manager.dart'; import 'package:video_player/video_player.dart'; +import 'package:wechat_picker_library/wechat_picker_library.dart'; import '../../constants/constants.dart'; import '../../delegates/asset_picker_viewer_builder_delegate.dart'; -import '../../internal/singleton.dart'; -import '../scale_text.dart'; -import 'locally_available_builder.dart'; +import '../../internals/singleton.dart'; class VideoPageBuilder extends StatefulWidget { const VideoPageBuilder({ diff --git a/lib/src/widget/gaps.dart b/lib/src/widget/gaps.dart deleted file mode 100644 index 7f9c2c2e..00000000 --- a/lib/src/widget/gaps.dart +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2019 The FlutterCandies author. All rights reserved. -// Use of this source code is governed by an Apache license that can be found -// in the LICENSE file. - -import 'package:flutter/material.dart'; - -class Gap extends StatelessWidget { - const Gap.h( - double width, { - super.key, - double? height, - this.color, - }) : _width = width, - _height = height; - - const Gap.v( - double height, { - super.key, - double? width, - this.color, - }) : _width = width, - _height = height; - - final double? _width; - final double? _height; - final Color? color; - - @override - Widget build(BuildContext context) { - Widget w = SizedBox(width: _width, height: _height); - if (color != null) { - w = ColoredBox(color: color!, child: w); - } - return w; - } -} - -class SliverGap extends StatelessWidget { - const SliverGap.h( - double width, { - super.key, - double? height, - this.color, - }) : _width = width, - _height = height; - - const SliverGap.v( - double height, { - super.key, - double? width, - this.color, - }) : _width = width, - _height = height; - - final double? _width; - final double? _height; - final Color? color; - - @override - Widget build(BuildContext context) { - Widget child; - if (_width != null) { - child = Gap.h(_width, height: _height, color: color); - } else if (_height != null) { - child = Gap.v(_height, width: _width, color: color); - } else { - child = const SizedBox.shrink(); - } - return SliverToBoxAdapter(child: child); - } -} diff --git a/lib/src/widget/platform_progress_indicator.dart b/lib/src/widget/platform_progress_indicator.dart deleted file mode 100644 index c465fe70..00000000 --- a/lib/src/widget/platform_progress_indicator.dart +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 The FlutterCandies author. All rights reserved. -// Use of this source code is governed by an Apache license that can be found -// in the LICENSE file. - -import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; - -/// Progress Indicator. Used in loading data. -class PlatformProgressIndicator extends StatelessWidget { - const PlatformProgressIndicator({ - super.key, - this.strokeWidth = 4.0, - this.radius = 10.0, - this.size = 48.0, - this.color, - this.value, - this.brightness, - }); - - final double strokeWidth; - final double radius; - final double size; - final Color? color; - final double? value; - final Brightness? brightness; - - bool get isAppleOS => switch (defaultTargetPlatform) { - TargetPlatform.iOS || TargetPlatform.macOS => true, - _ => false, - }; - - @override - Widget build(BuildContext context) { - return SizedBox.fromSize( - size: Size.square(size), - child: isAppleOS - ? CupertinoTheme( - data: CupertinoThemeData( - brightness: brightness ?? Brightness.dark, - ), - child: CupertinoActivityIndicator(radius: radius), - ) - : CircularProgressIndicator( - strokeWidth: strokeWidth, - valueColor: - color != null ? AlwaysStoppedAnimation(color!) : null, - value: value, - ), - ); - } -} diff --git a/lib/src/widget/scale_text.dart b/lib/src/widget/scale_text.dart deleted file mode 100644 index 93337517..00000000 --- a/lib/src/widget/scale_text.dart +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2019 The FlutterCandies author. All rights reserved. -// Use of this source code is governed by an Apache license that can be found -// in the LICENSE file. - -import 'package:flutter/material.dart'; - -class ScaleText extends StatelessWidget { - const ScaleText( - this.text, { - super.key, - this.style, - this.strutStyle, - this.maxLines, - this.overflow, - this.textAlign, - this.textDirection, - this.semanticsLabel, - this.softWrap, - this.minScaleFactor = 0.7, - this.maxScaleFactor = 1.3, - }); - - final String text; - final TextStyle? style; - final StrutStyle? strutStyle; - final int? maxLines; - final TextOverflow? overflow; - final TextAlign? textAlign; - final TextDirection? textDirection; - final String? semanticsLabel; - final bool? softWrap; - - final double minScaleFactor; - final double maxScaleFactor; - - @override - Widget build(BuildContext context) { - final MediaQueryData mqd = MediaQuery.of(context); - final effectiveScaler = mqd.textScaler.clamp( - minScaleFactor: minScaleFactor, - maxScaleFactor: maxScaleFactor, - ); - return MediaQuery( - data: mqd.copyWith(textScaler: effectiveScaler), - child: Text( - text, - style: style, - strutStyle: strutStyle, - maxLines: maxLines, - textAlign: textAlign, - overflow: overflow, - textDirection: textDirection, - semanticsLabel: semanticsLabel, - softWrap: softWrap, - ), - ); - } -} diff --git a/pubspec.yaml b/pubspec.yaml index d2bd4e66..d7650ce3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: wechat_assets_picker -version: 9.0.0-dev.2 +version: 9.0.0-dev.3 description: | An image picker (also with videos and audio) for Flutter projects based on WeChat's UI, @@ -22,6 +22,8 @@ dependencies: flutter: sdk: flutter + wechat_picker_library: ^1.0.0-0 + extended_image: ^8.1.0 photo_manager: ^3.0.0-dev.1 photo_manager_image_provider: ^2.0.0