diff --git a/lib/src/components/organisms/camera/camera_page.dart b/lib/src/components/organisms/camera/camera_page.dart index 4521593..f075cac 100644 --- a/lib/src/components/organisms/camera/camera_page.dart +++ b/lib/src/components/organisms/camera/camera_page.dart @@ -357,7 +357,10 @@ class _CameraWrapperState extends State<_CameraWrapper> { children: [ if (widget.state is! VideoRecordingCameraState) GestureDetector( - onTap: () => Navigator.of(context).pop(), + onTap: () async { + await ZdsSystemChrome.resetAppOrientations(); + if (context.mounted) Navigator.of(context).pop(); + }, child: AwesomeCircleWidget( theme: theme, size: 45, @@ -782,18 +785,23 @@ class _PreviewActions extends StatelessWidget { elevation: 0, shape: const CircleBorder(), backgroundColor: Colors.black38, - onPressed: () => Navigator.of(context).pop(false), + onPressed: () async => _onPop(context, false), child: const Icon(Icons.close, color: ZetaColorBase.white), ), FloatingActionButton( elevation: 0, shape: const CircleBorder(), backgroundColor: Colors.black38, - onPressed: () => Navigator.of(context).pop(true), + onPressed: () async => _onPop(context, true), child: const Icon(Icons.done, color: ZetaColorBase.white), ), ], ), ); } + + Future _onPop(BuildContext context, bool result) async { + await ZdsSystemChrome.resetAppOrientations(); + if (context.mounted) Navigator.of(context).pop(result); + } } diff --git a/lib/src/utils/tools.dart b/lib/src/utils/tools.dart index 12c0ec0..8bbfafb 100644 --- a/lib/src/utils/tools.dart +++ b/lib/src/utils/tools.dart @@ -4,5 +4,6 @@ export 'tools/frame_mixin.dart'; export 'tools/keyboard_dismiss.dart'; export 'tools/modifiers.dart'; export 'tools/nested_flow.dart'; +export 'tools/system_chrome.dart'; export 'tools/tab_navigator.dart'; export 'tools/utils.dart'; diff --git a/lib/src/utils/tools/system_chrome.dart b/lib/src/utils/tools/system_chrome.dart new file mode 100644 index 0000000..25c26c0 --- /dev/null +++ b/lib/src/utils/tools/system_chrome.dart @@ -0,0 +1,48 @@ +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +/// Controls orientations of the application interface +class ZdsSystemChrome { + static List _orientations = [ + DeviceOrientation.portraitUp, + DeviceOrientation.portraitDown, + DeviceOrientation.landscapeLeft, + DeviceOrientation.landscapeRight, + ]; + + /// Get the set of orientations the application interface can + /// be displayed in. + static List get appOrientations => _orientations; + + /// Specifies the set of orientations the application interface can + /// be displayed in. + /// + /// The `orientation` argument is a list of [DeviceOrientation] enum values. + static Future setPreferredOrientations(List? orientations) async { + final platformMediaQuery = MediaQueryData.fromView(PlatformDispatcher.instance.views.first); + if (orientations == null || orientations.isEmpty) { + if (platformMediaQuery.size.shortestSide < 600) { + _orientations = [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]; + } else { + _orientations = [ + DeviceOrientation.portraitUp, + DeviceOrientation.portraitDown, + DeviceOrientation.landscapeLeft, + DeviceOrientation.landscapeRight, + ]; + } + } else { + _orientations = orientations; + } + + await resetAppOrientations(); + } + + /// Set the set of orientations the application interface can + /// be displayed in. + static Future resetAppOrientations() async { + await SystemChrome.setPreferredOrientations(appOrientations); + } +}