Browse Source

[feat]增加wechat_assets_picker,图片选择器依赖和调用

hezihao 7 months ago
parent
commit
708855a58d

+ 16 - 13
android/app/src/main/AndroidManifest.xml

@@ -1,29 +1,32 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- 请求图片和视频权限 -->
+    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
+    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
+
     <application
-        android:allowBackup="false"
-        android:label="keyboard"
         android:name=".AtmobApplication"
-        android:icon="@mipmap/ic_launcher">
+        android:allowBackup="false"
+        android:icon="@mipmap/ic_launcher"
+        android:label="keyboard">
         <activity
             android:name=".MainActivity"
+            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
             android:exported="true"
+            android:hardwareAccelerated="true"
             android:launchMode="singleTop"
             android:taskAffinity=""
             android:theme="@style/LaunchTheme"
-            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
-            android:hardwareAccelerated="true"
             android:windowSoftInputMode="adjustResize">
             <!-- Specifies an Android theme to apply to this Activity as soon as
                  the Android process has started. This theme is visible to the user
                  while the Flutter UI initializes. After that, this theme continues
                  to determine the Window background behind the Flutter UI. -->
             <meta-data
-              android:name="io.flutter.embedding.android.NormalTheme"
-              android:resource="@style/NormalTheme"
-              />
+                android:name="io.flutter.embedding.android.NormalTheme"
+                android:resource="@style/NormalTheme" />
             <intent-filter>
-                <action android:name="android.intent.action.MAIN"/>
-                <category android:name="android.intent.category.LAUNCHER"/>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
         <!-- Don't delete the meta-data below.
@@ -39,8 +42,8 @@
          In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
     <queries>
         <intent>
-            <action android:name="android.intent.action.PROCESS_TEXT"/>
-            <data android:mimeType="text/plain"/>
+            <action android:name="android.intent.action.PROCESS_TEXT" />
+            <data android:mimeType="text/plain" />
         </intent>
     </queries>
-</manifest>
+</manifest>

+ 5 - 5
lib/module/intimacy_analyse/analyse_report/intimacy_analyse_report_view.dart

@@ -45,7 +45,7 @@ class IntimacyAnalyseReportView
         Positioned.fill(
           child: Align(
             alignment: Alignment.bottomCenter,
-            child: _buildBottomLayout(),
+            child: _buildBottomLayout(context),
           ),
         ),
       ],
@@ -219,13 +219,13 @@ class IntimacyAnalyseReportView
   }
 
   /// 底部布局
-  Widget _buildBottomLayout() {
+  Widget _buildBottomLayout(BuildContext context) {
     return Column(
       // 高度包裹内容,否则会撑满父组件
       mainAxisSize: MainAxisSize.min,
       children: [
         _buildReportPreviewBubble(),
-        _buildUnlockBtn(),
+        _buildUnlockBtn(context),
         SizedBox(height: 20.h),
       ],
     );
@@ -266,10 +266,10 @@ class IntimacyAnalyseReportView
   }
 
   /// 解锁按钮
-  Widget _buildUnlockBtn() {
+  Widget _buildUnlockBtn(BuildContext context) {
     return GestureDetector(
       onTap: () {
-        controller.clickUnlockBtn();
+        controller.clickUnlockBtn(context);
       },
       child: Container(
         margin: EdgeInsets.symmetric(horizontal: 16.w),

+ 4 - 1
lib/module/intimacy_analyse/analyse_report/intimacy_analyse_report_view_controller.dart

@@ -1,8 +1,10 @@
+import 'package:flutter/cupertino.dart';
 import 'package:get/get.dart';
 import 'package:injectable/injectable.dart';
 import 'package:keyboard/base/base_controller.dart';
 
 import '../../../data/model/intimacy_analyse_report.dart';
+import '../../../utils/image_picker_util.dart';
 
 /// 亲密度分析-分析报告Tab-Controller
 @injectable
@@ -42,6 +44,7 @@ class IntimacyAnalyseReportController extends BaseController {
   }
 
   /// 解锁
-  void clickUnlockBtn() {
+  void clickUnlockBtn(BuildContext context) {
+    ImagePickerUtil.pickImage(context, maxAssetsCount: 9);
   }
 }

+ 5 - 0
lib/resource/assets.gen.dart

@@ -424,6 +424,10 @@ class $AssetsImagesGen {
   AssetGenImage get iconKeyboardBanner =>
       const AssetGenImage('assets/images/icon_keyboard_banner.webp');
 
+  /// File path: assets/images/icon_keyboard_banner_close.webp
+  AssetGenImage get iconKeyboardBannerClose =>
+      const AssetGenImage('assets/images/icon_keyboard_banner_close.webp');
+
   /// File path: assets/images/icon_keyboard_current_character_title.webp
   AssetGenImage get iconKeyboardCurrentCharacterTitle => const AssetGenImage(
     'assets/images/icon_keyboard_current_character_title.webp',
@@ -804,6 +808,7 @@ class $AssetsImagesGen {
     iconIntimacyAnalyseReportPreviewTitle,
     iconIntimacyAnalyseUnlock,
     iconKeyboardBanner,
+    iconKeyboardBannerClose,
     iconKeyboardCurrentCharacterTitle,
     iconKeyboardCurrentGo,
     iconKeyboardDefaultAvatar,

+ 23 - 0
lib/utils/image_picker_util.dart

@@ -0,0 +1,23 @@
+import 'package:flutter/cupertino.dart';
+import 'package:wechat_assets_picker/wechat_assets_picker.dart';
+
+/// 本地选择图片工具类
+class ImagePickerUtil {
+  /// 选择图片
+  /// @param context 上下文
+  /// @param maxAssetsCount 最大选择数量
+  /// @param selectedAssets 已选择的图片列表
+  static Future<void> pickImage(
+    BuildContext context, {
+    required int maxAssetsCount,
+    List<AssetEntity>? selectedAssets,
+  }) async {
+    await AssetPicker.pickAssets(
+      context,
+      pickerConfig: AssetPickerConfig(
+        maxAssets: maxAssetsCount,
+        selectedAssets: selectedAssets,
+      ),
+    );
+  }
+}

+ 64 - 0
pubspec.lock

@@ -376,6 +376,22 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "3.4.0"
+  extended_image:
+    dependency: transitive
+    description:
+      name: extended_image
+      sha256: "85199f9233e03abc2ce2e68cbb2991648666af4a527ae4e6250935be8edfddae"
+      url: "https://pub.dev"
+    source: hosted
+    version: "9.1.0"
+  extended_image_library:
+    dependency: transitive
+    description:
+      name: extended_image_library
+      sha256: e61dafd94400fff6ef7ed1523d445ff3af137f198f3228e4a3107bc5b4bec5d1
+      url: "https://pub.dev"
+    source: hosted
+    version: "4.0.6"
   fake_async:
     dependency: transitive
     description:
@@ -628,6 +644,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "1.3.0"
+  http_client_helper:
+    dependency: transitive
+    description:
+      name: http_client_helper
+      sha256: "8a9127650734da86b5c73760de2b404494c968a3fd55602045ffec789dac3cb1"
+      url: "https://pub.dev"
+    source: hosted
+    version: "3.0.0"
   http_multi_server:
     dependency: transitive
     description:
@@ -1027,6 +1051,22 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "6.1.0"
+  photo_manager:
+    dependency: transitive
+    description:
+      name: photo_manager
+      sha256: "0bc7548fd3111eb93a3b0abf1c57364e40aeda32512c100085a48dade60e574f"
+      url: "https://pub.dev"
+    source: hosted
+    version: "3.6.4"
+  photo_manager_image_provider:
+    dependency: transitive
+    description:
+      name: photo_manager_image_provider
+      sha256: b6015b67b32f345f57cf32c126f871bced2501236c405aafaefa885f7c821e4f
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.2.0"
   platform:
     dependency: transitive
     description:
@@ -1480,6 +1520,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "2.3.4"
+  visibility_detector:
+    dependency: transitive
+    description:
+      name: visibility_detector
+      sha256: dd5cc11e13494f432d15939c3aa8ae76844c42b723398643ce9addb88a5ed420
+      url: "https://pub.dev"
+    source: hosted
+    version: "0.4.0+2"
   vm_service:
     dependency: transitive
     description:
@@ -1568,6 +1616,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "3.18.4"
+  wechat_assets_picker:
+    dependency: "direct main"
+    description:
+      name: wechat_assets_picker
+      sha256: "65104fff598394fcf1c9a75a8a65a7aa9687485534b44d6e85275774d015df45"
+      url: "https://pub.dev"
+    source: hosted
+    version: "9.5.0"
   wechat_kit:
     dependency: transitive
     description:
@@ -1576,6 +1632,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "6.0.2"
+  wechat_picker_library:
+    dependency: transitive
+    description:
+      name: wechat_picker_library
+      sha256: a42e09cb85b15fc9410f6a69671371cc60aa99c4a1f7967f6593a7f665f6f47a
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.0.5"
   win32:
     dependency: transitive
     description:

+ 3 - 0
pubspec.yaml

@@ -59,6 +59,9 @@ dependencies:
   reorderables:
     path: plugins/reorderables
 
+  # 图片选择器
+  wechat_assets_picker: ^9.5.0
+
   collection: ^1.19.1
 
   #虚线