Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #208

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
}

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
Loading