Compare commits
No commits in common. "b84e9d307de0480d91f5b524c360c7d8c77ff7db" and "fa129f17fb9390f3ddacfde21238f166f4ad98dd" have entirely different histories.
b84e9d307d
...
fa129f17fb
@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:hydrated_bloc/hydrated_bloc.dart';
|
import 'package:hydrated_bloc/hydrated_bloc.dart';
|
||||||
import 'package:ot_viewer_app/global_location_store.dart';
|
import 'package:ot_viewer_app/global_location_store.dart';
|
||||||
import 'package:ot_viewer_app/refresh_cubit.dart';
|
|
||||||
import 'package:ot_viewer_app/settings_page.dart';
|
import 'package:ot_viewer_app/settings_page.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'map_page.dart';
|
import 'map_page.dart';
|
||||||
@ -21,22 +20,8 @@ Future<void> main() async {
|
|||||||
|
|
||||||
GetIt.I
|
GetIt.I
|
||||||
.registerSingleton<GlobalLocationStoreCubit>(GlobalLocationStoreCubit());
|
.registerSingleton<GlobalLocationStoreCubit>(GlobalLocationStoreCubit());
|
||||||
GetIt.I.registerSingleton<RefreshCubit>(RefreshCubit());
|
|
||||||
|
|
||||||
runApp(
|
runApp(MyApp());
|
||||||
MultiBlocProvider(
|
|
||||||
providers: [
|
|
||||||
BlocProvider(
|
|
||||||
lazy: false,
|
|
||||||
create: (BuildContext context) => SettingsCubit(),
|
|
||||||
),
|
|
||||||
BlocProvider(
|
|
||||||
create: (BuildContext context) => GetIt.I.get<RefreshCubit>(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
child: MyApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@ -46,17 +31,7 @@ class MyApp extends StatelessWidget {
|
|||||||
title: 'OwnTracks Data Viewer',
|
title: 'OwnTracks Data Viewer',
|
||||||
theme: ThemeData.dark(),
|
theme: ThemeData.dark(),
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(title: const Text('OwnTrakcs Data Viewer')),
|
||||||
title: const Text('OwnTrakcs Data Viewer'),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.refresh),
|
|
||||||
onPressed: () async {
|
|
||||||
context.read<RefreshCubit>().triggerRefresh();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: const MainPage(),
|
body: const MainPage(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -85,7 +60,10 @@ class _MainPageState extends State<MainPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return BlocProvider(
|
||||||
|
lazy: false,
|
||||||
|
create: (BuildContext context) => SettingsCubit(),
|
||||||
|
child: Scaffold(
|
||||||
body: IndexedStack(
|
body: IndexedStack(
|
||||||
index: _currentIndex,
|
index: _currentIndex,
|
||||||
children: _pages,
|
children: _pages,
|
||||||
@ -104,6 +82,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
currentIndex: _currentIndex,
|
currentIndex: _currentIndex,
|
||||||
onTap: _onItemTapped,
|
onTap: _onItemTapped,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import 'package:get_it/get_it.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:latlong2/latlong.dart';
|
import 'package:latlong2/latlong.dart';
|
||||||
import 'package:ot_viewer_app/global_location_store.dart';
|
import 'package:ot_viewer_app/global_location_store.dart';
|
||||||
import 'package:ot_viewer_app/refresh_cubit.dart';
|
|
||||||
import 'package:ot_viewer_app/settings_page.dart';
|
import 'package:ot_viewer_app/settings_page.dart';
|
||||||
import 'package:ot_viewer_app/user_path_bloc.dart';
|
import 'package:ot_viewer_app/user_path_bloc.dart';
|
||||||
import 'package:ot_viewer_app/util.dart';
|
import 'package:ot_viewer_app/util.dart';
|
||||||
@ -35,8 +34,6 @@ class MapPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MapPageState extends State<MapPage> {
|
class _MapPageState extends State<MapPage> {
|
||||||
final MapController _mapController = MapController();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -51,58 +48,40 @@ class _MapPageState extends State<MapPage> {
|
|||||||
final settingsCubit = context.read<SettingsCubit>();
|
final settingsCubit = context.read<SettingsCubit>();
|
||||||
cubit.subscribe(settingsCubit.state);
|
cubit.subscribe(settingsCubit.state);
|
||||||
settingsCubit.stream.listen((settings) => cubit.subscribe(settings));
|
settingsCubit.stream.listen((settings) => cubit.subscribe(settings));
|
||||||
final refreshCubit = context.read<RefreshCubit>();
|
|
||||||
refreshCubit.stream.listen((_) => cubit.reconnect());
|
|
||||||
return cubit;
|
return cubit;
|
||||||
},
|
},
|
||||||
child: FutureBuilder<String>(
|
child: FutureBuilder<String>(
|
||||||
future: getPath(),
|
future: getPath(),
|
||||||
builder: (something, tempPath) =>
|
builder: (something, tempPath) => BlocBuilder<SettingsCubit, SettingsState>(
|
||||||
BlocBuilder<SettingsCubit, SettingsState>(
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (tempPath.data == null) {
|
if (tempPath.data == null) {
|
||||||
return const Center(child: Text('Loading Map...'));
|
return const Center(child: Text('Loading Map...'));
|
||||||
}
|
}
|
||||||
return Stack(children: [
|
return FlutterMap(
|
||||||
FlutterMap(
|
|
||||||
mapController: _mapController,
|
|
||||||
options: const MapOptions(
|
options: const MapOptions(
|
||||||
initialCenter: LatLng(48.3285, 9.8942),
|
initialCenter: LatLng(48.3285, 9.8942),
|
||||||
initialZoom: 13.0,
|
initialZoom: 13.0,
|
||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
TileLayer(
|
TileLayer(
|
||||||
urlTemplate:
|
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||||
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
||||||
tileProvider: CachedTileProvider(
|
tileProvider: CachedTileProvider(
|
||||||
maxStale: const Duration(days: 30),
|
maxStale: const Duration(days: 30),
|
||||||
store: HiveCacheStore(tempPath.data!,
|
store: HiveCacheStore(tempPath.data!, hiveBoxName: 'HiveCacheStore')),
|
||||||
hiveBoxName: 'HiveCacheStore')),
|
|
||||||
),
|
),
|
||||||
...state.activeDevices.map((id) =>
|
...state.activeDevices.map((id) => UserPath(key: ValueKey(id), device: id, settings: state)),
|
||||||
UserPath(key: ValueKey(id), device: id, settings: state)),
|
const MapCompass.cupertino(rotationDuration: Duration(milliseconds: 600)),
|
||||||
const MapCompass.cupertino(
|
|
||||||
rotationDuration: Duration(milliseconds: 600)),
|
|
||||||
// CurrentLocationLayer(), TODO: add permission
|
// CurrentLocationLayer(), TODO: add permission
|
||||||
RichAttributionWidget(
|
RichAttributionWidget(
|
||||||
attributions: [
|
attributions: [
|
||||||
TextSourceAttribution(
|
TextSourceAttribution(
|
||||||
'OpenStreetMap contributors',
|
'OpenStreetMap contributors',
|
||||||
onTap: () =>
|
onTap: () => (Uri.parse('https://openstreetmap.org/copyright')),
|
||||||
(Uri.parse('https://openstreetmap.org/copyright')),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
);
|
||||||
Positioned(
|
|
||||||
bottom: 16,
|
|
||||||
left: 16,
|
|
||||||
child: TrackerSelector(
|
|
||||||
mapController: _mapController,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -131,34 +110,20 @@ class _UserPathState extends State<UserPath> {
|
|||||||
// ONLY WORKS because gets rebuilt every time with settings update
|
// ONLY WORKS because gets rebuilt every time with settings update
|
||||||
return bloc;
|
return bloc;
|
||||||
},
|
},
|
||||||
child: MultiBlocListener(
|
child: BlocListener<LocationSubscribeCubit, LocationUpdateState>(
|
||||||
listeners: [
|
|
||||||
BlocListener<LocationSubscribeCubit, LocationUpdateState>(
|
|
||||||
listenWhen: (prevState, state) => state is LocationUpdateReceived,
|
listenWhen: (prevState, state) => state is LocationUpdateReceived,
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
UserPathBloc userPathBloc = context.read<UserPathBloc>();
|
UserPathBloc userPathBloc = context.read<UserPathBloc>();
|
||||||
if (state
|
if (state case LocationUpdateReceived(:final position, :final deviceId)) {
|
||||||
case LocationUpdateReceived(
|
|
||||||
:final position,
|
|
||||||
:final deviceId
|
|
||||||
)) {
|
|
||||||
if (userPathBloc.deviceId == state.deviceId) {
|
if (userPathBloc.deviceId == state.deviceId) {
|
||||||
userPathBloc.add(UserPathLiveSubscriptionUpdate(position));
|
userPathBloc.add(UserPathLiveSubscriptionUpdate(position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
BlocListener<RefreshCubit, DateTime>(
|
|
||||||
listener: (context, state) {
|
|
||||||
context.read<UserPathBloc>().add(UserPathFullUpdate());
|
|
||||||
},
|
},
|
||||||
)
|
|
||||||
],
|
|
||||||
child: BlocBuilder<UserPathBloc, UserPathState>(
|
child: BlocBuilder<UserPathBloc, UserPathState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
// TODO: change once smarter rebuilds are ready
|
// TODO: change once smarter rebuilds are ready
|
||||||
context
|
context.read<UserPathBloc>().add(UserPathLoginDataChanged(widget.settings));
|
||||||
.read<UserPathBloc>()
|
|
||||||
.add(UserPathLoginDataChanged(widget.settings));
|
|
||||||
|
|
||||||
print("rebuild");
|
print("rebuild");
|
||||||
final _istate = state as MainUserPathState;
|
final _istate = state as MainUserPathState;
|
||||||
@ -174,8 +139,7 @@ class _UserPathState extends State<UserPath> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => showUserLocationModalBottomSheet(
|
onTap: () => showUserLocationModalBottomSheet(context, widget.device),
|
||||||
context, widget.device),
|
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.black.withOpacity(0.85),
|
color: Colors.black.withOpacity(0.85),
|
||||||
@ -206,8 +170,7 @@ class _UserPathState extends State<UserPath> {
|
|||||||
List<List<LatLng>> segments = [];
|
List<List<LatLng>> segments = [];
|
||||||
List<Color> colors = [];
|
List<Color> colors = [];
|
||||||
if (state.initialPoints.isNotEmpty) {
|
if (state.initialPoints.isNotEmpty) {
|
||||||
final allPoints =
|
final allPoints = state.initialPoints.map((e) => LatLng(e.lat, e.lon)).toList();
|
||||||
state.initialPoints.map((e) => LatLng(e.lat, e.lon)).toList();
|
|
||||||
final segmentCount = math.min(100, allPoints.length);
|
final segmentCount = math.min(100, allPoints.length);
|
||||||
final pointsPerSegment = (allPoints.length / segmentCount).ceil();
|
final pointsPerSegment = (allPoints.length / segmentCount).ceil();
|
||||||
|
|
||||||
@ -230,9 +193,8 @@ class _UserPathState extends State<UserPath> {
|
|||||||
Polyline(
|
Polyline(
|
||||||
points: segments[i],
|
points: segments[i],
|
||||||
strokeWidth: 4.0,
|
strokeWidth: 4.0,
|
||||||
color: colors[i].withOpacity(
|
color: colors[i]
|
||||||
(math.pow(i, 2) / math.pow(segments.length, 2)) * 0.7 +
|
.withOpacity((math.pow(i, 2) / math.pow(segments.length, 2)) * 0.7 + 0.3), // Fading effect
|
||||||
0.3), // Fading effect
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -255,13 +217,9 @@ class _UserPathState extends State<UserPath> {
|
|||||||
...polylines
|
...polylines
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
PolylineLayer(
|
PolylineLayer(key: ValueKey('${widget.device}_liveLines'), polylines: [
|
||||||
key: ValueKey('${widget.device}_liveLines'),
|
|
||||||
polylines: [
|
|
||||||
Polyline(
|
Polyline(
|
||||||
points: state.livePoints
|
points: state.livePoints.map((e) => LatLng(e.lat, e.lon)).toList(),
|
||||||
.map((e) => LatLng(e.lat, e.lon))
|
|
||||||
.toList(),
|
|
||||||
strokeWidth: 4.0,
|
strokeWidth: 4.0,
|
||||||
color: Colors.blue.shade200,
|
color: Colors.blue.shade200,
|
||||||
),
|
),
|
||||||
@ -286,15 +244,13 @@ showUserLocationModalBottomSheet(BuildContext context, (String, String) user) {
|
|||||||
height: 500,
|
height: 500,
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
borderRadius: BorderRadius.only(
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(30), topRight: Radius.circular(30)),
|
||||||
topLeft: Radius.circular(30), topRight: Radius.circular(30)),
|
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.all(32),
|
padding: const EdgeInsets.all(32),
|
||||||
child: StreamBuilder<UserPathState>(
|
child: StreamBuilder<UserPathState>(
|
||||||
stream: context.read<UserPathBloc>().stream,
|
stream: context.read<UserPathBloc>().stream,
|
||||||
builder: (sheetContext, state) {
|
builder: (sheetContext, state) {
|
||||||
final istate = state.data as MainUserPathState? ??
|
final istate = state.data as MainUserPathState? ?? context.read<UserPathBloc>().state as MainUserPathState;
|
||||||
context.read<UserPathBloc>().state as MainUserPathState;
|
|
||||||
if (istate.livePoints.isEmpty) {
|
if (istate.livePoints.isEmpty) {
|
||||||
return Text("Couldn't find ${user.$1}:${user.$2}'s Location");
|
return Text("Couldn't find ${user.$1}:${user.$2}'s Location");
|
||||||
}
|
}
|
||||||
@ -319,15 +275,12 @@ showUserLocationModalBottomSheet(BuildContext context, (String, String) user) {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text("(${curLocation.lat.toStringAsFixed(4)}, ${curLocation.lon.toStringAsFixed(4)})"),
|
||||||
"(${curLocation.lat.toStringAsFixed(4)}, ${curLocation.lon.toStringAsFixed(4)})"),
|
Text(DateFormat('dd.MM.yyyy - kk:mm:ss').format(curLocation.timestamp)),
|
||||||
Text(DateFormat('dd.MM.yyyy - kk:mm:ss')
|
|
||||||
.format(curLocation.timestamp)),
|
|
||||||
StreamBuilder(
|
StreamBuilder(
|
||||||
stream: Stream.periodic(const Duration(seconds: 1)),
|
stream: Stream.periodic(const Duration(seconds: 1)),
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
return Text(
|
return Text("${formatDuration(DateTime.now().difference(curLocation.timestamp))} ago");
|
||||||
"${formatDuration(DateTime.now().difference(curLocation.timestamp))} ago");
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -338,8 +291,7 @@ showUserLocationModalBottomSheet(BuildContext context, (String, String) user) {
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
// Ensure GridView.builder is within an Expanded widget
|
// Ensure GridView.builder is within an Expanded widget
|
||||||
child: BlocBuilder<GlobalLocationStoreCubit,
|
child: BlocBuilder<GlobalLocationStoreCubit, GlobalLocationStoreState>(
|
||||||
GlobalLocationStoreState>(
|
|
||||||
bloc: GetIt.I.get<GlobalLocationStoreCubit>(),
|
bloc: GetIt.I.get<GlobalLocationStoreCubit>(),
|
||||||
builder: (sheetContext, state) {
|
builder: (sheetContext, state) {
|
||||||
// get map camera
|
// get map camera
|
||||||
@ -347,32 +299,22 @@ showUserLocationModalBottomSheet(BuildContext context, (String, String) user) {
|
|||||||
|
|
||||||
final mapRotation = mapController.camera.rotation;
|
final mapRotation = mapController.camera.rotation;
|
||||||
|
|
||||||
List<MapEntry<(String, String), Point>> locations = state
|
List<MapEntry<(String, String), Point>> locations = state.locations
|
||||||
.locations
|
|
||||||
.remove(user) // remove this
|
.remove(user) // remove this
|
||||||
.entries // get entries into a list, and sort alphabetically
|
.entries // get entries into a list, and sort alphabetically
|
||||||
.toList()
|
.toList()
|
||||||
..sort((a, b) => "${a.key.$1}:${a.key.$2}"
|
..sort((a, b) => "${a.key.$1}:${a.key.$2}".compareTo("${b.key.$1}:${b.key.$2}"));
|
||||||
.compareTo("${b.key.$1}:${b.key.$2}"));
|
|
||||||
if (locations.isEmpty) {
|
if (locations.isEmpty) {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
return GridView.builder(
|
return GridView.builder(
|
||||||
gridDelegate:
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
crossAxisCount: 1, crossAxisSpacing: 4.0, mainAxisSpacing: 4.0, mainAxisExtent: 100),
|
||||||
crossAxisCount: 1,
|
|
||||||
crossAxisSpacing: 4.0,
|
|
||||||
mainAxisSpacing: 4.0,
|
|
||||||
mainAxisExtent: 100),
|
|
||||||
itemCount: locations.length,
|
itemCount: locations.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
// calculate distance and bearing
|
// calculate distance and bearing
|
||||||
double distance = distanceBetween(
|
double distance = distanceBetween(curLocation.lat, curLocation.lon,
|
||||||
curLocation.lat,
|
locations[index].value.lat, locations[index].value.lon, "meters");
|
||||||
curLocation.lon,
|
|
||||||
locations[index].value.lat,
|
|
||||||
locations[index].value.lon,
|
|
||||||
"meters");
|
|
||||||
|
|
||||||
double bearing = (bearingBetween(
|
double bearing = (bearingBetween(
|
||||||
curLocation.lat,
|
curLocation.lat,
|
||||||
@ -391,8 +333,7 @@ showUserLocationModalBottomSheet(BuildContext context, (String, String) user) {
|
|||||||
margin: const EdgeInsets.all(8),
|
margin: const EdgeInsets.all(8),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
border:
|
border: Border.all(color: Colors.pink, width: 2),
|
||||||
Border.all(color: Colors.pink, width: 2),
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
@ -402,8 +343,7 @@ showUserLocationModalBottomSheet(BuildContext context, (String, String) user) {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"${locations[index].key.$1}:${locations[index].key.$2}",
|
"${locations[index].key.$1}:${locations[index].key.$2}",
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
Text(formatDistance(distance ~/ 1)),
|
Text(formatDistance(distance ~/ 1)),
|
||||||
@ -419,13 +359,11 @@ showUserLocationModalBottomSheet(BuildContext context, (String, String) user) {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
StreamBuilder(
|
StreamBuilder(
|
||||||
stream: Stream.periodic(
|
stream: Stream.periodic(const Duration(seconds: 1)),
|
||||||
const Duration(seconds: 1)),
|
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
return Text(
|
return Text(
|
||||||
"${formatDuration(DateTime.now().difference(locations[index].value.timestamp))} ago",
|
"${formatDuration(DateTime.now().difference(locations[index].value.timestamp))} ago",
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontSize: 12));
|
||||||
fontSize: 12));
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
@ -448,81 +386,3 @@ showUserLocationModalBottomSheet(BuildContext context, (String, String) user) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class TrackerSelector extends StatefulWidget {
|
|
||||||
final MapController mapController;
|
|
||||||
|
|
||||||
const TrackerSelector({super.key, required this.mapController});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<TrackerSelector> createState() => _TrackerSelectorState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _TrackerSelectorState extends State<TrackerSelector> {
|
|
||||||
bool _isExpanded = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AnimatedContainer(
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
width: _isExpanded ? MediaQuery.of(context).size.width - 32 : 48,
|
|
||||||
height: 48,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black87,
|
|
||||||
borderRadius: BorderRadius.circular(24),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(_isExpanded ? Icons.close : Icons.people),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_isExpanded = !_isExpanded;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (_isExpanded)
|
|
||||||
Expanded(
|
|
||||||
child: BlocBuilder<GlobalLocationStoreCubit,
|
|
||||||
GlobalLocationStoreState>(
|
|
||||||
bloc: GetIt.I.get<GlobalLocationStoreCubit>(),
|
|
||||||
builder: (context, state) {
|
|
||||||
return ListView.builder(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: state.locations.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final entry = state.locations.entries.elementAt(index);
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () => widget.mapController
|
|
||||||
.moveAndRotate(entry.value.asLatLng, 15, 0),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Icon(
|
|
||||||
Icons.location_history,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 24,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
"${entry.key.$1}:${entry.key.$2}",
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 12,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
|
|
||||||
class RefreshCubit extends Cubit<DateTime> {
|
|
||||||
RefreshCubit() : super(DateTime.now());
|
|
||||||
|
|
||||||
void triggerRefresh() {
|
|
||||||
emit(DateTime.now());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
|
// web_socket_cubit.dart
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:anyhow/anyhow.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:ot_viewer_app/owntracks_api.dart';
|
import 'package:ot_viewer_app/owntracks_api.dart';
|
||||||
import 'package:ot_viewer_app/settings_page.dart';
|
import 'package:ot_viewer_app/settings_page.dart';
|
||||||
@ -24,19 +24,16 @@ class LocationUpdateReceived extends LocationUpdateState {
|
|||||||
|
|
||||||
class LocationSubscribeCubit extends Cubit<LocationUpdateState> {
|
class LocationSubscribeCubit extends Cubit<LocationUpdateState> {
|
||||||
Option<WebSocketClient> _wsClient = None;
|
Option<WebSocketClient> _wsClient = None;
|
||||||
Option<Completer<void>> _connectionCompleter = None;
|
|
||||||
String url = '';
|
String url = '';
|
||||||
String username = '';
|
String username = '';
|
||||||
String pass = '';
|
String pass = '';
|
||||||
|
|
||||||
LocationSubscribeCubit() : super(LocationUpdateUnconnected());
|
LocationSubscribeCubit() : super(LocationUpdateUnconnected());
|
||||||
|
|
||||||
// TODO: handle ongoing connection attempt by canceling? the loop? or smth
|
|
||||||
subscribe(SettingsState settings) async {
|
subscribe(SettingsState settings) async {
|
||||||
|
|
||||||
// check if resubscribe is necessary (different URL)
|
// check if resubscribe is necessary (different URL)
|
||||||
if (settings.url == url &&
|
if (settings.url == url && settings.username == username && settings.password == pass) {
|
||||||
settings.username == username &&
|
|
||||||
settings.password == pass) {
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
url = settings.url;
|
url = settings.url;
|
||||||
@ -47,38 +44,13 @@ class LocationSubscribeCubit extends Cubit<LocationUpdateState> {
|
|||||||
await _wsConnectionEstablish();
|
await _wsConnectionEstablish();
|
||||||
}
|
}
|
||||||
|
|
||||||
reconnect() async {
|
|
||||||
print("reconnecting...");
|
|
||||||
if (_wsClient.isSome()) {
|
|
||||||
await _wsClient.unwrap().close();
|
|
||||||
_wsClient = None;
|
|
||||||
} else {
|
|
||||||
print("not connected, not reconnecting");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await _wsConnectionEstablish();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _wsConnectionEstablish() async {
|
Future<void> _wsConnectionEstablish() async {
|
||||||
// If there's an ongoing connection attempt, wait for it
|
|
||||||
if (_connectionCompleter.isSome()) {
|
|
||||||
await _connectionCompleter.unwrap().future;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start new connection attempt
|
|
||||||
_connectionCompleter = Some(Completer<void>());
|
|
||||||
|
|
||||||
if (_wsClient.isSome()) {
|
if (_wsClient.isSome()) {
|
||||||
await _wsClient.unwrap().close();
|
await _wsClient.unwrap().close();
|
||||||
_wsClient = None;
|
_wsClient = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<WebSocketClient> ws = bail('Not done yet');
|
var ws = await OwntracksApi(baseUrl: url, username: username, pass: pass)
|
||||||
|
|
||||||
while (!ws.isOk()) {
|
|
||||||
ws = await OwntracksApi(baseUrl: url, username: username, pass: pass)
|
|
||||||
.createWebSocketConnection(
|
.createWebSocketConnection(
|
||||||
wsPath: 'last',
|
wsPath: 'last',
|
||||||
onMessage: (msg) {
|
onMessage: (msg) {
|
||||||
@ -106,8 +78,7 @@ class LocationSubscribeCubit extends Cubit<LocationUpdateState> {
|
|||||||
final p = Point(
|
final p = Point(
|
||||||
lat: map['lat'] as double,
|
lat: map['lat'] as double,
|
||||||
lon: map['lon'] as double,
|
lon: map['lon'] as double,
|
||||||
timestamp: DateTime.fromMillisecondsSinceEpoch(
|
timestamp: DateTime.fromMillisecondsSinceEpoch((map['tst'] as int) * 1000));
|
||||||
(map['tst'] as int) * 1000));
|
|
||||||
|
|
||||||
print(p);
|
print(p);
|
||||||
|
|
||||||
@ -132,18 +103,7 @@ class LocationSubscribeCubit extends Cubit<LocationUpdateState> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!ws.isOk()) {
|
_wsClient = ws.expect("Estabilshing Websocket Conenction failed").toOption();
|
||||||
print(
|
|
||||||
'Failed to connect to WebSocket: ${ws.unwrapErr()}\n, retrying in 1s');
|
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_wsClient =
|
|
||||||
ws.expect("Estabilshing Websocket Conenction failed").toOption();
|
|
||||||
|
|
||||||
_connectionCompleter.unwrap().complete();
|
|
||||||
_connectionCompleter = None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
24
pubspec.lock
24
pubspec.lock
@ -73,14 +73,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.6"
|
version: "1.0.6"
|
||||||
dart_earcut:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: dart_earcut
|
|
||||||
sha256: "41b493147e30a051efb2da1e3acb7f38fe0db60afba24ac1ea5684cee272721e"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.1.0"
|
|
||||||
dio:
|
dio:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -186,26 +178,26 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_map
|
name: flutter_map
|
||||||
sha256: "2ecb34619a4be19df6f40c2f8dce1591675b4eff7a6857bd8f533706977385da"
|
sha256: cda8d72135b697f519287258b5294a57ce2f2a5ebf234f0e406aad4dc14c9399
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "7.0.2"
|
version: "6.1.0"
|
||||||
flutter_map_cache:
|
flutter_map_cache:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_map_cache
|
name: flutter_map_cache
|
||||||
sha256: "47607b8d95ca791f0367d18955035d098faf80990e5e3bb0dbfa26271a6c2f43"
|
sha256: "5539033bbfbc0a663f3a038f223a36b472974d6613ce8f84fe7762eeff38aa5a"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.5.1"
|
version: "1.5.0"
|
||||||
flutter_map_compass:
|
flutter_map_compass:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_map_compass
|
name: flutter_map_compass
|
||||||
sha256: "1dffdc4f562a63f17751d9eea20d99771955e7dd0fbcdcc3b83195672e7abf54"
|
sha256: f904bdfa3f0aa008ed57abb1154197318ab4524a2cc6fda6888133aa70f2415f
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.0.1"
|
||||||
flutter_map_math:
|
flutter_map_math:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -276,10 +268,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: latlong2
|
name: latlong2
|
||||||
sha256: "98227922caf49e6056f91b6c56945ea1c7b166f28ffcd5fb8e72fc0b453cc8fe"
|
sha256: "18712164760cee655bc790122b0fd8f3d5b3c36da2cb7bf94b68a197fbb0811b"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.9.1"
|
version: "0.9.0"
|
||||||
leak_tracker:
|
leak_tracker:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -35,7 +35,7 @@ dependencies:
|
|||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.6
|
cupertino_icons: ^1.0.6
|
||||||
flutter_map: ^7.0.2
|
flutter_map: ^6.1.0
|
||||||
http: ^1.2.1
|
http: ^1.2.1
|
||||||
flutter_dotenv: ^5.1.0
|
flutter_dotenv: ^5.1.0
|
||||||
shared_preferences: ^2.2.2
|
shared_preferences: ^2.2.2
|
||||||
|
Loading…
Reference in New Issue
Block a user