Files
flutter/lib/core/consts.dart
2026-09-27 01:06:32 +02:00

238 lines
9.3 KiB
Dart

/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2020 - 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:intl/intl.dart';
import 'package:material_ui/material_ui.dart';
/// Minimum server version required by this version of the app.
///
/// Bump this value whenever you depend on API changes that are only available
/// in a newer server release. The check is performed during login and
/// auto-login and mirrors what the server does with MIN_APP_VERSION.
///
/// A pre-release is lower than its release, so the spelling decides the
/// meaning:
///
/// '2.8.0-dev.3' at least that point of the 2.8 development cycle
/// '2.8.0' the finished 2.8 or newer, no development server
/// '2.8' the same as '2.8.0'
///
/// While 2.8 is unreleased, only the first form is safe. wger runs master
/// and reports as e.g. 2.8.0-dev.N, so '2.8' would lock the app out of it
/// and out of every self hosted instance following latest, for the whole cycle.
///
/// Count with a dot: '2.8.0-dev.10' is above '2.8.0-dev.9', while
/// '2.8.0-dev10' would sort below '2.8.0-dev9'.
const MIN_SERVER_VERSION = '2.7';
/// Size for the "smaller" icons, e.g. when they belong to less important items
/// and we don't want to fill the whole screen
const double ICON_SIZE_SMALL = 20;
/// Default wger server during login
const DEFAULT_SERVER_PROD = 'https://wger.de';
// Default wger test server during development
const DEFAULT_SERVER_TEST = 'https://dev.wger.de';
const TESTSERVER_USER_NAME = 'user';
const TESTSERVER_PASSWORD = 'flutteruser';
// Weight and repetition units for the workout logs
const REP_UNIT_REPETITIONS_ID = 1;
const REP_UNIT_TILL_FAILURE_ID = 2;
const WEIGHT_UNIT_KG = 1;
const WEIGHT_UNIT_LB = 2;
/// Time to locally cache values such as ingredients, etc
const DAYS_TO_CACHE = 20;
/// Name of the submit button in forms
const SUBMIT_BUTTON_KEY_NAME = 'submit-button';
/// Local Preferences keys
const PREFS_INGREDIENTS = 'ingredientData';
const PREFS_WORKOUT_UNITS = 'workoutUnits';
/// Pre-JWT credential blob. Only still read to delete it on startup.
const PREFS_USER = 'userData';
const PREFS_USER_DARK_THEME = 'userDarkMode';
const PREFS_USER_LOCALE = 'userLocale';
const PREFS_LAST_SERVER = 'lastServer';
/// User preference: use Material You dynamic colors from the platform instead
/// of the fixed wger seed palette. Defaults to [USE_DYNAMIC_COLOR_DEFAULT].
///
/// Android 12+ supplies a wallpaper palette, macOS (10.14+), Windows and
/// GTK-based Linux a system accent color. iOS and the web have no
/// implementation, so the setting is only offered where dynamicColorAvailable
/// reports true.
const PREFS_USE_DYNAMIC_COLOR = 'useDynamicColor';
const USE_DYNAMIC_COLOR_DEFAULT = false;
/// The chart range the measurement screens share, held as `ChartRange.name`
const PREFS_CHART_RANGE = 'measurementChartRange';
/// Headless JWT auth: SharedPreferences keys. The refresh token is **not**
/// stored here, it lives in secure storage (`SECURE_STORAGE_REFRESH_TOKEN`).
const PREFS_ACCESS_TOKEN = 'accessToken';
const PREFS_ACCESS_EXPIRES_AT = 'accessExpiresAt';
const PREFS_SERVER_URL = 'serverUrl';
/// JWT `sub` of the user whose data is materialised in the local PowerSync
/// DB. Compared on login to wipe the DB only on a genuine user switch.
const PREFS_DB_OWNER_USER_ID = 'dbOwnerUserId';
/// User preference: keep the local PowerSync DB on logout instead of wiping
/// it. Defaults to [KEEP_DATA_ON_LOGOUT_DEFAULT].
const PREFS_KEEP_DATA_ON_LOGOUT = 'keepDataOnLogout';
const KEEP_DATA_ON_LOGOUT_DEFAULT = true;
/// User preference: accept an invalid TLS certificate from the configured
/// self-hosted server, so the app can reach instances behind a self-signed
/// cert. Off by default, and never applies to the official servers. Defaults
/// to [ALLOW_SELF_SIGNED_CERTS_DEFAULT].
const PREFS_ALLOW_SELF_SIGNED_CERTS = 'allowSelfSignedCerts';
const ALLOW_SELF_SIGNED_CERTS_DEFAULT = false;
/// User preference: log everything instead of INFO and above, so a bug report
/// also carries the fine-grained diagnostics. Persisted rather than a session
/// switch, the interesting phase is the one right after a cold start.
const PREFS_VERBOSE_LOGGING = 'verboseLogging';
const VERBOSE_LOGGING_DEFAULT = false;
/// Secure-storage key for the headless refresh token.
const SECURE_STORAGE_REFRESH_TOKEN = 'wger_refresh_token';
/// Login-CSRF defence for the web-handoff flow. Stored in SharedPreferences
/// (not a secret, just a one-shot nonce echoed back by the server).
const PREFS_APP_AUTH_STATE = 'appAuthState';
const PREFS_APP_AUTH_STATE_AT = 'appAuthStateAt';
// The server URL the handoff was started for, round-tripped with the nonce so
// the returning token is redeemed against the same (e.g. self-hosted) server.
const PREFS_APP_AUTH_SERVER = 'appAuthServer';
/// True once PowerSync has been reachable for this user at least once
/// (i.e. its liveness probe returned 200).
const PREFS_HAS_EVER_SYNCED = 'hasEverSynced';
/// Absolute URL prefix for server-side media files
const PREFS_MEDIA_URL_PREFIX = 'mediaUrlPrefix';
const DEFAULT_ANIMATION_DURATION = Duration(milliseconds: 200);
const DEFAULT_ANIMATION_CURVE = Curves.bounceIn;
/// Dateformat used when using a date as a key in a dictionary. Using either the
/// regular date object or date.toLocal() can cause problems, depending on the
/// system's settings. Using a string is safer.
//ignore: non_constant_identifier_names
final DateFormatLists = DateFormat('yyyy-MM-dd');
/// Available plate weights, used for the plate calculator
const AVAILABLE_PLATES = [1.25, 2.5, 5, 10, 15];
/// Weight of the bar, used in the plate calculator
const BAR_WEIGHT = 20;
/// ID of the equipment entry for barbell
const ID_EQUIPMENT_BARBELL = 1;
/// kcal per gram of protein (approx)
const ENERGY_PROTEIN = 4;
/// kcal per gram of carbohydrates (approx)
const ENERGY_CARBOHYDRATES = 4;
/// kcal per gram of fat (approx)
const ENERGY_FAT = 9;
/// Language ID for English (fallback)
const LANGUAGE_SHORT_ENGLISH = 'en';
/// IDs of the different image art styles
///
/// Values taken from exercises/models/image.py
enum EXERCISE_IMAGE_ART_STYLE {
// ignore: unused_field
_, // 0 is not used
LINE_ART,
THREE_D,
LOW_POLY,
PHOTO,
OTHER,
}
/// Sentinel UUID for the synthetic "loose log entries" pseudo-meal.
///
/// All-zero UUID is reserved by RFC 4122 (the "nil UUID") and won't collide
/// with any client-generated UUID v4.
const PSEUDO_MEAL_ID = '00000000-0000-0000-0000-000000000000';
/// Colors used for muscles
const COLOR_MAIN_MUSCLES = Colors.red;
const COLOR_SECONDARY_MUSCLES = Colors.orange;
// Min account age to contribute exercises. Needs to be kept in sync with
// the value on the backend
const MIN_ACCOUNT_AGE = 14;
/// Different project URLs
const GITHUB_PROJECT_URL = 'https://github.com/wger-project';
const GITHUB_REPO_URL = '$GITHUB_PROJECT_URL/flutter';
const GITHUB_ISSUES_URL = '$GITHUB_REPO_URL/issues/new/choose';
const GITHUB_ISSUES_BUG_URL = '$GITHUB_REPO_URL/issues/new?template=1_bug.yml';
const GITHUB_SPONSORS_URL = 'https://github.com/sponsors/wger-project';
/// Maximum length for a pre-filled GitHub issue URL. GitHub starts answering
/// issues/new with an error page at roughly 7050 characters (measured 2026-07),
/// so stay well below that.
const GITHUB_ISSUES_MAX_URL_LENGTH = 6500;
const DISCORD_URL = 'https://discord.gg/rPWFv6W';
const MASTODON_URL = 'https://fosstodon.org/@wger';
const READTHEDOCS_URL = 'https://wger.readthedocs.io';
const WEBLATE_URL = 'https://hosted.weblate.org/engage/wger';
const BUY_ME_A_COFFEE_URL = 'https://buymeacoffee.com/wger';
const LIBERAPAY_URL = 'https://liberapay.com/wger';
/// Terms of service and privacy policy, served by every instance. What it says
/// is up to whoever runs the server, upstream ships a placeholder. The Health
/// Connect entry points in MainActivity.kt use wger.de's copy of this page.
const TERMS_OF_SERVICE_PATH = 'software/terms-of-service';
/// Factor to multiply / divide in the charts when converting dates to milliseconds
/// from epoch since fl_charts does not support real time series charts and using
/// the milliseconds themselves can cause the application to crash since it runs
/// out of memory...
const double CHART_MILLISECOND_FACTOR = 100000.0;
enum WeightUnitEnum { kg, lb }
/// TextInputType for decimal numbers
const textInputTypeDecimal = TextInputType.numberWithOptions(decimal: true);
const String API_MAX_PAGE_SIZE = '999';
const String API_RESULTS_PAGE_SIZE = '100';
/// Marker used for identifying interpolated values in a list, e.g. for measurements
/// the milliseconds in the entry date are set to this value
const INTERPOLATION_MARKER = 123;
/// Creative Commons license IDs
const CC_BY_SA_4_ID = 2;