Skip to content

Commit

Permalink
fix:[TM-42460] Reset resetPreferredOrientations after camera dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed May 23, 2024
1 parent f0b23a9 commit e307368
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/src/components/organisms/camera/camera_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<void> _onPop(BuildContext context, bool result) async {
await ZdsSystemChrome.resetAppOrientations();
if (context.mounted) Navigator.of(context).pop(result);
}
}
1 change: 1 addition & 0 deletions lib/src/utils/tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
48 changes: 48 additions & 0 deletions lib/src/utils/tools/system_chrome.dart
Original file line number Diff line number Diff line change
@@ -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<DeviceOrientation> _orientations = [
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
];

/// Get the set of orientations the application interface can
/// be displayed in.
static List<DeviceOrientation> 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<void> setPreferredOrientations(List<DeviceOrientation>? 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<void> resetAppOrientations() async {
await SystemChrome.setPreferredOrientations(appOrientations);
}
}

0 comments on commit e307368

Please sign in to comment.