diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index 8689381..41f4a68 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -17,6 +17,7 @@ import 'package:rogapp/utils/const.dart'; import 'package:rogapp/utils/database_helper.dart'; import 'package:rogapp/utils/text_util.dart'; import 'package:rogapp/widgets/bottom_sheet_controller.dart'; +import 'package:rogapp/widgets/debug_widget.dart'; import 'package:sqflite/sqflite.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -396,6 +397,13 @@ class BottomSheetNew extends GetView { destinationController.currentLat, destinationController.currentLon), LatLng(cdest.lat!, cdest.lon!)); + LogManager().addLog("Distance from current point : $distanceToDest"); + LogManager().addLog( + "forced distance for point : ${destinationController.getForcedChckinDistance(destination)}"); + LogManager().addLog("is already checked in : $isAlreadyCheckedIn"); + LogManager().addLog("Checkin radius : ${destination.checkin_radious}"); + LogManager().addLog("--${destination.cp}--"); + return SingleChildScrollView( child: Column( children: [ diff --git a/lib/widgets/debug_widget.dart b/lib/widgets/debug_widget.dart new file mode 100644 index 0000000..f2dcbb3 --- /dev/null +++ b/lib/widgets/debug_widget.dart @@ -0,0 +1,134 @@ +import 'package:flutter/material.dart'; + +class LogManager { + static final LogManager _instance = LogManager._internal(); + + factory LogManager() { + return _instance; + } + + LogManager._internal(); + + List _logs = []; + List _listeners = []; + + List get logs => _logs; + + void addLog(String log) { + _logs.add(log); + _notifyListeners(); // Notify all listeners + } + + void clearLogs() { + _logs.clear(); + _notifyListeners(); // Notify all listeners + } + + void addListener(VoidCallback listener) { + _listeners.add(listener); + } + + void removeListener(VoidCallback listener) { + _listeners.remove(listener); + } + + void _notifyListeners() { + for (var listener in _listeners) { + listener(); + } + } +} + +class DebugWidget extends StatefulWidget { + const DebugWidget({super.key}); + + @override + State createState() => _DebugWidgetState(); +} + +class _DebugWidgetState extends State { + final LogManager logManager = LogManager(); + + @override + void initState() { + super.initState(); + logManager.addListener(_updateLogs); + } + + @override + void dispose() { + logManager.removeListener(_updateLogs); + super.dispose(); + } + + void _updateLogs() { + Future.delayed(Duration.zero, () { + if (mounted) { + setState(() {}); + } + }); + } + + void toggleExpanded() { + setState(() { + isExpanded = !isExpanded; + }); + } + + void clearLogs() { + logManager.clearLogs(); + } + + bool isExpanded = false; + + @override + Widget build(BuildContext context) { + return Positioned( + left: 0, + right: 0, + bottom: 0, + child: GestureDetector( + onTap: toggleExpanded, + child: AnimatedContainer( + duration: Duration(milliseconds: 200), + color: Colors.black54, + height: isExpanded ? 450.0 : 50.0, // Adjust sizes as needed + child: Column( + children: [ + // Top bar with clear button + if (isExpanded) + Container( + padding: EdgeInsets.symmetric(horizontal: 10.0), + color: Colors.blueGrey, // Adjust color as needed + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('Debug Logs', style: TextStyle(color: Colors.white)), + IconButton( + icon: Icon(Icons.clear, color: Colors.white), + onPressed: clearLogs, + ), + ], + ), + ), + + // Log messages + Expanded( + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: logManager.logs.reversed + .map((log) => Text( + "${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond} - $log", + style: const TextStyle(color: Colors.white))) + .toList(), + ), + ), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/widgets/map_widget.dart b/lib/widgets/map_widget.dart index 97078b9..6877f6c 100644 --- a/lib/widgets/map_widget.dart +++ b/lib/widgets/map_widget.dart @@ -14,6 +14,7 @@ import 'package:rogapp/utils/database_helper.dart'; import 'package:rogapp/utils/text_util.dart'; import 'package:rogapp/widgets/base_layer_widget.dart'; import 'package:rogapp/widgets/bottom_sheet_new.dart'; +import 'package:rogapp/widgets/debug_widget.dart'; class MapWidget extends StatelessWidget { final IndexController indexController = Get.find(); @@ -228,7 +229,12 @@ class MapWidget extends StatelessWidget { ) : const Center(child: CircularProgressIndicator()), ], - )) + )), + const Positioned( + bottom: 10, + left: 0, + child: DebugWidget(), + ) ], ); }