64 lines
2.0 KiB
Dart
64 lines
2.0 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../print.dart';
|
|
|
|
/// خدمة التحكم بوضع النافذة العائمة (Picture-in-Picture) على أندرويد.
|
|
/// تُستدعى عند بدء الرحلة لتفعيل PiP تلقائياً عند خروج المستخدم من التطبيق.
|
|
class PipService {
|
|
static const MethodChannel _channel = MethodChannel('intaleq/pip');
|
|
|
|
/// هل وضع PiP مدعوم على هذا الجهاز؟
|
|
static Future<bool> isPipSupported() async {
|
|
if (!Platform.isAndroid) return false;
|
|
try {
|
|
final result = await _channel.invokeMethod<bool>('isPipSupported');
|
|
return result ?? false;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// تفعيل الدخول التلقائي لوضع PiP عند الخروج (أثناء الرحلة)
|
|
static Future<void> enablePip() async {
|
|
if (!Platform.isAndroid) return;
|
|
try {
|
|
await _channel.invokeMethod('enablePip');
|
|
} catch (e) {
|
|
Log.print('PiP enable error: \$e');
|
|
}
|
|
}
|
|
|
|
/// تعطيل الدخول التلقائي لوضع PiP (بعد انتهاء الرحلة)
|
|
static Future<void> disablePip() async {
|
|
if (!Platform.isAndroid) return;
|
|
try {
|
|
await _channel.invokeMethod('disablePip');
|
|
} catch (e) {
|
|
Log.print('PiP disable error: \$e');
|
|
}
|
|
}
|
|
|
|
/// الدخول يدوياً لوضع PiP
|
|
static Future<bool> enterPip() async {
|
|
if (!Platform.isAndroid) return false;
|
|
try {
|
|
final result = await _channel.invokeMethod<bool>('enterPip');
|
|
return result ?? false;
|
|
} catch (e) {
|
|
Log.print('PiP enter error: \$e');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// الاستماع لتغيير وضع PiP (الدخول/الخروج)
|
|
static void listenToPipChanges(Function(bool isInPip) onChanged) {
|
|
_channel.setMethodCallHandler((call) async {
|
|
if (call.method == 'onPipChanged') {
|
|
final isInPip = call.arguments as bool;
|
|
onChanged(isInPip);
|
|
}
|
|
});
|
|
}
|
|
}
|