wechat_camera_picker

repository·main·Indexed 19 days ago

https://github.com/fluttercandies/flutter_wechat_camera_picker

A Flutter camera picker that provides a user interface mimicking WeChat's camera functionality. It supports photo capturing, video recording with duration limits, and exposure adjustments. The package integrates with photo_manager and the camera plugin, returning captured media as AssetEntity objects. It includes support for localization in English, Chinese, and Vietnamese, and allows for deep UI customization via CameraPickerState and CameraPickerViewerState.

Tokens
8K
Snippets
18
Records
29
Agent score
61%

What's inside wechat_camera_picker

  1. How localization works in the camera picker

    main

    The package reads the Locale? from your BuildContext to provide the corresponding language implementation.

    Important: Ensure you can access the Locale via BuildContext, otherwise it will default to Chinese.

    Built-in languages:

    • Simplified Chinese (Default)
    • English
    • Tiếng Việt

    To use a custom or fixed language implementation, pass a CameraPickerTextDelegate to CameraPickerConfig.textDelegate.

  2. Understand Asset and Collection concepts

    main

    The wechat_camera_picker package is built on top of the photo_manager plugin. To use the API effectively, you must understand two core concepts from photo_manager:

    • Asset (AssetEntity): Represents an individual media item (photo, video, or audio).
    • Assets collection (AssetPathEntity): Represents a group of assets, such as an album or a device library.

    For detailed API information regarding these entities, refer to the photo_manager documentation.

  3. Handle localization in the camera picker

    main

    The package automatically attempts to obtain the Locale? from your BuildContext to provide localized text.

    Important: Ensure you have a valid Locale in your widget tree. If no valid Locale is found, the package defaults to Chinese (简体中文).

    Supported embedded languages:

    • 简体中文 (default)
    • English
    • Tiếng Việt

    To use a custom or fixed language, pass a CameraPickerTextDelegate through CameraPickerConfig.textDelegate.

  4. Understand the relationship with photo_manager

    main

    The wechat_camera_picker is strongly coupled with the photo_manager package. Most behaviors and data models are controlled by photo_manager. To use this picker effectively, you should understand the following core concepts from photo_manager:

    • AssetEntity: Represents a specific media resource (image, video, or audio).
    • AssetPathEntity: Represents a collection of resources (such as an album or a specific media type group).
  5. Customizing UI with custom State

    main

    You can implement custom user interfaces by overriding the following states:

    • CameraPickerState
    • CameraPickerViewerState

    Once you have implemented your custom state, you can use it when calling the picker or viewer:

    • For the picker: CameraPicker.pickFromCamera(createPickerState: () => CustomCameraPickerState());
    • For the viewer: CameraPickerViewer.pushToViewer(..., createViewerState: () => CustomCameraPickerViewerState());
  6. Customize UI using custom States

    main

    For deep UI customization, you can override and provide custom State classes for the picker and the viewer.

    Supported states to override:

    • CameraPickerState
    • CameraPickerViewerState

    To use them, pass a factory function to the respective picking methods:

    // For the camera picker
    CameraPicker.pickFromCamera(
      context,
      createPickerState: () => CustomCameraPickerState(),
    );
    
    // For the viewer
    CameraPickerViewer.pushToViewer(
      context,
      createViewerState: () => CustomCameraPickerViewerState(),
    );```
    
    // For the camera picker
    CameraPicker.pickFromCamera(
      context,
      createPickerState: () => CustomCameraPickerState(),
    );
    
    // For the viewer
    CameraPickerViewer.pushToViewer(
      context,
      createViewerState: () => CustomCameraPickerViewerState(),
    );
  7. Customize iOS launch screen assets

    main

    To change the launch screen image for the iOS version of the example app, you can either replace the image files directly in the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory or use Xcode.

    To use Xcode:

    1. Open the iOS workspace using open ios/Runner.xcworkspace.
    2. In the Project Navigator, select Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog.
    open ios/Runner.xcworkspace
  8. Configure platform-specific requirements for wechat_camera_picker

    main

    Before using the package, you must complete the setup requirements for its underlying dependencies. Specifically, follow the preparation guides for:

    1. wechat_assets_picker: Required for asset management integration.
    2. camera: Required for the actual camera hardware interface and capture functionality.
  9. Migrate customized CameraPickerState to v4.0.0

    main

    If you are extending CameraPickerState or overriding specific UI methods, you must update their signatures to match the new WeChat v8.3.0 style requirements in version 4.0.0. If you are not customizing these methods, no action is required.

    Key changes include:

    • Renaming of timer methods.
    • Changes to parameter requirements for back buttons, camera previews, capture buttons, focusing points, and foreground bodies.
    // Summary of signature changes in 4.0.0:
    
    // 1. Rename
    // restartDisplayModeDisplayTimer -> restartExposureModeDisplayTimer
    
    // 2. buildBackButton
    // Old: Widget buildBackButton(BuildContext context, BoxConstraints constraints)
    // New:
    Widget buildBackButton(BuildContext context)
    
    // 3. buildCameraPreview
    // Old: Widget buildCameraPreview(BuildContext context, DeviceOrientation orientation, BoxConstraints constraints)
    // New:
    Widget buildCameraPreview({
      required BuildContext context,
      required CameraValue cameraValue,
      required BoxConstraints constraints,
    })
    
    // 4. buildCaptureButton
    // Old: Widget buildCaptureButton(BoxConstraints constraints)
    // New:
    Widget buildCaptureButton(BuildContext context, BoxConstraints constraints)
    
    // 5. buildFocusingPoint
    // Old: Widget buildFocusingPoint(CameraValue cameraValue, BoxConstraints constraints)
    // New:
    Widget buildFocusingPoint({
      required CameraValue cameraValue,
      required BoxConstraints constraints,
      int quarterTurns = 0,
    })
    
    // 6. buildForegroundBody
    // Old: Widget buildForegroundBody(BuildContext context, BoxConstraints constraints)
    // New:
    Widget buildForegroundBody(
      BuildContext context,
      BoxConstraints constraints,
      DeviceOrientation? deviceOrientation,
    )
  10. Configure platform permissions and dependencies

    main

    Before using the picker, you must complete the setup requirements for its underlying dependencies. Specifically, follow the setup guides for:

    1. wechat_assets_picker: This is required because the camera picker deeply integrates with photo_manager.
    2. camera: Required for image and video capture functionality.

    If you encounter resolve conflict errors during flutter pub get, use dependency_overrides in your pubspec.yaml to resolve them.