Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd594601f1 | |||
| 2910706e87 | |||
| d1d7521805 | |||
| 3e79a448ec |
+94
-68
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart'; // For kDebugMode
|
||||
import 'dart:async';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
@@ -8,6 +9,13 @@ import 'gps_service.dart';
|
||||
import 'color_themes.dart';
|
||||
import 'dart:math' as math; // Import for math.pi
|
||||
|
||||
// Debug helper - only prints in debug builds
|
||||
void customDebugPrint(String message) {
|
||||
if (kDebugMode) {
|
||||
print(message);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(const SpeedoApp());
|
||||
}
|
||||
@@ -15,7 +23,7 @@ void main() {
|
||||
// Entry point for overlay window
|
||||
@pragma("vm:entry-point")
|
||||
void overlayMain() {
|
||||
print('[Overlay] 🚀 overlayMain() called');
|
||||
customDebugPrint('[Overlay] 🚀 overlayMain() called');
|
||||
runApp(const MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: OverlaySpeedometer(),
|
||||
@@ -61,12 +69,45 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
bool _isInBackground = false;
|
||||
bool _isOverlayActive = false;
|
||||
|
||||
// Single source of truth for overlay sizing
|
||||
Map<String, int> _getOverlaySize() {
|
||||
final window = WidgetsBinding.instance.platformDispatcher.views.first;
|
||||
final physicalSize = window.physicalSize;
|
||||
final devicePixelRatio = window.devicePixelRatio;
|
||||
final systemSize = physicalSize / devicePixelRatio;
|
||||
|
||||
customDebugPrint('[Main] 🔍 Screen size analysis:');
|
||||
customDebugPrint(' physicalSize: ${physicalSize.width.round()}x${physicalSize.height.round()}');
|
||||
customDebugPrint(' devicePixelRatio: $devicePixelRatio');
|
||||
customDebugPrint(' calculated systemSize: ${systemSize.width.round()}x${systemSize.height.round()}');
|
||||
|
||||
// Use actual physical pixels, not scaled logical pixels
|
||||
final overlayWidth = (physicalSize.width * 0.4).round(); // 40% of actual screen width
|
||||
final overlayHeight = (overlayWidth * 0.6).round();
|
||||
|
||||
customDebugPrint(' using fixed overlay size: ${overlayWidth}x${overlayHeight}');
|
||||
|
||||
return {'width': overlayWidth, 'height': overlayHeight};
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_initializeGps();
|
||||
_enableWakelock();
|
||||
_listenToOverlayMessages();
|
||||
}
|
||||
|
||||
void _listenToOverlayMessages() {
|
||||
FlutterOverlayWindow.overlayListener.listen((data) {
|
||||
if (data is Map && data['action'] == 'overlayClosed') {
|
||||
customDebugPrint('[Main] 📡 Received overlay close notification');
|
||||
setState(() {
|
||||
_isOverlayActive = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _enableWakelock() async {
|
||||
@@ -162,20 +203,11 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
final speedText = displaySpeed < 1.0 ? '--' : displaySpeed.toInt().toString();
|
||||
final headingText = GpsService.formatHeading(_heading);
|
||||
|
||||
// Get system screen size to share with overlay
|
||||
final window = WidgetsBinding.instance.platformDispatcher.views.first;
|
||||
final systemSize = window.physicalSize / window.devicePixelRatio;
|
||||
|
||||
print('[Main] 📤 SENDING to overlay:');
|
||||
print(' speedText: "$speedText"');
|
||||
print(' headingText: "$headingText"');
|
||||
print(' direction: ${_heading.toStringAsFixed(1)}°');
|
||||
print(' unit: ${_currentUnit.label}, theme: $_currentThemeIndex');
|
||||
print(' systemScreen: ${systemSize.width.round()}x${systemSize.height.round()}');
|
||||
|
||||
// Calculate overlay size the same way as when launching
|
||||
final overlayWidth = (systemSize.width * 0.4).round();
|
||||
final overlayHeight = (overlayWidth * 0.5).round();
|
||||
customDebugPrint('[Main] 📤 SENDING to overlay:');
|
||||
customDebugPrint(' speedText: "$speedText"');
|
||||
customDebugPrint(' headingText: "$headingText"');
|
||||
customDebugPrint(' direction: ${_heading.toStringAsFixed(1)}°');
|
||||
customDebugPrint(' unit: ${_currentUnit.label}, theme: $_currentThemeIndex');
|
||||
|
||||
FlutterOverlayWindow.shareData({
|
||||
'action': 'updateDisplay',
|
||||
@@ -184,10 +216,6 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
'heading': _heading,
|
||||
'unitIndex': _currentUnit.index,
|
||||
'themeIndex': _currentThemeIndex,
|
||||
'systemScreenWidth': systemSize.width,
|
||||
'systemScreenHeight': systemSize.height,
|
||||
'overlayWidth': overlayWidth.clamp(280, 480).toDouble(),
|
||||
'overlayHeight': overlayHeight.clamp(140, 240).toDouble(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -209,17 +237,10 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
|
||||
Future<void> _showFloatingWindow() async {
|
||||
try {
|
||||
// Get actual system screen resolution for proportional sizing
|
||||
final window = WidgetsBinding.instance.platformDispatcher.views.first;
|
||||
final systemSize = window.physicalSize / window.devicePixelRatio;
|
||||
final overlayWidth = (systemSize.width * 0.4).round(); // 40% of system screen width
|
||||
final overlayHeight = (overlayWidth * 0.5).round(); // 2:1 aspect ratio
|
||||
// Use centralized sizing function
|
||||
final overlaySize = _getOverlaySize();
|
||||
|
||||
// Debug info for development
|
||||
// print('[Main] System resolution: ${systemSize.width.round()}x${systemSize.height.round()}');
|
||||
// print('[Main] Calculated overlay size: ${overlayWidth}x${overlayHeight}');
|
||||
|
||||
// Send initial display data to overlay including screen size
|
||||
// Send initial display data WITH size info (only needed on creation)
|
||||
final displaySpeed = _currentUnit.convert(_speed);
|
||||
final speedText = displaySpeed < 1.0 ? '--' : displaySpeed.toInt().toString();
|
||||
final headingText = GpsService.formatHeading(_heading);
|
||||
@@ -231,10 +252,8 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
'heading': _heading,
|
||||
'unitIndex': _currentUnit.index,
|
||||
'themeIndex': _currentThemeIndex,
|
||||
'systemScreenWidth': systemSize.width,
|
||||
'systemScreenHeight': systemSize.height,
|
||||
'overlayWidth': overlayWidth.clamp(280, 480).toDouble(),
|
||||
'overlayHeight': overlayHeight.clamp(140, 240).toDouble(),
|
||||
'overlayWidth': overlaySize['width']!.toDouble(),
|
||||
'overlayHeight': overlaySize['height']!.toDouble(),
|
||||
});
|
||||
|
||||
// Show the overlay with proportional sizing based on system resolution
|
||||
@@ -245,12 +264,12 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
flag: OverlayFlag.defaultFlag,
|
||||
visibility: NotificationVisibility.visibilityPublic,
|
||||
positionGravity: PositionGravity.none,
|
||||
// Use system-based proportional sizing with reasonable limits
|
||||
width: overlayWidth.clamp(280, 480),
|
||||
height: overlayHeight.clamp(140, 240),
|
||||
// Use consistent sizing from centralized function
|
||||
width: overlaySize['width']!,
|
||||
height: overlaySize['height']!,
|
||||
);
|
||||
|
||||
print('[Main] 🟢 OVERLAY LAUNCHED - Size: ${overlayWidth.clamp(280, 480)}x${overlayHeight.clamp(140, 240)}');
|
||||
customDebugPrint('[Main] 🟢 OVERLAY LAUNCHED - Size: ${overlaySize['width']}x${overlaySize['height']}');
|
||||
setState(() {
|
||||
_isOverlayActive = true;
|
||||
});
|
||||
@@ -261,18 +280,18 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
|
||||
Future<void> _closeFloatingWindow() async {
|
||||
if (!_isOverlayActive) {
|
||||
print('[Main] ⚠️ No overlay to close');
|
||||
customDebugPrint('[Main] ⚠️ No overlay to close');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await FlutterOverlayWindow.closeOverlay();
|
||||
print('[Main] 🔴 OVERLAY CLOSED - Requested from main app');
|
||||
customDebugPrint('[Main] 🔴 OVERLAY CLOSED - Requested from main app');
|
||||
setState(() {
|
||||
_isOverlayActive = false;
|
||||
});
|
||||
} catch (e) {
|
||||
print('[Main] ❌ Error closing overlay: $e');
|
||||
customDebugPrint('[Main] ❌ Error closing overlay: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +434,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
flex: 32,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
print('[Main] 🖱️ Navigation area tapped - overlay active: $_isOverlayActive');
|
||||
customDebugPrint('[Main] 🖱️ Navigation area tapped - overlay active: $_isOverlayActive');
|
||||
if (_isOverlayActive) {
|
||||
_closeFloatingWindow();
|
||||
} else {
|
||||
@@ -423,7 +442,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
print('[Main] 🖱️ Navigation area long-pressed - overlay active: $_isOverlayActive');
|
||||
customDebugPrint('[Main] 🖱️ Navigation area long-pressed - overlay active: $_isOverlayActive');
|
||||
_closeFloatingWindow();
|
||||
},
|
||||
child: Container(
|
||||
@@ -541,7 +560,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
flex: 33,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
print('[Main] 🖱️ Navigation area tapped (landscape) - overlay active: $_isOverlayActive');
|
||||
customDebugPrint('[Main] 🖱️ Navigation area tapped (landscape) - overlay active: $_isOverlayActive');
|
||||
if (_isOverlayActive) {
|
||||
_closeFloatingWindow();
|
||||
} else {
|
||||
@@ -549,7 +568,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
print('[Main] 🖱️ Navigation area long-pressed (landscape) - overlay active: $_isOverlayActive');
|
||||
customDebugPrint('[Main] 🖱️ Navigation area long-pressed (landscape) - overlay active: $_isOverlayActive');
|
||||
_closeFloatingWindow();
|
||||
},
|
||||
child: Container(
|
||||
@@ -616,7 +635,7 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
print('[Overlay] 🟢 CREATED - Floating window initialized');
|
||||
customDebugPrint('[Overlay] 🟢 CREATED - Floating window initialized');
|
||||
_getSystemScreenSize();
|
||||
_listenToMainAppMessages();
|
||||
}
|
||||
@@ -629,18 +648,18 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
||||
final devicePixelRatio = window.devicePixelRatio;
|
||||
final systemSize = physicalSize / devicePixelRatio;
|
||||
|
||||
print('[Overlay] 🔍 Screen detection:');
|
||||
print(' physicalSize: ${physicalSize.width.round()}x${physicalSize.height.round()}');
|
||||
print(' devicePixelRatio: $devicePixelRatio');
|
||||
print(' calculated systemSize: ${systemSize.width.round()}x${systemSize.height.round()}');
|
||||
customDebugPrint('[Overlay] 🔍 Screen detection:');
|
||||
customDebugPrint(' physicalSize: ${physicalSize.width.round()}x${physicalSize.height.round()}');
|
||||
customDebugPrint(' devicePixelRatio: $devicePixelRatio');
|
||||
customDebugPrint(' calculated systemSize: ${systemSize.width.round()}x${systemSize.height.round()}');
|
||||
|
||||
setState(() {
|
||||
_systemScreenWidth = systemSize.width;
|
||||
});
|
||||
|
||||
print('[Overlay] ✅ _systemScreenWidth set to: ${_systemScreenWidth.round()}');
|
||||
customDebugPrint('[Overlay] ✅ _systemScreenWidth set to: ${_systemScreenWidth.round()}');
|
||||
} catch (e) {
|
||||
print('[Overlay] ❌ Error getting system screen size: $e');
|
||||
customDebugPrint('[Overlay] ❌ Error getting system screen size: $e');
|
||||
// Fallback to reasonable default
|
||||
setState(() {
|
||||
_systemScreenWidth = 400;
|
||||
@@ -668,20 +687,20 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
||||
}
|
||||
});
|
||||
|
||||
print('[Overlay] 📡 UPDATE received:');
|
||||
print(' speedText: "$_speedText"');
|
||||
print(' headingText: "$_headingText"');
|
||||
print(' direction: ${_heading.toStringAsFixed(1)}°');
|
||||
print(' themeIndex: $_currentThemeIndex');
|
||||
print(' systemScreenWidth: ${_systemScreenWidth.round()}');
|
||||
print(' overlaySize from main: ${_overlayWidth.round()}x${_overlayHeight.round()}');
|
||||
customDebugPrint('[Overlay] 📡 UPDATE received:');
|
||||
customDebugPrint(' speedText: "$_speedText"');
|
||||
customDebugPrint(' headingText: "$_headingText"');
|
||||
customDebugPrint(' direction: ${_heading.toStringAsFixed(1)}°');
|
||||
customDebugPrint(' themeIndex: $_currentThemeIndex');
|
||||
customDebugPrint(' systemScreenWidth: ${_systemScreenWidth.round()}');
|
||||
customDebugPrint(' overlaySize from main: ${_overlayWidth.round()}x${_overlayHeight.round()}');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
print('[Overlay] 🔴 DESTROYED - Floating window disposed');
|
||||
customDebugPrint('[Overlay] 🔴 DESTROYED - Floating window disposed');
|
||||
// No GPS subscription to cancel - overlay is display-only
|
||||
super.dispose();
|
||||
}
|
||||
@@ -693,7 +712,7 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
||||
// Use overlay dimensions provided by main app (not calculated locally)
|
||||
final fontSize = (_overlayWidth * 0.2); // Font size proportional to actual overlay width
|
||||
|
||||
print('[Overlay] 📐 Window size: ${_overlayWidth.round()}x${_overlayHeight.round()}, fontSize: ${fontSize.round()}');
|
||||
customDebugPrint('[Overlay] 📐 Window size: ${_overlayWidth.round()}x${_overlayHeight.round()}, fontSize: ${fontSize.round()}');
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
@@ -724,7 +743,7 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: Text(
|
||||
_speedText,
|
||||
(_speedText == "--" ? "0" : _speedText),
|
||||
style: TextStyle(
|
||||
fontSize: fontSize,
|
||||
fontWeight: FontWeight.w300,
|
||||
@@ -783,22 +802,29 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
||||
top: 4,
|
||||
right: 4,
|
||||
child: GestureDetector(
|
||||
onTap: () => FlutterOverlayWindow.closeOverlay(),
|
||||
onTap: () {
|
||||
customDebugPrint('[Overlay] 🔴 Close button tapped');
|
||||
// Notify main app that overlay is closing
|
||||
FlutterOverlayWindow.shareData({
|
||||
'action': 'overlayClosed',
|
||||
});
|
||||
FlutterOverlayWindow.closeOverlay();
|
||||
},
|
||||
child: Container(
|
||||
width: _overlayHeight * 0.2,
|
||||
height: _overlayHeight * 0.2,
|
||||
width: 18,
|
||||
height: 18, // fixed
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red.withOpacity(0.6),
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(_overlayHeight * 0.1),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
color: currentTheme.speedTextSub.withOpacity(0.9),
|
||||
width: 1
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
size: _overlayHeight * 0.15,
|
||||
color: currentTheme.speedText.withOpacity(0.9),
|
||||
size: 15,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ name: gps_speedo
|
||||
description: "Speedo - A Flutter application."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 2.1.0+2
|
||||
version: 2.2.0+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.9.0
|
||||
|
||||
Reference in New Issue
Block a user