-
Sara Savanovic Djordjevic authoredSara Savanovic Djordjevic authored
main.dart 5.88 KiB
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart'; // Import LatLng class from the latlong package
import 'dart:async';
import 'dart:io';
import 'dart:convert';
const String port = "8443";
const String serverURI = "https://127.0.0.1:$port/";
const String mapEndpoint = "update_map";
// NB: if http connection fails, run: adb reverse tcp:8443 tcp:8443
const int fetchInterval = 5;
// main is the entry point for the application, and starts the App() function
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: DefaultPage(),
);
}
}
class DefaultPage extends StatefulWidget {
const DefaultPage({Key? key}) : super(key: key);
@override
_DefaultPageState createState() => _DefaultPageState();
}
// MarkerData holds data for the dynamicllay allocated markers
class MarkerData {
final LatLng location;
final double size;
final Color color;
MarkerData({required this.location, required this.size, required this.color});
}
// parseMarkerData parses jsonData into an object of type MakerData
List<MarkerData> parseMarkerData(String jsonString) {
final parsed = json.decode(jsonString);
return List<MarkerData>.from(parsed.map((data) => MarkerData(
location: LatLng(data['latitude'], data['longitude']),
size: data['size'].toDouble(),
color: parseColor(data['color']),
)));
}
// parseColor parses the color strings into Colors types
Color parseColor(String colorString) {
switch (colorString) {
case 'blue':
return Colors.blue;
case 'red':
return Colors.red;
case 'green':
return Colors.green;
default:
return Colors.black; // Default color if unrecognized
}
}