Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
949 stars 240 forks source link

`CameraAwesomeBuilder.custom.builder` doesn't rebuild when state changes #172

Closed Zazo032 closed 1 year ago

Zazo032 commented 1 year ago

Steps to Reproduce

Run this small sample:

CameraAwesomeBuilder.custom(
  enableAudio: false,
  saveConfig: SaveConfig.photo(
    pathBuilder: () => photoPath,
  ),
  builder: (CameraState state) {
    return IconButton(
      color: Colors.white,
      icon: Icon(_getFlashIcon(state.sensorConfig.flashMode)),
      key: const Key('flash_icon'),
      onPressed: state.sensorConfig.switchCameraFlash,
    );
  }
),

Expected results

After tapping the IconButton, state.sensorConfig.switchCameraFlash gets called and a new FlashMode should be available in state.sensorConfig.flashMode. Also happens with state.sensorConfig.sensor after calling state.switchCameraSensor

Actual results

builder method is not called, so Icons are not updated.

About your device

Brand Model OS
Samsung A21s 12

Using latest version of the repo:

camerawesome:
    git:
      url: https://github.com/Apparence-io/camera_awesome.git

Using Flutter version 3.3.10.

apalala-dev commented 1 year ago

Hello, thank you for reporting this! We might make the documentation more clear about this, but what you need to do is listen to the sensorConfig as well. The stream of the current sensorConfig is accessible by appending a $ to the end of the sensorConfig (sensorConfig$). This is how the built-in Flash button works:

StreamBuilder<SensorConfig>(
  stream: state.sensorConfig$,
  builder: (_, sensorConfigSnapshot) {
    if (!sensorConfigSnapshot.hasData) {
      return SizedBox();
    }
    final sensorConfig = sensorConfigSnapshot.requireData;
    return StreamBuilder<FlashMode>(
      stream: sensorConfig.flashMode$,
      builder: (context, snapshot) {
        // return your icon
      },
    );
  },
);

You should work with the sensorConfig$ if you want to get their updates.

Zazo032 commented 1 year ago

StreamBuilder<SensorConfig> throws an error because it seems like SensorConfig class is not exposed

Zazo032 commented 1 year ago

Similar thing happens to CameraPreviewFit, seems like there are a few hidden but required APIs: image

As a workaround, you can import:

import 'package:camerawesome/src/layouts/awesome/widgets/awesome_camera_preview.dart';

But the following linter gets triggered: https://dart-lang.github.io/linter/lints/implementation_imports.html

apalala-dev commented 1 year ago

I'll make a PR to expose these, you're right.

apalala-dev commented 1 year ago

Classes should be exposed on master now. I'm closing the issue, feel free to open a new one if something else is missing. 👌