Make debug output production-ready with conditional printing
- Add kDebugMode conditional debug output using debugPrint() helper - All debug messages (🚀🟢🔴📡📤📐🖱️) only appear in debug builds - Release builds will be clean without console spam - Maintains full debug visibility during development This ensures production APKs have no debug console output while preserving comprehensive debugging capabilities for development. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+41
-33
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/foundation.dart'; // For kDebugMode
|
||||||
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';
|
||||||
@@ -8,6 +9,13 @@ import 'gps_service.dart';
|
|||||||
import 'color_themes.dart';
|
import 'color_themes.dart';
|
||||||
import 'dart:math' as math; // Import for math.pi
|
import 'dart:math' as math; // Import for math.pi
|
||||||
|
|
||||||
|
// Debug helper - only prints in debug builds
|
||||||
|
void debugPrint(String message) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
debugPrint(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const SpeedoApp());
|
runApp(const SpeedoApp());
|
||||||
}
|
}
|
||||||
@@ -15,7 +23,7 @@ void main() {
|
|||||||
// Entry point for overlay window
|
// Entry point for overlay window
|
||||||
@pragma("vm:entry-point")
|
@pragma("vm:entry-point")
|
||||||
void overlayMain() {
|
void overlayMain() {
|
||||||
print('[Overlay] 🚀 overlayMain() called');
|
debugPrint('[Overlay] 🚀 overlayMain() called');
|
||||||
runApp(const MaterialApp(
|
runApp(const MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
home: OverlaySpeedometer(),
|
home: OverlaySpeedometer(),
|
||||||
@@ -166,12 +174,12 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
final window = WidgetsBinding.instance.platformDispatcher.views.first;
|
final window = WidgetsBinding.instance.platformDispatcher.views.first;
|
||||||
final systemSize = window.physicalSize / window.devicePixelRatio;
|
final systemSize = window.physicalSize / window.devicePixelRatio;
|
||||||
|
|
||||||
print('[Main] 📤 SENDING to overlay:');
|
debugPrint('[Main] 📤 SENDING to overlay:');
|
||||||
print(' speedText: "$speedText"');
|
debugPrint(' speedText: "$speedText"');
|
||||||
print(' headingText: "$headingText"');
|
debugPrint(' headingText: "$headingText"');
|
||||||
print(' direction: ${_heading.toStringAsFixed(1)}°');
|
debugPrint(' direction: ${_heading.toStringAsFixed(1)}°');
|
||||||
print(' unit: ${_currentUnit.label}, theme: $_currentThemeIndex');
|
debugPrint(' unit: ${_currentUnit.label}, theme: $_currentThemeIndex');
|
||||||
print(' systemScreen: ${systemSize.width.round()}x${systemSize.height.round()}');
|
debugPrint(' systemScreen: ${systemSize.width.round()}x${systemSize.height.round()}');
|
||||||
|
|
||||||
// Calculate overlay size the same way as when launching
|
// Calculate overlay size the same way as when launching
|
||||||
final overlayWidth = (systemSize.width * 0.4).round();
|
final overlayWidth = (systemSize.width * 0.4).round();
|
||||||
@@ -216,8 +224,8 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
final overlayHeight = (overlayWidth * 0.5).round(); // 2:1 aspect ratio
|
final overlayHeight = (overlayWidth * 0.5).round(); // 2:1 aspect ratio
|
||||||
|
|
||||||
// Debug info for development
|
// Debug info for development
|
||||||
// print('[Main] System resolution: ${systemSize.width.round()}x${systemSize.height.round()}');
|
// debugPrint('[Main] System resolution: ${systemSize.width.round()}x${systemSize.height.round()}');
|
||||||
// print('[Main] Calculated overlay size: ${overlayWidth}x${overlayHeight}');
|
// debugPrint('[Main] Calculated overlay size: ${overlayWidth}x${overlayHeight}');
|
||||||
|
|
||||||
// Send initial display data to overlay including screen size
|
// Send initial display data to overlay including screen size
|
||||||
final displaySpeed = _currentUnit.convert(_speed);
|
final displaySpeed = _currentUnit.convert(_speed);
|
||||||
@@ -250,7 +258,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
height: overlayHeight.clamp(140, 240),
|
height: overlayHeight.clamp(140, 240),
|
||||||
);
|
);
|
||||||
|
|
||||||
print('[Main] 🟢 OVERLAY LAUNCHED - Size: ${overlayWidth.clamp(280, 480)}x${overlayHeight.clamp(140, 240)}');
|
debugPrint('[Main] 🟢 OVERLAY LAUNCHED - Size: ${overlayWidth.clamp(280, 480)}x${overlayHeight.clamp(140, 240)}');
|
||||||
setState(() {
|
setState(() {
|
||||||
_isOverlayActive = true;
|
_isOverlayActive = true;
|
||||||
});
|
});
|
||||||
@@ -261,18 +269,18 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
|
|
||||||
Future<void> _closeFloatingWindow() async {
|
Future<void> _closeFloatingWindow() async {
|
||||||
if (!_isOverlayActive) {
|
if (!_isOverlayActive) {
|
||||||
print('[Main] ⚠️ No overlay to close');
|
debugPrint('[Main] ⚠️ No overlay to close');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await FlutterOverlayWindow.closeOverlay();
|
await FlutterOverlayWindow.closeOverlay();
|
||||||
print('[Main] 🔴 OVERLAY CLOSED - Requested from main app');
|
debugPrint('[Main] 🔴 OVERLAY CLOSED - Requested from main app');
|
||||||
setState(() {
|
setState(() {
|
||||||
_isOverlayActive = false;
|
_isOverlayActive = false;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('[Main] ❌ Error closing overlay: $e');
|
debugPrint('[Main] ❌ Error closing overlay: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,7 +423,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
flex: 32,
|
flex: 32,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
print('[Main] 🖱️ Navigation area tapped - overlay active: $_isOverlayActive');
|
debugPrint('[Main] 🖱️ Navigation area tapped - overlay active: $_isOverlayActive');
|
||||||
if (_isOverlayActive) {
|
if (_isOverlayActive) {
|
||||||
_closeFloatingWindow();
|
_closeFloatingWindow();
|
||||||
} else {
|
} else {
|
||||||
@@ -423,7 +431,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
print('[Main] 🖱️ Navigation area long-pressed - overlay active: $_isOverlayActive');
|
debugPrint('[Main] 🖱️ Navigation area long-pressed - overlay active: $_isOverlayActive');
|
||||||
_closeFloatingWindow();
|
_closeFloatingWindow();
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
@@ -541,7 +549,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
flex: 33,
|
flex: 33,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
print('[Main] 🖱️ Navigation area tapped (landscape) - overlay active: $_isOverlayActive');
|
debugPrint('[Main] 🖱️ Navigation area tapped (landscape) - overlay active: $_isOverlayActive');
|
||||||
if (_isOverlayActive) {
|
if (_isOverlayActive) {
|
||||||
_closeFloatingWindow();
|
_closeFloatingWindow();
|
||||||
} else {
|
} else {
|
||||||
@@ -549,7 +557,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> with WidgetsBindi
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
print('[Main] 🖱️ Navigation area long-pressed (landscape) - overlay active: $_isOverlayActive');
|
debugPrint('[Main] 🖱️ Navigation area long-pressed (landscape) - overlay active: $_isOverlayActive');
|
||||||
_closeFloatingWindow();
|
_closeFloatingWindow();
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
@@ -616,7 +624,7 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
print('[Overlay] 🟢 CREATED - Floating window initialized');
|
debugPrint('[Overlay] 🟢 CREATED - Floating window initialized');
|
||||||
_getSystemScreenSize();
|
_getSystemScreenSize();
|
||||||
_listenToMainAppMessages();
|
_listenToMainAppMessages();
|
||||||
}
|
}
|
||||||
@@ -629,18 +637,18 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
|||||||
final devicePixelRatio = window.devicePixelRatio;
|
final devicePixelRatio = window.devicePixelRatio;
|
||||||
final systemSize = physicalSize / devicePixelRatio;
|
final systemSize = physicalSize / devicePixelRatio;
|
||||||
|
|
||||||
print('[Overlay] 🔍 Screen detection:');
|
debugPrint('[Overlay] 🔍 Screen detection:');
|
||||||
print(' physicalSize: ${physicalSize.width.round()}x${physicalSize.height.round()}');
|
debugPrint(' physicalSize: ${physicalSize.width.round()}x${physicalSize.height.round()}');
|
||||||
print(' devicePixelRatio: $devicePixelRatio');
|
debugPrint(' devicePixelRatio: $devicePixelRatio');
|
||||||
print(' calculated systemSize: ${systemSize.width.round()}x${systemSize.height.round()}');
|
debugPrint(' calculated systemSize: ${systemSize.width.round()}x${systemSize.height.round()}');
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_systemScreenWidth = systemSize.width;
|
_systemScreenWidth = systemSize.width;
|
||||||
});
|
});
|
||||||
|
|
||||||
print('[Overlay] ✅ _systemScreenWidth set to: ${_systemScreenWidth.round()}');
|
debugPrint('[Overlay] ✅ _systemScreenWidth set to: ${_systemScreenWidth.round()}');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('[Overlay] ❌ Error getting system screen size: $e');
|
debugPrint('[Overlay] ❌ Error getting system screen size: $e');
|
||||||
// Fallback to reasonable default
|
// Fallback to reasonable default
|
||||||
setState(() {
|
setState(() {
|
||||||
_systemScreenWidth = 400;
|
_systemScreenWidth = 400;
|
||||||
@@ -668,20 +676,20 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
print('[Overlay] 📡 UPDATE received:');
|
debugPrint('[Overlay] 📡 UPDATE received:');
|
||||||
print(' speedText: "$_speedText"');
|
debugPrint(' speedText: "$_speedText"');
|
||||||
print(' headingText: "$_headingText"');
|
debugPrint(' headingText: "$_headingText"');
|
||||||
print(' direction: ${_heading.toStringAsFixed(1)}°');
|
debugPrint(' direction: ${_heading.toStringAsFixed(1)}°');
|
||||||
print(' themeIndex: $_currentThemeIndex');
|
debugPrint(' themeIndex: $_currentThemeIndex');
|
||||||
print(' systemScreenWidth: ${_systemScreenWidth.round()}');
|
debugPrint(' systemScreenWidth: ${_systemScreenWidth.round()}');
|
||||||
print(' overlaySize from main: ${_overlayWidth.round()}x${_overlayHeight.round()}');
|
debugPrint(' overlaySize from main: ${_overlayWidth.round()}x${_overlayHeight.round()}');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
print('[Overlay] 🔴 DESTROYED - Floating window disposed');
|
debugPrint('[Overlay] 🔴 DESTROYED - Floating window disposed');
|
||||||
// No GPS subscription to cancel - overlay is display-only
|
// No GPS subscription to cancel - overlay is display-only
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@@ -693,7 +701,7 @@ class _OverlaySpeedometerState extends State<OverlaySpeedometer> {
|
|||||||
// Use overlay dimensions provided by main app (not calculated locally)
|
// Use overlay dimensions provided by main app (not calculated locally)
|
||||||
final fontSize = (_overlayWidth * 0.2); // Font size proportional to actual overlay width
|
final fontSize = (_overlayWidth * 0.2); // Font size proportional to actual overlay width
|
||||||
|
|
||||||
print('[Overlay] 📐 Window size: ${_overlayWidth.round()}x${_overlayHeight.round()}, fontSize: ${fontSize.round()}');
|
debugPrint('[Overlay] 📐 Window size: ${_overlayWidth.round()}x${_overlayHeight.round()}, fontSize: ${fontSize.round()}');
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
|
|||||||
Reference in New Issue
Block a user