Skip to content

Commit

Permalink
Merge pull request #6 from Metatavu/feature-5-skip-updates
Browse files Browse the repository at this point in the history
Added support for skipping updates
  • Loading branch information
lauriLukkarinen committed Apr 25, 2024
2 parents 8ad1ade + 06a99fd commit 832fd72
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
1 change: 1 addition & 0 deletions assets/l10n/fi-FI/localizations.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"updateAvailable": "Sovellukseen on saatavilla päivitys. Ole hyvä ja asenna päivitys painamalla alla olevaa painiketta.",
"installUpdate": "Asenna päivitys",
"installingUpdate": "Asennetaan päivitystä...",
"skipUpdate": "Ohita päivitys",
"loginInstructions": "Aseta digikortti piirturiin ja paina \"Kirjaudu\".",
"login": "Kirjaudu",
"errors": {
Expand Down
3 changes: 3 additions & 0 deletions lib/app/env.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Env {

/// URL for app updates
static const updatesUrl = String.fromEnvironment('UPDATES_URL');

/// Whether updates can be skipped
static const updatesSkippable = bool.fromEnvironment('UPDATES_SKIPPABLE');
}


63 changes: 51 additions & 12 deletions lib/views/login/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "package:flutter/material.dart";
import "package:flutter_hooks/flutter_hooks.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:tms_api/tms_api.dart";
import "package:vp_kuljetus_driver_app/app/env.gen.dart";
import "package:vp_kuljetus_driver_app/providers/authentication/authentication_providers.dart";
import "package:vp_kuljetus_driver_app/providers/trucks/trucks_providers.dart";
import "package:vp_kuljetus_driver_app/services/localization/l10n.dart";
Expand Down Expand Up @@ -63,6 +64,11 @@ class LoginScreen extends HookConsumerWidget {
}
}

/// Skips the update
void skipUpdate() {
updateAvailable.value = false;
}

Future<void> initLogin(final PublicTruck selectedTruck) async {
try {
await authNotifier.login(selectedTruck.id!);
Expand All @@ -81,10 +87,13 @@ class LoginScreen extends HookConsumerWidget {
}
}

useEffect(() {
checkUpdates();
return null;
}, [],);
useEffect(
() {
checkUpdates();
return null;
},
[],
);

return Scaffold(
resizeToAvoidBottomInset: false,
Expand All @@ -109,14 +118,44 @@ class LoginScreen extends HookConsumerWidget {
style: Theme.of(context).textTheme.bodyMedium,
),
const SizedBox(height: 32),
ElevatedButton(
onPressed: !installingUpdate.value
? installUpdate
: null,
child: Text(l10n.t(installingUpdate.value
? "installingUpdate"
: "installUpdate",),),
),
Env.updatesSkippable
? Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: !installingUpdate.value
? installUpdate
: null,
child: Text(
l10n.t(
installingUpdate.value
? "installingUpdate"
: "installUpdate",
),
),
),
ElevatedButton(
onPressed: !installingUpdate.value
? skipUpdate
: null,
child: Text(
l10n.t("skipUpdate"),
),
),
],
)
: ElevatedButton(
onPressed: !installingUpdate.value
? installUpdate
: null,
child: Text(
l10n.t(
installingUpdate.value
? "installingUpdate"
: "installUpdate",
),
),
),
],
)
: Column(
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ dart_define:
- name: KEYCLOAK_CLIENT_SECRET
description: Keycloak client secret
- name: UPDATES_URL
description: URL for app updates
description: URL for app updates
- name: UPDATES_SKIPPABLE
description: Whether updates can be skipped

0 comments on commit 832fd72

Please sign in to comment.