Flutter Overlay Window Not Triggering Automatically in Background Service

I’m working on a Flutter app where I track the user’s movement (speed) using Geolocator and display different overlays based on the speed. If the speed is below 5 km/h, I want to show a “Park Mode” overlay, and if the speed is above 5 km/h, I want to show a “Drive Mode” overlay.

To achieve this, I’m using:

flutter_background_service for background tasks.
Geolocator for location tracking and speed calculation.
flutter_overlay_window_sdk34 for displaying overlays.
The app is successfully calculating the speed, but the overlays are not being triggered automatically as expected when the speed changes. The permissions for overlay windows have been granted, and I can manually display the overlays, but they do not trigger on their own in the background.

Here’s a simplified version of my implementation.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>void callbackDispatcher() {
Workmanager().executeTask((task, inputData) async {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
double speed = position.speed; // speed in m/s
double speedKmh = speed / 1000;
if (speedKmh < 5.0) {
await FlutterOverlayWindow.requestPermission();
try {
await OverlayUtils.showCustomOverlay(overlayTitle: 'Park Mode');
} catch (e) {
print("Error showing park mode overlay: $e");
}
} else if (speedKmh > 5.0) {
await FlutterOverlayWindow.requestPermission();
try {
await OverlayUtils.showCustomOverlay(overlayTitle: 'Drive Mode');
} catch (e) {
print("Error showing drive mode overlay: $e");
}
}
return Future.value(true);
});
}
</code>
<code>void callbackDispatcher() { Workmanager().executeTask((task, inputData) async { Position position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.high); double speed = position.speed; // speed in m/s double speedKmh = speed / 1000; if (speedKmh < 5.0) { await FlutterOverlayWindow.requestPermission(); try { await OverlayUtils.showCustomOverlay(overlayTitle: 'Park Mode'); } catch (e) { print("Error showing park mode overlay: $e"); } } else if (speedKmh > 5.0) { await FlutterOverlayWindow.requestPermission(); try { await OverlayUtils.showCustomOverlay(overlayTitle: 'Drive Mode'); } catch (e) { print("Error showing drive mode overlay: $e"); } } return Future.value(true); }); } </code>
void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
    Position position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.high);
    double speed = position.speed;  // speed in m/s
    double speedKmh = speed / 1000;

    if (speedKmh < 5.0) {
      await FlutterOverlayWindow.requestPermission();
      try {
        await OverlayUtils.showCustomOverlay(overlayTitle: 'Park Mode');
      } catch (e) {
        print("Error showing park mode overlay: $e");
      }
    } else if (speedKmh > 5.0) {
      await FlutterOverlayWindow.requestPermission();
      try {
        await OverlayUtils.showCustomOverlay(overlayTitle: 'Drive Mode');
      } catch (e) {
        print("Error showing drive mode overlay: $e");
      }
    }

    return Future.value(true);
  });
}

Problem:
The overlays don’t automatically trigger when the speed condition is met, even though the app correctly calculates the speed. The overlay logic works when triggered manually, but it doesn’t work as intended in the background.

What I’ve Tried:
Verifying overlay window permissions (they are granted).
Checking if the background service is running (it is).
Manually showing the overlay works fine, but not when triggered from the background task.
Question:
How can I get the overlays to trigger automatically based on the user’s speed while the app is running in the background? Is there an issue with how the background service interacts with the flutter_overlay_window_sdk34 package, or am I missing something in my implementation?

Any help or guidance would be appreciated. Thanks!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật