-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add PublishTaskPositionsOnUpdate.dart
- Loading branch information
Showing
4 changed files
with
64 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:locus/services/current_location_service.dart'; | ||
import 'package:locus/services/location_point_service.dart'; | ||
import 'package:locus/services/task_service/index.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class PublishTaskPositionsOnUpdate extends StatefulWidget { | ||
const PublishTaskPositionsOnUpdate({super.key}); | ||
|
||
@override | ||
State<PublishTaskPositionsOnUpdate> createState() => | ||
_PublishTaskPositionsOnUpdateState(); | ||
} | ||
|
||
class _PublishTaskPositionsOnUpdateState | ||
extends State<PublishTaskPositionsOnUpdate> { | ||
late final CurrentLocationService _currentLocation; | ||
late final StreamSubscription _stream; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_currentLocation = context.read<CurrentLocationService>(); | ||
|
||
_stream = _currentLocation.stream.listen((position) async { | ||
final taskService = context.read<TaskService>(); | ||
|
||
final runningTasks = await taskService.getRunningTasks().toList(); | ||
|
||
if (runningTasks.isEmpty) { | ||
return; | ||
} | ||
|
||
final locationData = await LocationPointService.fromPosition(position); | ||
|
||
for (final task in runningTasks) { | ||
await task.publisher.publishOutstandingPositions(); | ||
await task.publisher.publishLocation( | ||
locationData.copyWithDifferentId(), | ||
); | ||
} | ||
}); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_stream.cancel(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const SizedBox.shrink(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters