mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Move flag checking for minimum required version to manifest
This is still not the best solution, ideally we would save this to some kind of configuration file that we can use for dev/prod etc. Also, this solution doesn't work with iOS or web
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
|
||||
<meta-data android:name="wger.api_key" android:value="${WGER_API_KEY}" />
|
||||
<meta-data android:name="wger.check_min_app_version" android:value="true" />
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
|
||||
@@ -26,6 +26,10 @@ const double ICON_SIZE_SMALL = 20;
|
||||
/// Default wger server during login
|
||||
const DEFAULT_SERVER = 'https://wger.de';
|
||||
|
||||
/// Keys used in the android manifest
|
||||
const MANIFEST_KEY_API = 'wger.api_key';
|
||||
const MANIFEST_KEY_CHECK_UPDATE = 'wger.check_min_app_version';
|
||||
|
||||
/// Default weight unit is "kg"
|
||||
const DEFAULT_WEIGHT_UNIT = 1;
|
||||
|
||||
@@ -70,6 +74,3 @@ const ENERGY_CARBOHYDRATES = 4;
|
||||
|
||||
/// kcal per gram of fat (approx)
|
||||
const ENERGY_FAT = 9;
|
||||
|
||||
/// Flag to check for updates to the new version.
|
||||
const CHECK_APP_MIN_VERSION = false;
|
||||
|
||||
@@ -39,11 +39,18 @@ class AuthProvider with ChangeNotifier {
|
||||
String? serverUrl;
|
||||
String? serverVersion;
|
||||
PackageInfo? applicationVersion;
|
||||
Map<String, String>? metadata = {};
|
||||
|
||||
late http.Client client;
|
||||
|
||||
AuthProvider([http.Client? client]) {
|
||||
this.client = client ?? http.Client();
|
||||
|
||||
try {
|
||||
AndroidMetadata.metaDataAsMap.then((value) => metadata = value);
|
||||
} on PlatformException {
|
||||
throw Exception('An error occurred reading the metadata from AndroidManifest');
|
||||
}
|
||||
}
|
||||
|
||||
/// flag to indicate that the application has successfully loaded all initial data
|
||||
@@ -85,7 +92,8 @@ class AuthProvider with ChangeNotifier {
|
||||
|
||||
/// Checking if there is a new version of the application.
|
||||
Future<bool> applicationUpdateRequired([String? version]) async {
|
||||
if (!CHECK_APP_MIN_VERSION) {
|
||||
if (metadata!.containsKey('wger.check_min_app_version') ||
|
||||
metadata!['wger.check_min_app_version'] == 'false') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -105,14 +113,6 @@ class AuthProvider with ChangeNotifier {
|
||||
required String email,
|
||||
required String serverUrl}) async {
|
||||
final uri = Uri.parse('$serverUrl/api/v2/register/');
|
||||
Map<String, String>? metadata = {};
|
||||
|
||||
// Read the api key from the manifest file
|
||||
try {
|
||||
metadata = await AndroidMetadata.metaDataAsMap;
|
||||
} on PlatformException {
|
||||
throw Exception('An error occurred reading the API key');
|
||||
}
|
||||
|
||||
// Register
|
||||
try {
|
||||
@@ -124,7 +124,7 @@ class AuthProvider with ChangeNotifier {
|
||||
uri,
|
||||
headers: {
|
||||
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
|
||||
HttpHeaders.authorizationHeader: "Token ${metadata!['wger.api_key']}"
|
||||
HttpHeaders.authorizationHeader: 'Token ${metadata![MANIFEST_KEY_API]}'
|
||||
},
|
||||
body: json.encode(data),
|
||||
);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:android_metadata/android_metadata.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
@@ -119,11 +118,10 @@ class _AuthCardState extends State<AuthCard> {
|
||||
//
|
||||
// If not, the user will not be able to register via the app
|
||||
try {
|
||||
AndroidMetadata.metaDataAsMap.then((data) {
|
||||
if (!data!.containsKey('wger.api_key') || data['wger.api_key'] == '') {
|
||||
_canRegister = false;
|
||||
}
|
||||
});
|
||||
final metadata = Provider.of<AuthProvider>(context, listen: false).metadata;
|
||||
if (metadata!.containsKey(MANIFEST_KEY_API) || metadata[MANIFEST_KEY_API] == '') {
|
||||
_canRegister = false;
|
||||
}
|
||||
} on PlatformException {
|
||||
_canRegister = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user