Sending better info to admin, big circular button
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
void main() {
|
||||
@@ -14,7 +16,7 @@ class WalkerApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Blockwalker',
|
||||
title: 'Blockcatcher',
|
||||
theme: ThemeData(primarySwatch: Colors.blue),
|
||||
home: const TrackingScreen(),
|
||||
);
|
||||
@@ -57,11 +59,24 @@ class _TrackingScreenState extends State<TrackingScreen> {
|
||||
final log = '${DateTime.now().toIso8601String()} — (${pos.latitude}, ${pos.longitude})';
|
||||
setState(() => _logs.insert(0, log));
|
||||
|
||||
final timestamp = DateTime.now().toIso8601String();
|
||||
final timestamp = formatCentralTime(DateTime.now());
|
||||
await _sendLocationToBackend(pos.latitude, pos.longitude, timestamp);
|
||||
});
|
||||
}
|
||||
|
||||
String formatCentralTime(DateTime dt) {
|
||||
// Central Time offset is UTC-5 or UTC-6 depending on daylight saving
|
||||
// Using DateTime.now().toUtc() + Duration(hours: -5) is one option
|
||||
// A better way is using timeZoneOffset from a known location
|
||||
// For simplicity, let's assume Central Standard Time (UTC-6)
|
||||
|
||||
final centralTime = dt.toUtc().subtract(const Duration(hours: 5));
|
||||
|
||||
// Format as 10.31.25 9:39:08pm
|
||||
final formatter = DateFormat('MM.dd.yy h:mm:ss a');
|
||||
return formatter.format(centralTime);
|
||||
}
|
||||
|
||||
Future<void> _sendLocationToBackend(double lat, double lon, String timestamp) async {
|
||||
final url = Uri.parse('http://sam.local:3008/api/location');
|
||||
|
||||
@@ -69,6 +84,7 @@ class _TrackingScreenState extends State<TrackingScreen> {
|
||||
url,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: jsonEncode({
|
||||
'name': "Freddy Krueger",
|
||||
'latitude': lat,
|
||||
'longitude': lon,
|
||||
'timestamp': timestamp,
|
||||
@@ -90,24 +106,39 @@ class _TrackingScreenState extends State<TrackingScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Blockwalker')),
|
||||
backgroundColor: const Color(0xFFAEBDFF), // <-- your hex color here
|
||||
appBar: AppBar(
|
||||
title: const Text('BLOCKCATCHER'),
|
||||
backgroundColor: const Color(0xFFAEBDFF), // ✅ your color here
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _tracking ? _stopTracking : _startTracking,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _tracking ? Colors.red : Colors.green,
|
||||
const SizedBox(height: 200), // move button closer to top
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: _tracking ? _stopTracking : _startTracking,
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: const CircleBorder(),
|
||||
padding: const EdgeInsets.all(60),
|
||||
backgroundColor: _tracking ? Colors.red : Colors.green,
|
||||
),
|
||||
child: Icon(
|
||||
_tracking ? Icons.stop : Icons.play_arrow,
|
||||
color: Colors.white,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
child: Text(_tracking ? 'Stop Tracking' : 'Begin Tracking'),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 40),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _logs.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
dense: true,
|
||||
title: Text(_logs[index]),
|
||||
title: Text(
|
||||
_logs[index],
|
||||
style: const TextStyle(color: Colors.black87),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user