曝光
Flutter上CupertinoSlider
組件的樣式是iOS上的Slider
,使用該組件控制曝光量,
Camera插件提供的API是CameraController
的
Future<double> setExposureOffset(double offset) async {
...
}
最后調用iOS端的系統方法控制曝光值
- (void)setExposureTargetBias:(float)bias completionHandler:(nullable void (^)(CMTime syncTime))handler API_AVAILABLE(ios(8.0), macCatalyst(14.0), tvos(17.0)) API_UNAVAILABLE(macos, visionos);
class TakePictureScreenState extends State<TakePictureScreen> {/// 設置默認值double currentExposure = 0.0;/// 是否顯示曝光Slider組件bool _showedExposure = false;.../// 使用CupertinoSliderWidget showExposure() {if (_showedExposure) {return SizedBox(height: 44,width: MediaQuery.of(context).size.width,child: CupertinoSlider(/// 滑動Slider時觸發的事件onChanged: (value) {setState(() {/// 調整相機的曝光值_controller.setExposureOffset(value);currentExposure = value;});},min: -3, /// 設置作用范圍max: 3,value: currentExposure, /// 當前Slider顯示的值),);}return SizedBox.shrink();}
}

兩指手勢縮放
系統的相機可以雙指進行縮放操作,在Flutter中可以在GestureDetector來實現
/// 最小縮放比例
double _minAvailableZoom = 1.0;
/// 最大縮放比例
double _maxAvailableZoom = 1.0;
/// 記錄當前的縮放比例
double _currentScale = 1.0;
/// 當前的基礎值
double _baseScale = 1.0;Listener(onPointerDown: (_) => _pointers++,onPointerUp: (_) => _pointers--, // 用來判斷是否雙指child: CameraPreview(_controller,// Creates a widget that defers its building until layout.// 布局完成再創建child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {return GestureDetector(// Opaque targets can be hit by hit tests, causing them to both receive events within their bounds and prevent targets visually behind them from also receiving events.// 相機Widget能收到手勢behavior: HitTestBehavior.opaque, // 設置開始縮放事件onScaleStart: _handleScaleStart,// 設置縮放值變化事件