Skip to content

Commit

Permalink
Merge pull request #208 from LezdCS/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LezdCS authored Jun 8, 2024
2 parents 3b7a2cf + f3011eb commit 0bc181e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
11 changes: 6 additions & 5 deletions lib/src/core/services/realtime_irl.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dio/dio.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:irllink/src/core/resources/data_state.dart';
import 'package:irllink/src/core/utils/init_dio.dart';

Expand All @@ -11,13 +12,13 @@ enum RtIrlStatus {
class RealtimeIrl {
String key;

RtIrlStatus status = RtIrlStatus.stopped;
Rx<RtIrlStatus> status = RtIrlStatus.stopped.obs;

RealtimeIrl(
this.key,
);

Future<DataState<bool>> updatePosition(Position p) async {
Future<DataState> updatePosition(Position p) async {
try {
Response response;
Dio dio = initDio();
Expand All @@ -29,10 +30,10 @@ class RealtimeIrl {
'longitude': p.longitude,
},
);
status = RtIrlStatus.updating;
status.value = RtIrlStatus.updating;
return DataSuccess(response.data);
} on DioException catch (e) {
status = RtIrlStatus.stopped;
status.value = RtIrlStatus.stopped;
return DataFailed(
"Unable to update your position on RTIRL : ${e.message}",
);
Expand All @@ -46,7 +47,7 @@ class RealtimeIrl {
response = await dio.post(
"https://rtirl.com/api/stop?key=$key",
);
status = RtIrlStatus.stopped;
status.value = RtIrlStatus.stopped;
return DataSuccess(response.data);
} on DioException catch (e) {
return DataFailed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class RealtimeIrlViewController extends GetxController {
void onInit() {
homeViewController = Get.find<HomeViewController>();

realtimeIrl = RealtimeIrl(homeViewController.settings.value.rtIrlPushKey ?? '');
realtimeIrl =
RealtimeIrl(homeViewController.settings.value.rtIrlPushKey ?? '');

super.onInit();
}
Expand All @@ -28,10 +29,15 @@ class RealtimeIrlViewController extends GetxController {
}

Future start() async {
realtimeIrl.status.value = RtIrlStatus.updating;
timerRtIrl = Timer.periodic(const Duration(seconds: 4), (Timer t) async {
DataState<Position> p = await determinePosition();
if (p is DataSuccess && realtimeIrl.status == RtIrlStatus.updating) {

Check notice on line 35 in lib/src/presentation/controllers/realtime_irl_view_controller.dart

View workflow job for this annotation

GitHub Actions / analyze

The type of the right operand ('RtIrlStatus') isn't a subtype or a supertype of the left operand ('Rx<RtIrlStatus>').

Try changing one or both of the operands. See https://dart.dev/lints/unrelated_type_equality_checks to learn more about this problem.
realtimeIrl.updatePosition(p.data!);
DataState updateResult = await realtimeIrl.updatePosition(p.data!);
if(updateResult is DataFailed) {
realtimeIrl.status.value = RtIrlStatus.stopped;
await stop();
}
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/presentation/widgets/tabs/realtime_irl_tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class RealtimeIrlTabView extends GetView<RealtimeIrlViewController> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Container(
child: Obx(() => Container(
alignment: Alignment.center,
child: controller.realtimeIrl.status == RtIrlStatus.updating
child: controller.realtimeIrl.status.value == RtIrlStatus.updating
? _stopUpdatingPosition()
: _startUpdatingPosition(),
),
),),
);
}

Expand Down

0 comments on commit 0bc181e

Please sign in to comment.