How to Use the Flutter WeChat Assets Picker

Dec 29, 2022 | Programming

The Flutter WeChat Assets Picker is a fabulous tool that allows Flutter developers to seamlessly integrate image, video, and audio picking functionalities into their applications, drawing inspiration from the WeChat user interface. In this guide, we’ll walk through how to implement it effectively!

Getting Started

The first step in utilizing the Flutter WeChat Assets Picker is to include it in your Flutter project. Here’s how you do that:

  • Open your pubspec.yaml file.
  • Add the following dependency:
  • dependencies:
      wechat_assets_picker: ^latest_version
    
  • Run the command flutter pub get to install the new package.

Setup According to Platform

Different platforms require specific permissions and configurations:

1. Android

Make sure to set your targetSdkVersion and compileSdkVersion to 33 in your project’s build configuration. This is crucial for fetching assets on devices running Android 13.

Add necessary permissions in your AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>

2. iOS

For iOS, ensure your platform version is at least 11.0. Update the Podfile accordingly:

platform :ios, '11.0'

Also, add a usage description in the Info.plist file:

<key>NSPhotoLibraryUsageDescription</key>
<string>Your permission description here.</string>

3. macOS

Update the macOS platform version in the macos/Podfile to at least 10.15:

platform :osx, '10.15'

Usage Example

Utilizing the picker is straightforward. Here’s a simple usage example:

Imagine you want to pick several photos, similar to choosing candies from a jar:

final List<AssetEntity>? result = await AssetPicker.pickAssets(context);

Think of it as reaching into a selection of candies; you can choose whichever ones you want. This line of code will open the picker interface for you to make your selections.

Troubleshooting

If you encounter common issues like dependency conflicts when running flutter pub get, you can use dependency_overrides within your pubspec.yaml file to resolve them:

dependency_overrides:
  wechat_assets_picker: ^latest_version

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

With just the steps outlined above, you can easily implement the Flutter WeChat Assets Picker into your app, providing users with a familiar and seamless experience when it comes to selecting media files.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox