Skip to content

Commit

Permalink
Merge branch 'main' into enable-modules-with-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sharjeelyunus authored Dec 22, 2024
2 parents 75656c8 + 931ad39 commit 01d6477
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
31 changes: 23 additions & 8 deletions modules/camera/lib/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ class CameraState extends EWidgetState<Camera> with WidgetsBindingObserver {
try {
cameras = await availableCameras();
setCameraInit();
setState(() {
isLoading = false;
});
} catch (e) {
if (e is CameraException && e.code == 'CameraAccessDenied') {
hasPermission = false;
}
}
setState(() {
isLoading = false;
});
}

void initAccelerometerSub() {
Expand Down Expand Up @@ -412,8 +412,8 @@ class CameraState extends EWidgetState<Camera> with WidgetsBindingObserver {
if (isLoading) {
return const Scaffold(body: Center(child: CircularProgressIndicator()));
}
if (hasPermission) {
return showPreviewPage ? fullImagePreview() : permissionDeniedView();
if (showPreviewPage) {
return fullImagePreview();
}
if (widget._controller.cameraController == null ||
!widget._controller.cameraController!.value.isInitialized) {
Expand Down Expand Up @@ -639,7 +639,10 @@ class CameraState extends EWidgetState<Camera> with WidgetsBindingObserver {
final file = widget._controller.files.elementAt(index);

return kIsWeb
? DisplayMediaWeb(file: file)
? DisplayMediaWeb(
file: file,
aspectRatio: widget
.controller.cameraController?.value.aspectRatio)
: Center(
child: file.getMediaType() == MediaType.image
? Image.file(file.toFile()!)
Expand Down Expand Up @@ -1469,9 +1472,13 @@ class _InlineVideoPlayerState extends State<InlineVideoPlayer> {
class DisplayMediaWeb extends StatefulWidget {
final File file;
final bool isThumbnail;
final double? aspectRatio;

const DisplayMediaWeb(
{Key? key, required this.file, this.isThumbnail = false})
{Key? key,
required this.file,
this.isThumbnail = false,
this.aspectRatio})
: super(key: key);

@override
Expand Down Expand Up @@ -1527,13 +1534,21 @@ class _DisplayMediaWebState extends State<DisplayMediaWeb> {
@override
Widget build(BuildContext context) {
if (_isImage) {
return Image.network(
final image = Image.network(
widget.file.path!,
fit: widget.isThumbnail ? BoxFit.cover : null,
errorBuilder: (context, error, stackTrace) {
return const SizedBox.shrink();
},
);
return widget.aspectRatio != null
? Center(
child: AspectRatio(
aspectRatio: widget.aspectRatio!,
child: image,
),
)
: image;
} else if (_isVideo) {
if (widget.isThumbnail) {
return const Icon(
Expand Down
13 changes: 13 additions & 0 deletions modules/camera/lib/camera_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:camera/camera.dart';
import 'package:ensemble/framework/action.dart';
import 'package:ensemble/framework/bindings.dart';
import 'package:ensemble/framework/data_context.dart';
import 'package:ensemble/framework/event.dart';
import 'package:ensemble/framework/stub/camera_manager.dart';
import 'package:ensemble/framework/scope.dart';
import 'package:ensemble/screen_controller.dart';
Expand Down Expand Up @@ -98,6 +99,18 @@ class CameraManagerImpl extends CameraManager {
scopeManager?.dataContext.eval(cameraAction.options?['default']),
fallback: false);

final isCameraAllowed = await hasPermission();

if (!(isCameraAllowed ?? false)) {
if (cameraAction.onError != null) {
ScreenController().executeAction(context, cameraAction.onError!,
event: EnsembleEvent(null,
error: 'ensemble_camera: permission denied'));
}
debugPrint('ensemble_camera: permission denied');
return;
}

if (isDefault && !kIsWeb) {
await defaultCamera(context, cameraAction, scopeManager);
} else {
Expand Down
3 changes: 3 additions & 0 deletions modules/ensemble/lib/framework/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ class ShowCameraAction extends EnsembleAction {
this.onComplete,
this.onClose,
this.onCapture,
this.onError,
}) : super(initiator: initiator);
final Map<String, dynamic>? options;
String? id;
EnsembleAction? onComplete;
EnsembleAction? onClose;
EnsembleAction? onCapture;
EnsembleAction? onError;


factory ShowCameraAction.fromYaml({Invokable? initiator, Map? payload}) {
return ShowCameraAction(
Expand Down
6 changes: 5 additions & 1 deletion modules/ensemble/lib/widget/input/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ abstract class SelectOne extends StatefulWidget
var setters = _controller.textPlaceholderSetters;
setters.addAll({
'value': (value) {
_controller.textEditingController.value = TextEditingValue(text: (value == null)? '': value.toString());
_controller.textEditingController.value =
TextEditingValue(text: (value == null) ? '' : value.toString());
return _controller.maybeValue = value;
},
'items': (values) => updateItems(values),
Expand Down Expand Up @@ -450,11 +451,14 @@ class SelectOneState extends FormFieldWidgetState<SelectOne>
focusedBorder: getSafeFocusedBorder(),
),
onChanged: (value) {
// Preserve the cursor position
final cursorPosition = fieldTextEditingController.selection;
final oldValue = widget._controller.maybeValue;
if (oldValue != value) {
widget._controller.maybeValue = value;
widget.onSelectionChanged(value);
}
fieldTextEditingController.selection = cursorPosition;
},
);
},
Expand Down

0 comments on commit 01d6477

Please sign in to comment.