import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:vibration/vibration.dart'; class FloatingActionHandler with WidgetsBindingObserver { static const platform = MethodChannel('com.camelsoft.wanisdriver.ChatHeadService'); FloatingActionHandler() { WidgetsBinding.instance.addObserver(this); } void dispose() { WidgetsBinding.instance.removeObserver(this); } static Future startFloatingService() async { try { await platform.invokeMethod('startChatHeadService'); } on PlatformException catch (e) { print("Failed to start service: ${e.message}"); } } static Future stopFloatingService() async { try { await platform.invokeMethod('stopChatHeadService'); } on PlatformException catch (e) { print("Failed to stop service: ${e.message}"); } } Future vibrateOnNotification() async { if (await Vibration.hasVibrator() ?? false) { Vibration.vibrate(duration: 500); } } @override void didChangeAppLifecycleState(AppLifecycleState state) { if (state == AppLifecycleState.paused) { // App is minimized, start floating service startFloatingService(); } else if (state == AppLifecycleState.resumed) { // App is back in the foreground, stop floating service stopFloatingService(); } } }