CR Implementation contd.
parent
08e2cc1f3a
commit
31ed9483ad
@ -0,0 +1,177 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_zoom_videosdk/native/zoom_videosdk.dart';
|
||||
import 'package:hmg_patient_app_new/core/app_assets.dart';
|
||||
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
|
||||
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
||||
import 'package:hmg_patient_app_new/theme/colors.dart';
|
||||
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter_zoom_videosdk/flutter_zoom_view.dart' as zoom_view;
|
||||
|
||||
import '../../../../generated/locale_keys.g.dart';
|
||||
|
||||
class ZoomConnectionTestSheet extends StatefulWidget {
|
||||
const ZoomConnectionTestSheet({super.key});
|
||||
|
||||
@override
|
||||
State<ZoomConnectionTestSheet> createState() => _ZoomConnectionTestSheetState();
|
||||
}
|
||||
|
||||
class _ZoomConnectionTestSheetState extends State<ZoomConnectionTestSheet> {
|
||||
PermissionStatus? _cameraPermission;
|
||||
PermissionStatus? _micPermission;
|
||||
PermissionStatus? _notificationPermission;
|
||||
|
||||
final ZoomVideoSdk _zoomSdk = ZoomVideoSdk();
|
||||
bool _isPreviewingCamera = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_stopCameraPreview();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// 1. Request and verify system permissions
|
||||
Future<void> _checkPermissions() async {
|
||||
final cameraStatus = await Permission.camera.request();
|
||||
final micStatus = await Permission.microphone.request();
|
||||
final notificationStatus = await Permission.notification.request();
|
||||
|
||||
setState(() {
|
||||
_cameraPermission = cameraStatus;
|
||||
_micPermission = micStatus;
|
||||
_notificationPermission = notificationStatus;
|
||||
});
|
||||
|
||||
if (cameraStatus.isGranted && micStatus.isGranted) {
|
||||
_startCameraPreview();
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Turn on camera feed via Zoom Video SDK VideoHelper
|
||||
Future<void> _startCameraPreview() async {
|
||||
try {
|
||||
await _zoomSdk.videoHelper.startVideo();
|
||||
setState(() {
|
||||
_isPreviewingCamera = true;
|
||||
});
|
||||
} catch (e) {
|
||||
debugPrint('Error starting Zoom camera feed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _stopCameraPreview() async {
|
||||
if (_isPreviewingCamera) {
|
||||
await _zoomSdk.videoHelper.stopVideo();
|
||||
setState(() {
|
||||
_isPreviewingCamera = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(20.h),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 'Zoom Device Diagnostics'.toText18(isBold: true),
|
||||
// const SizedBox(height: 16),
|
||||
|
||||
// Status Indicators
|
||||
_StatusRow(label: LocaleKeys.cameraPermissionText.tr(context: context), status: _cameraPermission),
|
||||
_StatusRow(label: LocaleKeys.microphonePermissionText.tr(context: context), status: _micPermission),
|
||||
_StatusRow(label: LocaleKeys.notificationPermissionText.tr(context: context), status: _notificationPermission),
|
||||
|
||||
SizedBox(height: 16.h),
|
||||
|
||||
// Zoom Native Platform View Widget
|
||||
Container(
|
||||
height: 200.h,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: _isPreviewingCamera
|
||||
? zoom_view.View(
|
||||
creationParams: const {
|
||||
"userId": "",
|
||||
"sharing": false,
|
||||
"preview": true, // Instructs SDK to operate in local preview mode
|
||||
"focused": false,
|
||||
"hasMultiCamera": false,
|
||||
"multiCameraIndex": "0",
|
||||
"videoAspect": "FullFilled",
|
||||
"fullScreen": false,
|
||||
},
|
||||
)
|
||||
: Center(
|
||||
child: Text(
|
||||
LocaleKeys.cameraFeedInactive.tr(),
|
||||
style: TextStyle(color: Colors.white70),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 20.h),
|
||||
|
||||
CustomButton(
|
||||
text: LocaleKeys.testConnection.tr(context: context),
|
||||
onPressed: () {
|
||||
_checkPermissions();
|
||||
},
|
||||
backgroundColor: AppColors.infoColor.withValues(alpha: 0.20),
|
||||
borderColor: AppColors.infoColor.withValues(alpha: 0.01),
|
||||
textColor: AppColors.infoColor,
|
||||
fontSize: 14.f,
|
||||
fontWeight: FontWeight.w600,
|
||||
borderRadius: 12.r,
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.w),
|
||||
height: 40.h,
|
||||
iconColor: AppColors.infoColor,
|
||||
iconSize: 18.h,
|
||||
icon: AppAssets.call,
|
||||
)
|
||||
|
||||
// ElevatedButton.icon(
|
||||
// icon: const Icon(Icons.sensors),
|
||||
// label: const Text('Test Permissions & Devices'),
|
||||
// onPressed: _checkPermissions,
|
||||
// )
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatusRow extends StatelessWidget {
|
||||
final String label;
|
||||
final PermissionStatus? status;
|
||||
|
||||
const _StatusRow({required this.label, this.status});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isOk = status?.isGranted ?? false;
|
||||
final icon = status == null
|
||||
? Icons.help_outline
|
||||
: isOk
|
||||
? Icons.check_circle
|
||||
: Icons.cancel;
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 4.h),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label),
|
||||
Icon(icon, color: status == null ? Colors.grey : (isOk ? Colors.green : Colors.red)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue