Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ae660156e | |||
| 9cd497f4f5 | |||
| 057f33fc50 | |||
| 550755fad9 | |||
| 940aaee135 | |||
| 6c9bada84d |
@@ -15,7 +15,8 @@
|
|||||||
"Bash(powershell:*)",
|
"Bash(powershell:*)",
|
||||||
"WebFetch(domain:docs.anthropic.com)",
|
"WebFetch(domain:docs.anthropic.com)",
|
||||||
"WebSearch",
|
"WebSearch",
|
||||||
"WebFetch(domain:pub.dev)"
|
"WebFetch(domain:pub.dev)",
|
||||||
|
"Bash(git commit:*)"
|
||||||
],
|
],
|
||||||
"defaultMode": "acceptEdits"
|
"defaultMode": "acceptEdits"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,21 +25,29 @@ A customizable Flutter GPS speedometer app targeting Android devices, emphasizin
|
|||||||
|
|
||||||
### Technical Stack
|
### Technical Stack
|
||||||
```
|
```
|
||||||
Dependencies: geolocator, permission_handler, provider, shared_preferences, flutter_material_color_picker
|
Dependencies: geolocator, permission_handler, provider, shared_preferences, flutter_material_color_picker, flutter_overlay_window
|
||||||
Platforms: Android (primary), iOS support included but untested
|
Platforms: Android (primary), iOS support included but untested
|
||||||
Architecture: Provider + Consumer pattern for reactive state management
|
Architecture: Provider + Consumer pattern for reactive state management
|
||||||
Permissions: Location services with graceful degradation
|
Permissions: Location services + SYSTEM_ALERT_WINDOW for overlay functionality
|
||||||
```
|
```
|
||||||
|
|
||||||
## Recent Updates (v2.1.0)
|
## Recent Updates (v2.1.0)
|
||||||
|
|
||||||
### ✅ Completed Features
|
### ✅ Completed Features (Master Branch - Stable)
|
||||||
- [x] **Floating Window Overlay**: System-level overlay window for persistent speed display
|
- [x] **Split Decimal Display**: Main speed prominent with smaller, faded decimal fraction for better readability
|
||||||
- [x] **Split Decimal Display**: Main speed prominent, decimal fraction smaller and faded
|
- [x] **Optimized Content Sizing**: Maximized readability with improved responsive layout and flex ratios
|
||||||
- [x] **Optimized Content Sizing**: Maximized readability with improved flex ratios
|
- [x] **Basic Floating Window**: Simple overlay with "GPS SPEEDO" text and close button (stable implementation)
|
||||||
- [x] **Navigation Icon Trigger**: Tap compass area to launch floating window
|
- [x] **Navigation Icon Trigger**: Tap compass/navigation area to launch floating window overlay
|
||||||
- [x] **Multiple Close Options**: Overlay close button and long-press navigation area
|
- [x] **Multiple Close Options**: Overlay close button and long-press navigation area for easy dismissal
|
||||||
- [x] **Android Permissions**: SYSTEM_ALERT_WINDOW and foreground service support
|
- [x] **Android System Integration**: SYSTEM_ALERT_WINDOW permissions and foreground service configuration
|
||||||
|
|
||||||
|
### 🚧 Work in Progress Features (dev/floating-window-wip Branch - Seriously Buggy)
|
||||||
|
- [ ] **Advanced Floating Window Overlay**: System-level overlay with live GPS data - basic functionality works but seriously buggy
|
||||||
|
- GPS data synchronization implemented but unreliable
|
||||||
|
- Theme/unit sync between main app and overlay works partially
|
||||||
|
- Proportional sizing and positioning needs major refinement
|
||||||
|
- Close button functionality works but overlay behavior inconsistent
|
||||||
|
- Performance may impact main app, needs optimization
|
||||||
|
|
||||||
### Previous Updates (v1.1)
|
### Previous Updates (v1.1)
|
||||||
- [x] **Portrait/Landscape Support**: Automatic orientation detection implemented
|
- [x] **Portrait/Landscape Support**: Automatic orientation detection implemented
|
||||||
@@ -48,10 +56,19 @@ Permissions: Location services with graceful degradation
|
|||||||
|
|
||||||
## TODO - Future Improvements
|
## TODO - Future Improvements
|
||||||
|
|
||||||
### Critical Issues
|
### Known Issues
|
||||||
- [ ] **Dependency Updates**: Update 10 packages to latest compatible versions
|
|
||||||
|
**Master Branch (v2.1.0 - Stable):**
|
||||||
|
- [ ] **Dependency Updates**: Update packages to latest compatible versions
|
||||||
- [ ] **Orientation Override**: Fix auto-rotate to work regardless of system toggle status
|
- [ ] **Orientation Override**: Fix auto-rotate to work regardless of system toggle status
|
||||||
|
|
||||||
|
**Dev Branch (floating-window-wip - Seriously Buggy):**
|
||||||
|
- [ ] **Floating Window Reliability**: Overlay behavior inconsistent across different devices and Android versions
|
||||||
|
- [ ] **GPS Data Sync**: Real-time GPS synchronization between main app and overlay unreliable
|
||||||
|
- [ ] **Theme/Unit Sync**: Setting synchronization works partially but not consistently
|
||||||
|
- [ ] **Overlay Positioning**: Poor positioning stability, sizing calculations need major work
|
||||||
|
- [ ] **Performance**: Overlay may impact main app performance, needs optimization
|
||||||
|
|
||||||
### UI/UX Enhancements
|
### UI/UX Enhancements
|
||||||
- [ ] **Background Customization**: Custom background color selection
|
- [ ] **Background Customization**: Custom background color selection
|
||||||
- [ ] **Interface Rearrangement**: User-defined layout customization
|
- [ ] **Interface Rearrangement**: User-defined layout customization
|
||||||
@@ -74,6 +91,11 @@ Permissions: Location services with graceful degradation
|
|||||||
- **Memory**: Project uses automatic Claude Code memory - this file for major decisions only
|
- **Memory**: Project uses automatic Claude Code memory - this file for major decisions only
|
||||||
- **Git**: Active repository at `https://github.com/mikkelimatlock/gps_speedo`
|
- **Git**: Active repository at `https://github.com/mikkelimatlock/gps_speedo`
|
||||||
|
|
||||||
|
## Branch Strategy
|
||||||
|
- **master**: Stable releases, ready for production APK builds
|
||||||
|
- **dev/floating-window-wip**: Advanced floating window development (seriously buggy, not for release)
|
||||||
|
- Tagged releases: v2.1.0 on master branch contains stable basic floating window
|
||||||
|
|
||||||
## Code Patterns to Maintain
|
## Code Patterns to Maintain
|
||||||
- Provider pattern for state management
|
- Provider pattern for state management
|
||||||
- Separate widgets for reusability
|
- Separate widgets for reusability
|
||||||
|
|||||||
+301
-106
@@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:geolocator/geolocator.dart';
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||||
@@ -16,57 +15,10 @@ void main() {
|
|||||||
// Entry point for overlay window
|
// Entry point for overlay window
|
||||||
@pragma("vm:entry-point")
|
@pragma("vm:entry-point")
|
||||||
void overlayMain() {
|
void overlayMain() {
|
||||||
runApp(MaterialApp(
|
print('[Overlay] 🚀 overlayMain() called');
|
||||||
|
runApp(const MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: Scaffold(
|
home: OverlaySpeedometer(),
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
body: Container(
|
|
||||||
width: 180,
|
|
||||||
height: 100,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black.withOpacity(0.8),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(color: Colors.green.withOpacity(0.7), width: 2),
|
|
||||||
),
|
|
||||||
child: Stack(
|
|
||||||
children: [
|
|
||||||
const Center(
|
|
||||||
child: Text(
|
|
||||||
'GPS\nSPEEDO',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.green,
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Close button
|
|
||||||
Positioned(
|
|
||||||
top: 4,
|
|
||||||
right: 4,
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () => FlutterOverlayWindow.closeOverlay(),
|
|
||||||
child: Container(
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.red.withOpacity(0.8),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(color: Colors.white, width: 1),
|
|
||||||
),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.close,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +59,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
StreamSubscription<Position>? _positionSubscription;
|
StreamSubscription<Position>? _positionSubscription;
|
||||||
String _errorMessage = '';
|
String _errorMessage = '';
|
||||||
bool _isInBackground = false;
|
bool _isInBackground = false;
|
||||||
|
bool _isOverlayActive = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -157,8 +110,6 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
|
|
||||||
void _handleBackgroundTransition() {
|
void _handleBackgroundTransition() {
|
||||||
// When app goes to background, show floating window if GPS is active and no error
|
// When app goes to background, show floating window if GPS is active and no error
|
||||||
print('App went to background, checking conditions for floating window...');
|
|
||||||
print('Speed: $_speed, Error: $_errorMessage');
|
|
||||||
// Temporarily disable auto-trigger for debugging
|
// Temporarily disable auto-trigger for debugging
|
||||||
// if (_speed >= 0 && _errorMessage.isEmpty) {
|
// if (_speed >= 0 && _errorMessage.isEmpty) {
|
||||||
// _showFloatingWindow();
|
// _showFloatingWindow();
|
||||||
@@ -200,29 +151,93 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
_heading = position.heading;
|
_heading = position.heading;
|
||||||
_errorMessage = '';
|
_errorMessage = '';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Push display data to overlay if active
|
||||||
|
_pushDataToOverlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _pushDataToOverlay() {
|
||||||
|
// Send complete display data to overlay including screen size
|
||||||
|
final displaySpeed = _currentUnit.convert(_speed);
|
||||||
|
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();
|
||||||
|
|
||||||
|
FlutterOverlayWindow.shareData({
|
||||||
|
'action': 'updateDisplay',
|
||||||
|
'speedText': speedText,
|
||||||
|
'headingText': headingText,
|
||||||
|
'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(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _cycleUnit() {
|
void _cycleUnit() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentUnit = _currentUnit.next;
|
_currentUnit = _currentUnit.next;
|
||||||
});
|
});
|
||||||
|
// Push updated display data to overlay
|
||||||
|
_pushDataToOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _cycleTheme() {
|
void _cycleTheme() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentThemeIndex = ColorThemes.getNextThemeIndex(_currentThemeIndex);
|
_currentThemeIndex = ColorThemes.getNextThemeIndex(_currentThemeIndex);
|
||||||
});
|
});
|
||||||
|
// Push updated display data to overlay
|
||||||
|
_pushDataToOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _showFloatingWindow() async {
|
Future<void> _showFloatingWindow() async {
|
||||||
try {
|
try {
|
||||||
// Share current unit with overlay
|
// 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
|
||||||
|
|
||||||
|
// 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
|
||||||
|
final displaySpeed = _currentUnit.convert(_speed);
|
||||||
|
final speedText = displaySpeed < 1.0 ? '--' : displaySpeed.toInt().toString();
|
||||||
|
final headingText = GpsService.formatHeading(_heading);
|
||||||
|
|
||||||
await FlutterOverlayWindow.shareData({
|
await FlutterOverlayWindow.shareData({
|
||||||
'action': 'updateUnit',
|
'action': 'updateDisplay',
|
||||||
|
'speedText': speedText,
|
||||||
|
'headingText': headingText,
|
||||||
|
'heading': _heading,
|
||||||
'unitIndex': _currentUnit.index,
|
'unitIndex': _currentUnit.index,
|
||||||
|
'themeIndex': _currentThemeIndex,
|
||||||
|
'systemScreenWidth': systemSize.width,
|
||||||
|
'systemScreenHeight': systemSize.height,
|
||||||
|
'overlayWidth': overlayWidth.clamp(280, 480).toDouble(),
|
||||||
|
'overlayHeight': overlayHeight.clamp(140, 240).toDouble(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show the overlay with safer positioning
|
// Show the overlay with proportional sizing based on system resolution
|
||||||
await FlutterOverlayWindow.showOverlay(
|
await FlutterOverlayWindow.showOverlay(
|
||||||
enableDrag: true,
|
enableDrag: true,
|
||||||
overlayTitle: "GPS Speedometer",
|
overlayTitle: "GPS Speedometer",
|
||||||
@@ -230,19 +245,34 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
flag: OverlayFlag.defaultFlag,
|
flag: OverlayFlag.defaultFlag,
|
||||||
visibility: NotificationVisibility.visibilityPublic,
|
visibility: NotificationVisibility.visibilityPublic,
|
||||||
positionGravity: PositionGravity.none,
|
positionGravity: PositionGravity.none,
|
||||||
width: 180,
|
// Use system-based proportional sizing with reasonable limits
|
||||||
height: 100,
|
width: overlayWidth.clamp(280, 480),
|
||||||
|
height: overlayHeight.clamp(140, 240),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
print('[Main] 🟢 OVERLAY LAUNCHED - Size: ${overlayWidth.clamp(280, 480)}x${overlayHeight.clamp(140, 240)}');
|
||||||
|
setState(() {
|
||||||
|
_isOverlayActive = true;
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error showing floating window: $e');
|
// Silent error handling - floating window issues shouldn't crash main app
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _closeFloatingWindow() async {
|
Future<void> _closeFloatingWindow() async {
|
||||||
|
if (!_isOverlayActive) {
|
||||||
|
print('[Main] ⚠️ No overlay to close');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await FlutterOverlayWindow.closeOverlay();
|
await FlutterOverlayWindow.closeOverlay();
|
||||||
|
print('[Main] 🔴 OVERLAY CLOSED - Requested from main app');
|
||||||
|
setState(() {
|
||||||
|
_isOverlayActive = false;
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error closing floating window: $e');
|
print('[Main] ❌ Error closing overlay: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +357,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
children: [
|
children: [
|
||||||
// Speed area - takes most space, precise tap targets on text only
|
// Speed area - takes most space, precise tap targets on text only
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 7,
|
flex: 65,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
@@ -382,10 +412,20 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
),
|
),
|
||||||
// Compass area - compact but fully tappable for floating window
|
// Compass area - compact but fully tappable for floating window
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 3,
|
flex: 32,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: _showFloatingWindow, // Tap navigation icon to show floating window
|
onTap: () {
|
||||||
onLongPress: _closeFloatingWindow, // Long press to close floating window
|
print('[Main] 🖱️ Navigation area tapped - overlay active: $_isOverlayActive');
|
||||||
|
if (_isOverlayActive) {
|
||||||
|
_closeFloatingWindow();
|
||||||
|
} else {
|
||||||
|
_showFloatingWindow();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
print('[Main] 🖱️ Navigation area long-pressed - overlay active: $_isOverlayActive');
|
||||||
|
_closeFloatingWindow();
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
@@ -457,7 +497,11 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
)
|
)
|
||||||
else ...[
|
else ...[
|
||||||
Flexible(
|
Flexible(
|
||||||
flex: 4,
|
flex: 1,
|
||||||
|
child: FittedBox(),
|
||||||
|
),
|
||||||
|
Flexible(
|
||||||
|
flex: 20,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: _cycleTheme,
|
onTap: _cycleTheme,
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
@@ -467,7 +511,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Flexible(
|
Flexible(
|
||||||
flex: 1,
|
flex: 7,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: _cycleUnit,
|
onTap: _cycleUnit,
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
@@ -483,6 +527,10 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Flexible(
|
||||||
|
flex: 5,
|
||||||
|
child: FittedBox(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -492,8 +540,18 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
Expanded(
|
Expanded(
|
||||||
flex: 33,
|
flex: 33,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: _showFloatingWindow,
|
onTap: () {
|
||||||
onLongPress: _closeFloatingWindow, // Long press to close floating window
|
print('[Main] 🖱️ Navigation area tapped (landscape) - overlay active: $_isOverlayActive');
|
||||||
|
if (_isOverlayActive) {
|
||||||
|
_closeFloatingWindow();
|
||||||
|
} else {
|
||||||
|
_showFloatingWindow();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
print('[Main] 🖱️ Navigation area long-pressed (landscape) - overlay active: $_isOverlayActive');
|
||||||
|
_closeFloatingWindow();
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: double.infinity,
|
height: double.infinity,
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
@@ -539,72 +597,208 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SimpleOverlaySpeedometer extends StatelessWidget {
|
class OverlaySpeedometer extends StatefulWidget {
|
||||||
const SimpleOverlaySpeedometer({super.key});
|
const OverlaySpeedometer({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<OverlaySpeedometer> createState() => _OverlaySpeedometerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
||||||
|
String _speedText = '--';
|
||||||
|
String _headingText = 'N/A';
|
||||||
|
double _heading = -1.0;
|
||||||
|
int _currentThemeIndex = 0;
|
||||||
|
double _systemScreenWidth = 400;
|
||||||
|
double _overlayWidth = 280;
|
||||||
|
double _overlayHeight = 140;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
print('[Overlay] 🟢 CREATED - Floating window initialized');
|
||||||
|
_getSystemScreenSize();
|
||||||
|
_listenToMainAppMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _getSystemScreenSize() {
|
||||||
|
try {
|
||||||
|
// Get actual system screen resolution, not just app window size
|
||||||
|
final window = WidgetsBinding.instance.platformDispatcher.views.first;
|
||||||
|
final physicalSize = window.physicalSize;
|
||||||
|
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()}');
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_systemScreenWidth = systemSize.width;
|
||||||
|
});
|
||||||
|
|
||||||
|
print('[Overlay] ✅ _systemScreenWidth set to: ${_systemScreenWidth.round()}');
|
||||||
|
} catch (e) {
|
||||||
|
print('[Overlay] ❌ Error getting system screen size: $e');
|
||||||
|
// Fallback to reasonable default
|
||||||
|
setState(() {
|
||||||
|
_systemScreenWidth = 400;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _listenToMainAppMessages() {
|
||||||
|
FlutterOverlayWindow.overlayListener.listen((data) {
|
||||||
|
if (data is Map && data['action'] == 'updateDisplay') {
|
||||||
|
setState(() {
|
||||||
|
_speedText = data['speedText'] ?? '--';
|
||||||
|
_headingText = data['headingText'] ?? 'N/A';
|
||||||
|
_heading = data['heading']?.toDouble() ?? -1.0;
|
||||||
|
_currentThemeIndex = data['themeIndex'] ?? 0;
|
||||||
|
// Update screen size and overlay dimensions if provided by main app
|
||||||
|
if (data.containsKey('systemScreenWidth')) {
|
||||||
|
_systemScreenWidth = data['systemScreenWidth']?.toDouble() ?? _systemScreenWidth;
|
||||||
|
}
|
||||||
|
if (data.containsKey('overlayWidth')) {
|
||||||
|
_overlayWidth = data['overlayWidth']?.toDouble() ?? _overlayWidth;
|
||||||
|
}
|
||||||
|
if (data.containsKey('overlayHeight')) {
|
||||||
|
_overlayHeight = data['overlayHeight']?.toDouble() ?? _overlayHeight;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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()}');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
print('[Overlay] 🔴 DESTROYED - Floating window disposed');
|
||||||
|
// No GPS subscription to cancel - overlay is display-only
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
print("SimpleOverlaySpeedometer build() called");
|
final currentTheme = ColorThemes.getTheme(_currentThemeIndex);
|
||||||
|
|
||||||
|
// 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()}');
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
|
child: SizedBox(
|
||||||
|
// Use SizedBox to fill the overlay window completely
|
||||||
|
width: double.infinity,
|
||||||
|
height: double.infinity,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 200,
|
|
||||||
height: 120,
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.red.withOpacity(0.9), // Highly visible red background
|
color: currentTheme.background.withOpacity(0.85),
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(color: Colors.yellow, width: 3), // Bright yellow border
|
border: Border.all(
|
||||||
|
color: currentTheme.speedText.withOpacity(0.3),
|
||||||
|
width: 1
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
// Test content - much more visible
|
// Main content - landscape layout (1:1 flex as per NOTES.txt)
|
||||||
Center(
|
Row(
|
||||||
|
children: [
|
||||||
|
// Speed section - left half
|
||||||
|
Expanded(
|
||||||
|
flex: 1,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: Center(
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
child: Text(
|
||||||
|
_speedText,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: fontSize,
|
||||||
|
fontWeight: FontWeight.w300,
|
||||||
|
color: currentTheme.speedText,
|
||||||
|
fontFamily: 'DIN1451Alt',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Direction section - right half (same as full-screen behavior)
|
||||||
|
Expanded(
|
||||||
|
flex: 1,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
Flexible(
|
||||||
'FLOATING',
|
flex: 2,
|
||||||
|
child: Transform.rotate(
|
||||||
|
angle: (_heading >= 0 && _heading < 360) ? (_heading * math.pi / 180.0) : 0,
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
child: Icon(
|
||||||
|
Icons.navigation,
|
||||||
|
size: fontSize * 0.8,
|
||||||
|
color: currentTheme.headingText,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Flexible(
|
||||||
|
flex: 1,
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
child: Text(
|
||||||
|
_headingText,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 20,
|
fontSize: fontSize * 0.4,
|
||||||
fontWeight: FontWeight.bold,
|
color: currentTheme.headingText,
|
||||||
color: Colors.white,
|
fontFamily: 'DIN1451Alt',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Text(
|
|
||||||
'WINDOW',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.yellow,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Text(
|
|
||||||
'WORKING!',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Close button
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
// Semi-transparent close button (only interaction as per NOTES.txt)
|
||||||
Positioned(
|
Positioned(
|
||||||
top: 2,
|
top: 4,
|
||||||
right: 2,
|
right: 4,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () => FlutterOverlayWindow.closeOverlay(),
|
onTap: () => FlutterOverlayWindow.closeOverlay(),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 20,
|
width: _overlayHeight * 0.2,
|
||||||
height: 20,
|
height: _overlayHeight * 0.2,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color.fromARGB(255, 255, 171, 16), // call the current background colour defined as in `color_themes.dart`
|
color: Colors.red.withOpacity(0.6),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(_overlayHeight * 0.1),
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.white.withOpacity(0.8),
|
||||||
|
width: 1
|
||||||
),
|
),
|
||||||
child: const Icon(
|
),
|
||||||
|
child: Icon(
|
||||||
Icons.close,
|
Icons.close,
|
||||||
color: Colors.white,
|
color: Colors.white.withOpacity(0.9),
|
||||||
size: 12,
|
size: _overlayHeight * 0.15,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -612,6 +806,7 @@ class SimpleOverlaySpeedometer extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user