mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-17 16:07:51 +01:00
Run "dart format --line-length=100 ." to make the diff smaller
This commit is contained in:
@@ -18,8 +18,7 @@ void main(List<String> arguments) async {
|
||||
'You must run this script with a metadata file argument, using the --meta flag.');
|
||||
}
|
||||
if (arguments.length == metaIndex + 1) {
|
||||
throw Exception(
|
||||
'The --meta flag must be followed by the path to the metadata file.');
|
||||
throw Exception('The --meta flag must be followed by the path to the metadata file.');
|
||||
}
|
||||
|
||||
final metaFile = File(arguments[metaIndex + 1]);
|
||||
@@ -31,18 +30,14 @@ void main(List<String> arguments) async {
|
||||
|
||||
final fetchFromGithub = arguments.contains('--github');
|
||||
|
||||
final outputDir =
|
||||
Directory('${Directory.current.path}/flatpak_generator_exports');
|
||||
final outputDir = Directory('${Directory.current.path}/flatpak_generator_exports');
|
||||
outputDir.createSync();
|
||||
|
||||
final packageGenerator =
|
||||
PackageGenerator(inputDir: metaFile.parent, meta: meta);
|
||||
final packageGenerator = PackageGenerator(inputDir: metaFile.parent, meta: meta);
|
||||
|
||||
packageGenerator.generatePackage(
|
||||
outputDir,
|
||||
PackageGenerator.runningOnARM()
|
||||
? CPUArchitecture.aarch64
|
||||
: CPUArchitecture.x86_64,
|
||||
PackageGenerator.runningOnARM() ? CPUArchitecture.aarch64 : CPUArchitecture.x86_64,
|
||||
fetchFromGithub,
|
||||
);
|
||||
}
|
||||
@@ -54,8 +49,8 @@ class PackageGenerator {
|
||||
|
||||
PackageGenerator({required this.inputDir, required this.meta});
|
||||
|
||||
Future<void> generatePackage(Directory outputDir, CPUArchitecture arch,
|
||||
bool fetchReleasesFromGithub) async {
|
||||
Future<void> generatePackage(
|
||||
Directory outputDir, CPUArchitecture arch, bool fetchReleasesFromGithub) async {
|
||||
final tempDir = outputDir.createTempSync('flutter_generator_temp');
|
||||
final appId = meta.appId;
|
||||
|
||||
@@ -90,8 +85,7 @@ class PackageGenerator {
|
||||
}
|
||||
|
||||
final editedAppDataContent = AppDataModifier.replaceVersions(
|
||||
origAppDataFile.readAsStringSync(),
|
||||
await meta.getReleases(fetchReleasesFromGithub));
|
||||
origAppDataFile.readAsStringSync(), await meta.getReleases(fetchReleasesFromGithub));
|
||||
|
||||
final editedAppDataFile = File('${tempDir.path}/$appId.appdata.xml');
|
||||
editedAppDataFile.writeAsStringSync(editedAppDataContent);
|
||||
@@ -107,21 +101,17 @@ class PackageGenerator {
|
||||
final destDir = Directory('${tempDir.path}/bin');
|
||||
destDir.createSync();
|
||||
|
||||
final baseFileName =
|
||||
'${meta.lowercaseAppName}-linux-${arch.flatpakArchCode}';
|
||||
final baseFileName = '${meta.lowercaseAppName}-linux-${arch.flatpakArchCode}';
|
||||
|
||||
final packagePath = '${outputDir.absolute.path}/$baseFileName.tar.gz';
|
||||
Process.runSync(
|
||||
'cp', ['-r', '${buildDir.absolute.path}/.', destDir.absolute.path]);
|
||||
Process.runSync('tar', ['-czvf', packagePath, '.'],
|
||||
workingDirectory: tempDir.absolute.path);
|
||||
Process.runSync('cp', ['-r', '${buildDir.absolute.path}/.', destDir.absolute.path]);
|
||||
Process.runSync('tar', ['-czvf', packagePath, '.'], workingDirectory: tempDir.absolute.path);
|
||||
print('Generated $packagePath');
|
||||
|
||||
final preShasum = Process.runSync('shasum', ['-a', '256', packagePath]);
|
||||
final sha256 = preShasum.stdout.toString().split(' ').first;
|
||||
|
||||
final shaFile = await File('${outputDir.path}/$baseFileName.sha256')
|
||||
.writeAsString(sha256);
|
||||
final shaFile = await File('${outputDir.path}/$baseFileName.sha256').writeAsString(sha256);
|
||||
print('Generated ${shaFile.path}');
|
||||
|
||||
shaByArch.putIfAbsent(arch, () => sha256);
|
||||
@@ -138,21 +128,17 @@ class PackageGenerator {
|
||||
|
||||
// updates releases in ${appName}.appdata.xml
|
||||
class AppDataModifier {
|
||||
static String replaceVersions(
|
||||
String origAppDataContent, List<Release> versions) {
|
||||
final joinedReleases = versions
|
||||
.map((v) => '\t\t<release version="${v.version}" date="${v.date}" />')
|
||||
.join('\n');
|
||||
final releasesSection =
|
||||
'<releases>\n$joinedReleases\n\t</releases>'; //todo check this
|
||||
static String replaceVersions(String origAppDataContent, List<Release> versions) {
|
||||
final joinedReleases =
|
||||
versions.map((v) => '\t\t<release version="${v.version}" date="${v.date}" />').join('\n');
|
||||
final releasesSection = '<releases>\n$joinedReleases\n\t</releases>'; //todo check this
|
||||
if (origAppDataContent.contains('<releases')) {
|
||||
return origAppDataContent
|
||||
.replaceAll('\n', '<~>')
|
||||
.replaceFirst(RegExp('<releases.*</releases>'), releasesSection)
|
||||
.replaceAll('<~>', '\n');
|
||||
} else {
|
||||
return origAppDataContent.replaceFirst(
|
||||
'</component>', '\n\t$releasesSection\n</component>');
|
||||
return origAppDataContent.replaceFirst('</component>', '\n\t$releasesSection\n</component>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,9 +43,8 @@ class Icon {
|
||||
_fileExtension = path.split('.').last;
|
||||
}
|
||||
|
||||
String getFilename(String appId) => (type == _symbolicType)
|
||||
? '$appId-symbolic.$_fileExtension'
|
||||
: '$appId.$_fileExtension';
|
||||
String getFilename(String appId) =>
|
||||
(type == _symbolicType) ? '$appId-symbolic.$_fileExtension' : '$appId.$_fileExtension';
|
||||
}
|
||||
|
||||
class GithubReleases {
|
||||
@@ -74,8 +73,7 @@ class GithubReleases {
|
||||
final releaseJsonContent = (await http.get(Uri(
|
||||
scheme: 'https',
|
||||
host: 'api.github.com',
|
||||
path:
|
||||
'/repos/$githubReleaseOrganization/$githubReleaseProject/releases')))
|
||||
path: '/repos/$githubReleaseOrganization/$githubReleaseProject/releases')))
|
||||
.body;
|
||||
final decodedJson = jsonDecode(releaseJsonContent) as List;
|
||||
|
||||
@@ -86,10 +84,8 @@ class GithubReleases {
|
||||
await Future.forEach<dynamic>(decodedJson, (dynamic releaseDynamic) async {
|
||||
final releaseMap = releaseDynamic as Map;
|
||||
|
||||
final releaseDateAndTime =
|
||||
DateTime.parse(releaseMap['published_at'] as String);
|
||||
final releaseDateString =
|
||||
releaseDateAndTime.toIso8601String().split('T').first;
|
||||
final releaseDateAndTime = DateTime.parse(releaseMap['published_at'] as String);
|
||||
final releaseDateString = releaseDateAndTime.toIso8601String().split('T').first;
|
||||
|
||||
if (latestReleaseAssetDate == null ||
|
||||
(latestReleaseAssetDate?.compareTo(releaseDateAndTime) == -1)) {
|
||||
@@ -100,8 +96,7 @@ class GithubReleases {
|
||||
}
|
||||
}
|
||||
|
||||
releases.add(Release(
|
||||
version: releaseMap['name'] as String, date: releaseDateString));
|
||||
releases.add(Release(version: releaseMap['name'] as String, date: releaseDateString));
|
||||
});
|
||||
|
||||
if (releases.isNotEmpty) {
|
||||
@@ -120,8 +115,7 @@ class GithubReleases {
|
||||
final downloadUrl = amMap['browser_download_url'] as String;
|
||||
final filename = amMap['name'] as String;
|
||||
final fileExtension = filename.substring(filename.indexOf('.') + 1);
|
||||
final filenameWithoutExtension =
|
||||
filename.substring(0, filename.indexOf('.'));
|
||||
final filenameWithoutExtension = filename.substring(0, filename.indexOf('.'));
|
||||
|
||||
final arch = filenameWithoutExtension.endsWith('aarch64')
|
||||
? CPUArchitecture.aarch64
|
||||
@@ -218,8 +212,7 @@ class FlatpakMeta {
|
||||
: _localReleases = localReleases,
|
||||
_localReleaseAssets = localReleaseAssets {
|
||||
if (githubReleaseOrganization != null && githubReleaseProject != null) {
|
||||
_githubReleases =
|
||||
GithubReleases(githubReleaseOrganization!, githubReleaseProject!);
|
||||
_githubReleases = GithubReleases(githubReleaseOrganization!, githubReleaseProject!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,15 +225,13 @@ class FlatpakMeta {
|
||||
return await _githubReleases!.getReleases();
|
||||
} else {
|
||||
if (_localReleases == null) {
|
||||
throw Exception(
|
||||
'Metadata must include releases if not fetching releases from Github.');
|
||||
throw Exception('Metadata must include releases if not fetching releases from Github.');
|
||||
}
|
||||
return _localReleases!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<ReleaseAsset>?> getReleaseAssets(
|
||||
bool fetchReleasesFromGithub) async {
|
||||
Future<List<ReleaseAsset>?> getReleaseAssets(bool fetchReleasesFromGithub) async {
|
||||
if (fetchReleasesFromGithub) {
|
||||
if (_githubReleases == null) {
|
||||
throw Exception(
|
||||
@@ -249,8 +240,7 @@ class FlatpakMeta {
|
||||
return _githubReleases!.getLatestReleaseAssets();
|
||||
} else {
|
||||
if (_localReleases == null) {
|
||||
throw Exception(
|
||||
'Metadata must include releases if not fetching releases from Github.');
|
||||
throw Exception('Metadata must include releases if not fetching releases from Github.');
|
||||
}
|
||||
return _localReleaseAssets;
|
||||
}
|
||||
@@ -262,17 +252,13 @@ class FlatpakMeta {
|
||||
return FlatpakMeta(
|
||||
appId: json['appId'] as String,
|
||||
lowercaseAppName: json['lowercaseAppName'] as String,
|
||||
githubReleaseOrganization:
|
||||
json['githubReleaseOrganization'] as String?,
|
||||
githubReleaseOrganization: json['githubReleaseOrganization'] as String?,
|
||||
githubReleaseProject: json['githubReleaseProject'] as String?,
|
||||
localReleases: (json['localReleases'] as List?)?.map((dynamic r) {
|
||||
final rMap = r as Map;
|
||||
return Release(
|
||||
version: rMap['version'] as String,
|
||||
date: rMap['date'] as String);
|
||||
return Release(version: rMap['version'] as String, date: rMap['date'] as String);
|
||||
}).toList(),
|
||||
localReleaseAssets:
|
||||
(json['localReleaseAssets'] as List?)?.map((dynamic ra) {
|
||||
localReleaseAssets: (json['localReleaseAssets'] as List?)?.map((dynamic ra) {
|
||||
final raMap = ra as Map;
|
||||
final archString = raMap['arch'] as String;
|
||||
final arch = (archString == CPUArchitecture.x86_64.flatpakArchCode)
|
||||
@@ -284,10 +270,8 @@ class FlatpakMeta {
|
||||
throw Exception(
|
||||
'Architecture must be either "${CPUArchitecture.x86_64.flatpakArchCode}" or "${CPUArchitecture.aarch64.flatpakArchCode}"');
|
||||
}
|
||||
final tarballPath =
|
||||
'${jsonFile.parent.path}/${raMap['tarballPath'] as String}';
|
||||
final preShasum =
|
||||
Process.runSync('shasum', ['-a', '256', tarballPath]);
|
||||
final tarballPath = '${jsonFile.parent.path}/${raMap['tarballPath'] as String}';
|
||||
final preShasum = Process.runSync('shasum', ['-a', '256', tarballPath]);
|
||||
final shasum = preShasum.stdout.toString().split(' ').first;
|
||||
if (preShasum.exitCode != 0) {
|
||||
throw Exception(preShasum.stderr);
|
||||
@@ -302,17 +286,14 @@ class FlatpakMeta {
|
||||
appDataPath: json['appDataPath'] as String,
|
||||
desktopPath: json['desktopPath'] as String,
|
||||
icons: (json['icons'] as Map).entries.map((mapEntry) {
|
||||
return Icon(
|
||||
type: mapEntry.key as String, path: mapEntry.value as String);
|
||||
return Icon(type: mapEntry.key as String, path: mapEntry.value as String);
|
||||
}).toList(),
|
||||
freedesktopRuntime: json['freedesktopRuntime'] as String,
|
||||
buildCommandsAfterUnpack: (json['buildCommandsAfterUnpack'] as List?)
|
||||
?.map((dynamic bc) => bc as String)
|
||||
.toList(),
|
||||
extraModules: json['extraModules'] as List?,
|
||||
finishArgs: (json['finishArgs'] as List)
|
||||
.map((dynamic fa) => fa as String)
|
||||
.toList());
|
||||
finishArgs: (json['finishArgs'] as List).map((dynamic fa) => fa as String).toList());
|
||||
} catch (e) {
|
||||
throw Exception('Could not parse JSON file, due to this error:\n$e');
|
||||
}
|
||||
|
||||
@@ -14,8 +14,7 @@ void main(List<String> arguments) async {
|
||||
'You must run this script with a metadata file argument, using the --meta flag.');
|
||||
}
|
||||
if (arguments.length == metaIndex + 1) {
|
||||
throw Exception(
|
||||
'The --meta flag must be followed by the path to the metadata file.');
|
||||
throw Exception('The --meta flag must be followed by the path to the metadata file.');
|
||||
}
|
||||
|
||||
final metaFile = File(arguments[metaIndex + 1]);
|
||||
@@ -27,20 +26,17 @@ void main(List<String> arguments) async {
|
||||
|
||||
final fetchFromGithub = arguments.contains('--github');
|
||||
|
||||
final outputDir =
|
||||
Directory('${Directory.current.path}/flatpak_generator_exports');
|
||||
final outputDir = Directory('${Directory.current.path}/flatpak_generator_exports');
|
||||
outputDir.createSync();
|
||||
|
||||
final manifestGenerator = FlatpakManifestGenerator(meta);
|
||||
final manifestContent =
|
||||
await manifestGenerator.generateFlatpakManifest(fetchFromGithub);
|
||||
final manifestContent = await manifestGenerator.generateFlatpakManifest(fetchFromGithub);
|
||||
final manifestPath = '${outputDir.path}/${meta.appId}.json';
|
||||
final manifestFile = File(manifestPath);
|
||||
manifestFile.writeAsStringSync(manifestContent);
|
||||
print('Generated $manifestPath');
|
||||
|
||||
final flathubJsonContent =
|
||||
await manifestGenerator.generateFlathubJson(fetchFromGithub);
|
||||
final flathubJsonContent = await manifestGenerator.generateFlathubJson(fetchFromGithub);
|
||||
if (flathubJsonContent != null) {
|
||||
final flathubJsonPath = '${outputDir.path}/flathub.json';
|
||||
final flathubJsonFile = File(flathubJsonPath);
|
||||
@@ -119,8 +115,7 @@ class FlatpakManifestGenerator {
|
||||
|
||||
const encoder = JsonEncoder.withIndent(' ');
|
||||
|
||||
final onlyArchListInput =
|
||||
fetchFromGithub ? _githubArchSupport! : _localArchSupport!;
|
||||
final onlyArchListInput = fetchFromGithub ? _githubArchSupport! : _localArchSupport!;
|
||||
|
||||
final onlyArchList = List<String>.empty(growable: true);
|
||||
for (final e in onlyArchListInput.entries) {
|
||||
@@ -136,8 +131,7 @@ class FlatpakManifestGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
void _lazyGenerateArchSupportMap(
|
||||
bool fetchFromGithub, List<ReleaseAsset> assets) {
|
||||
void _lazyGenerateArchSupportMap(bool fetchFromGithub, List<ReleaseAsset> assets) {
|
||||
if (fetchFromGithub) {
|
||||
if (_githubArchSupport == null) {
|
||||
_githubArchSupport = <CPUArchitecture, bool>{
|
||||
|
||||
@@ -34,20 +34,17 @@ Widget createDashboardScreen({locale = 'en'}) {
|
||||
}
|
||||
]
|
||||
};
|
||||
when(mockWorkoutProvider.fetchSessionData())
|
||||
.thenAnswer((a) => Future.value(logs));
|
||||
when(mockWorkoutProvider.fetchSessionData()).thenAnswer((a) => Future.value(logs));
|
||||
|
||||
final mockNutritionProvider = MockNutritionPlansProvider();
|
||||
when(mockNutritionProvider.currentPlan)
|
||||
.thenAnswer((realInvocation) => getNutritionalPlan());
|
||||
when(mockNutritionProvider.currentPlan).thenAnswer((realInvocation) => getNutritionalPlan());
|
||||
when(mockNutritionProvider.items).thenReturn([getNutritionalPlan()]);
|
||||
|
||||
final mockWeightProvider = MockBodyWeightProvider();
|
||||
when(mockWeightProvider.items).thenReturn(getWeightEntries());
|
||||
|
||||
final mockMeasurementProvider = MockMeasurementProvider();
|
||||
when(mockMeasurementProvider.categories)
|
||||
.thenReturn(getMeasurementCategories());
|
||||
when(mockMeasurementProvider.categories).thenReturn(getMeasurementCategories());
|
||||
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
|
||||
@@ -15,8 +15,7 @@ Widget createWorkoutDetailScreen({locale = 'en'}) {
|
||||
final mockWorkoutProvider = MockWorkoutPlansProvider();
|
||||
final workout = getWorkout();
|
||||
when(mockWorkoutProvider.activePlan).thenReturn(workout);
|
||||
when(mockWorkoutProvider.fetchAndSetWorkoutPlanFull(1))
|
||||
.thenAnswer((_) => Future.value(workout));
|
||||
when(mockWorkoutProvider.fetchAndSetWorkoutPlanFull(1)).thenAnswer((_) => Future.value(workout));
|
||||
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
|
||||
@@ -20,10 +20,8 @@ Widget createGymModeScreen({locale = 'en'}) {
|
||||
|
||||
final mockExerciseProvider = MockExercisesProvider();
|
||||
|
||||
when(mockExerciseProvider.findExerciseBaseById(1))
|
||||
.thenReturn(bases[0]); // bench press
|
||||
when(mockExerciseProvider.findExerciseBaseById(6))
|
||||
.thenReturn(bases[5]); // side raises
|
||||
when(mockExerciseProvider.findExerciseBaseById(1)).thenReturn(bases[0]); // bench press
|
||||
when(mockExerciseProvider.findExerciseBaseById(6)).thenReturn(bases[5]); // side raises
|
||||
//when(mockExerciseProvider.findExerciseBaseById(2)).thenReturn(bases[1]); // crunches
|
||||
//when(mockExerciseProvider.findExerciseBaseById(3)).thenReturn(bases[2]); // dead lift
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@ import '../test_data/measurements.dart';
|
||||
|
||||
Widget createMeasurementScreen({locale = 'en'}) {
|
||||
final mockMeasurementProvider = MockMeasurementProvider();
|
||||
when(mockMeasurementProvider.categories)
|
||||
.thenReturn(getMeasurementCategories());
|
||||
when(mockMeasurementProvider.categories).thenReturn(getMeasurementCategories());
|
||||
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
|
||||
@@ -11,14 +11,12 @@ import '4_measurements.dart';
|
||||
import '5_nutritional_plan.dart';
|
||||
import '6_weight.dart';
|
||||
|
||||
Future<void> takeScreenshot(
|
||||
tester, binding, String language, String name) async {
|
||||
Future<void> takeScreenshot(tester, binding, String language, String name) async {
|
||||
if (Platform.isAndroid) {
|
||||
await binding.convertFlutterSurfaceToImage();
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
final filename =
|
||||
'fastlane/metadata/android/$language/images/phoneScreenshots/$name.png';
|
||||
final filename = 'fastlane/metadata/android/$language/images/phoneScreenshots/$name.png';
|
||||
await binding.takeScreenshot(filename);
|
||||
}
|
||||
|
||||
@@ -62,10 +60,8 @@ void main() {
|
||||
await takeScreenshot(tester, binding, language, '01 - dashboard');
|
||||
});
|
||||
|
||||
testWidgets('workout detail screen - $language',
|
||||
(WidgetTester tester) async {
|
||||
await tester
|
||||
.pumpWidget(createWorkoutDetailScreen(locale: languageCode));
|
||||
testWidgets('workout detail screen - $language', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createWorkoutDetailScreen(locale: languageCode));
|
||||
await tester.tap(find.byType(TextButton));
|
||||
await tester.pumpAndSettle();
|
||||
await takeScreenshot(tester, binding, language, '02 - workout detail');
|
||||
@@ -78,24 +74,19 @@ void main() {
|
||||
await takeScreenshot(tester, binding, language, '03 - gym mode');
|
||||
});
|
||||
|
||||
testWidgets('measurement screen - $language',
|
||||
(WidgetTester tester) async {
|
||||
testWidgets('measurement screen - $language', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createMeasurementScreen(locale: languageCode));
|
||||
await takeScreenshot(tester, binding, language, '04 - measurements');
|
||||
});
|
||||
|
||||
testWidgets('nutritional plan detail - $language',
|
||||
(WidgetTester tester) async {
|
||||
await tester
|
||||
.pumpWidget(createNutritionalPlanScreen(locale: languageCode));
|
||||
testWidgets('nutritional plan detail - $language', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createNutritionalPlanScreen(locale: languageCode));
|
||||
await tester.tap(find.byType(TextButton));
|
||||
await tester.pumpAndSettle();
|
||||
await takeScreenshot(
|
||||
tester, binding, language, '05 - nutritional plan');
|
||||
await takeScreenshot(tester, binding, language, '05 - nutritional plan');
|
||||
});
|
||||
|
||||
testWidgets('body weight screen - $language',
|
||||
(WidgetTester tester) async {
|
||||
testWidgets('body weight screen - $language', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(createWeightScreen(locale: languageCode));
|
||||
await tester.pumpAndSettle();
|
||||
await takeScreenshot(tester, binding, language, '06 - weight');
|
||||
|
||||
@@ -17,16 +17,12 @@ part 'exercise_database.g.dart';
|
||||
@DataClassName('ExerciseTable')
|
||||
class ExerciseTableItems extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
TextColumn get exercisebase =>
|
||||
text().map(const ExerciseBaseConverter()).nullable()();
|
||||
TextColumn get exercisebase => text().map(const ExerciseBaseConverter()).nullable()();
|
||||
TextColumn get muscle => text().map(const MuscleConverter()).nullable()();
|
||||
TextColumn get category =>
|
||||
text().map(const ExerciseCategoryConverter()).nullable()();
|
||||
TextColumn get variation =>
|
||||
text().map(const VariationConverter()).nullable()();
|
||||
TextColumn get category => text().map(const ExerciseCategoryConverter()).nullable()();
|
||||
TextColumn get variation => text().map(const VariationConverter()).nullable()();
|
||||
TextColumn get language => text().map(const LanguageConverter()).nullable()();
|
||||
TextColumn get equipment =>
|
||||
text().map(const EquipmentConverter()).nullable()();
|
||||
TextColumn get equipment => text().map(const EquipmentConverter()).nullable()();
|
||||
DateTimeColumn get expiresIn => dateTime().nullable()();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,76 +11,55 @@ class $ExerciseTableItemsTable extends ExerciseTableItems
|
||||
$ExerciseTableItemsTable(this.attachedDatabase, [this._alias]);
|
||||
static const VerificationMeta _idMeta = const VerificationMeta('id');
|
||||
@override
|
||||
late final GeneratedColumn<int> id = GeneratedColumn<int>(
|
||||
'id', aliasedName, false,
|
||||
late final GeneratedColumn<int> id = GeneratedColumn<int>('id', aliasedName, false,
|
||||
hasAutoIncrement: true,
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: false,
|
||||
defaultConstraints:
|
||||
GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT'));
|
||||
static const VerificationMeta _exercisebaseMeta =
|
||||
const VerificationMeta('exercisebase');
|
||||
defaultConstraints: GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT'));
|
||||
static const VerificationMeta _exercisebaseMeta = const VerificationMeta('exercisebase');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<ExerciseBase?, String>
|
||||
exercisebase = GeneratedColumn<String>('exercisebase', aliasedName, true,
|
||||
late final GeneratedColumnWithTypeConverter<ExerciseBase?, String> exercisebase =
|
||||
GeneratedColumn<String>('exercisebase', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<ExerciseBase?>(
|
||||
$ExerciseTableItemsTable.$converterexercisebasen);
|
||||
.withConverter<ExerciseBase?>($ExerciseTableItemsTable.$converterexercisebasen);
|
||||
static const VerificationMeta _muscleMeta = const VerificationMeta('muscle');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<Muscle?, String> muscle =
|
||||
GeneratedColumn<String>('muscle', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<Muscle?>($ExerciseTableItemsTable.$convertermusclen);
|
||||
static const VerificationMeta _categoryMeta =
|
||||
const VerificationMeta('category');
|
||||
late final GeneratedColumnWithTypeConverter<Muscle?, String> muscle = GeneratedColumn<String>(
|
||||
'muscle', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<Muscle?>($ExerciseTableItemsTable.$convertermusclen);
|
||||
static const VerificationMeta _categoryMeta = const VerificationMeta('category');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<ExerciseCategory?, String>
|
||||
category = GeneratedColumn<String>('category', aliasedName, true,
|
||||
late final GeneratedColumnWithTypeConverter<ExerciseCategory?, String> category =
|
||||
GeneratedColumn<String>('category', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<ExerciseCategory?>(
|
||||
$ExerciseTableItemsTable.$convertercategoryn);
|
||||
static const VerificationMeta _variationMeta =
|
||||
const VerificationMeta('variation');
|
||||
.withConverter<ExerciseCategory?>($ExerciseTableItemsTable.$convertercategoryn);
|
||||
static const VerificationMeta _variationMeta = const VerificationMeta('variation');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<Variation?, String> variation =
|
||||
GeneratedColumn<String>('variation', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<Variation?>(
|
||||
$ExerciseTableItemsTable.$convertervariationn);
|
||||
static const VerificationMeta _languageMeta =
|
||||
const VerificationMeta('language');
|
||||
.withConverter<Variation?>($ExerciseTableItemsTable.$convertervariationn);
|
||||
static const VerificationMeta _languageMeta = const VerificationMeta('language');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<Language?, String> language =
|
||||
GeneratedColumn<String>('language', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<Language?>(
|
||||
$ExerciseTableItemsTable.$converterlanguagen);
|
||||
static const VerificationMeta _equipmentMeta =
|
||||
const VerificationMeta('equipment');
|
||||
late final GeneratedColumnWithTypeConverter<Language?, String> language = GeneratedColumn<String>(
|
||||
'language', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<Language?>($ExerciseTableItemsTable.$converterlanguagen);
|
||||
static const VerificationMeta _equipmentMeta = const VerificationMeta('equipment');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<Equipment?, String> equipment =
|
||||
GeneratedColumn<String>('equipment', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<Equipment?>(
|
||||
$ExerciseTableItemsTable.$converterequipmentn);
|
||||
static const VerificationMeta _expiresInMeta =
|
||||
const VerificationMeta('expiresIn');
|
||||
.withConverter<Equipment?>($ExerciseTableItemsTable.$converterequipmentn);
|
||||
static const VerificationMeta _expiresInMeta = const VerificationMeta('expiresIn');
|
||||
@override
|
||||
late final GeneratedColumn<DateTime> expiresIn = GeneratedColumn<DateTime>(
|
||||
'expires_in', aliasedName, true,
|
||||
type: DriftSqlType.dateTime, requiredDuringInsert: false);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [
|
||||
id,
|
||||
exercisebase,
|
||||
muscle,
|
||||
category,
|
||||
variation,
|
||||
language,
|
||||
equipment,
|
||||
expiresIn
|
||||
];
|
||||
List<GeneratedColumn> get $columns =>
|
||||
[id, exercisebase, muscle, category, variation, language, equipment, expiresIn];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@override
|
||||
@@ -101,8 +80,8 @@ class $ExerciseTableItemsTable extends ExerciseTableItems
|
||||
context.handle(_languageMeta, const VerificationResult.success());
|
||||
context.handle(_equipmentMeta, const VerificationResult.success());
|
||||
if (data.containsKey('expires_in')) {
|
||||
context.handle(_expiresInMeta,
|
||||
expiresIn.isAcceptableOrUnknown(data['expires_in']!, _expiresInMeta));
|
||||
context.handle(
|
||||
_expiresInMeta, expiresIn.isAcceptableOrUnknown(data['expires_in']!, _expiresInMeta));
|
||||
}
|
||||
return context;
|
||||
}
|
||||
@@ -113,26 +92,20 @@ class $ExerciseTableItemsTable extends ExerciseTableItems
|
||||
ExerciseTable map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return ExerciseTable(
|
||||
id: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
|
||||
exercisebase: $ExerciseTableItemsTable.$converterexercisebasen.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string, data['${effectivePrefix}exercisebase'])),
|
||||
id: attachedDatabase.typeMapping.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
|
||||
exercisebase: $ExerciseTableItemsTable.$converterexercisebasen.fromSql(attachedDatabase
|
||||
.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}exercisebase'])),
|
||||
muscle: $ExerciseTableItemsTable.$convertermusclen.fromSql(
|
||||
attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}muscle'])),
|
||||
category: $ExerciseTableItemsTable.$convertercategoryn.fromSql(
|
||||
attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}category'])),
|
||||
variation: $ExerciseTableItemsTable.$convertervariationn.fromSql(
|
||||
attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}variation'])),
|
||||
language: $ExerciseTableItemsTable.$converterlanguagen.fromSql(
|
||||
attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}language'])),
|
||||
equipment: $ExerciseTableItemsTable.$converterequipmentn.fromSql(
|
||||
attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}equipment'])),
|
||||
attachedDatabase.typeMapping.read(DriftSqlType.string, data['${effectivePrefix}muscle'])),
|
||||
category: $ExerciseTableItemsTable.$convertercategoryn.fromSql(attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}category'])),
|
||||
variation: $ExerciseTableItemsTable.$convertervariationn.fromSql(attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}variation'])),
|
||||
language: $ExerciseTableItemsTable.$converterlanguagen.fromSql(attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}language'])),
|
||||
equipment: $ExerciseTableItemsTable.$converterequipmentn.fromSql(attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}equipment'])),
|
||||
expiresIn: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.dateTime, data['${effectivePrefix}expires_in']),
|
||||
);
|
||||
@@ -143,28 +116,23 @@ class $ExerciseTableItemsTable extends ExerciseTableItems
|
||||
return $ExerciseTableItemsTable(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
static TypeConverter<ExerciseBase, String> $converterexercisebase =
|
||||
const ExerciseBaseConverter();
|
||||
static TypeConverter<ExerciseBase, String> $converterexercisebase = const ExerciseBaseConverter();
|
||||
static TypeConverter<ExerciseBase?, String?> $converterexercisebasen =
|
||||
NullAwareTypeConverter.wrap($converterexercisebase);
|
||||
static TypeConverter<Muscle, String> $convertermuscle =
|
||||
const MuscleConverter();
|
||||
static TypeConverter<Muscle, String> $convertermuscle = const MuscleConverter();
|
||||
static TypeConverter<Muscle?, String?> $convertermusclen =
|
||||
NullAwareTypeConverter.wrap($convertermuscle);
|
||||
static TypeConverter<ExerciseCategory, String> $convertercategory =
|
||||
const ExerciseCategoryConverter();
|
||||
static TypeConverter<ExerciseCategory?, String?> $convertercategoryn =
|
||||
NullAwareTypeConverter.wrap($convertercategory);
|
||||
static TypeConverter<Variation, String> $convertervariation =
|
||||
const VariationConverter();
|
||||
static TypeConverter<Variation, String> $convertervariation = const VariationConverter();
|
||||
static TypeConverter<Variation?, String?> $convertervariationn =
|
||||
NullAwareTypeConverter.wrap($convertervariation);
|
||||
static TypeConverter<Language, String> $converterlanguage =
|
||||
const LanguageConverter();
|
||||
static TypeConverter<Language, String> $converterlanguage = const LanguageConverter();
|
||||
static TypeConverter<Language?, String?> $converterlanguagen =
|
||||
NullAwareTypeConverter.wrap($converterlanguage);
|
||||
static TypeConverter<Equipment, String> $converterequipment =
|
||||
const EquipmentConverter();
|
||||
static TypeConverter<Equipment, String> $converterequipment = const EquipmentConverter();
|
||||
static TypeConverter<Equipment?, String?> $converterequipmentn =
|
||||
NullAwareTypeConverter.wrap($converterequipment);
|
||||
}
|
||||
@@ -224,31 +192,18 @@ class ExerciseTable extends DataClass implements Insertable<ExerciseTable> {
|
||||
ExerciseTableItemsCompanion toCompanion(bool nullToAbsent) {
|
||||
return ExerciseTableItemsCompanion(
|
||||
id: Value(id),
|
||||
exercisebase: exercisebase == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(exercisebase),
|
||||
muscle:
|
||||
muscle == null && nullToAbsent ? const Value.absent() : Value(muscle),
|
||||
category: category == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(category),
|
||||
variation: variation == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(variation),
|
||||
language: language == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(language),
|
||||
equipment: equipment == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(equipment),
|
||||
expiresIn: expiresIn == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(expiresIn),
|
||||
exercisebase:
|
||||
exercisebase == null && nullToAbsent ? const Value.absent() : Value(exercisebase),
|
||||
muscle: muscle == null && nullToAbsent ? const Value.absent() : Value(muscle),
|
||||
category: category == null && nullToAbsent ? const Value.absent() : Value(category),
|
||||
variation: variation == null && nullToAbsent ? const Value.absent() : Value(variation),
|
||||
language: language == null && nullToAbsent ? const Value.absent() : Value(language),
|
||||
equipment: equipment == null && nullToAbsent ? const Value.absent() : Value(equipment),
|
||||
expiresIn: expiresIn == null && nullToAbsent ? const Value.absent() : Value(expiresIn),
|
||||
);
|
||||
}
|
||||
|
||||
factory ExerciseTable.fromJson(Map<String, dynamic> json,
|
||||
{ValueSerializer? serializer}) {
|
||||
factory ExerciseTable.fromJson(Map<String, dynamic> json, {ValueSerializer? serializer}) {
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return ExerciseTable(
|
||||
id: serializer.fromJson<int>(json['id']),
|
||||
@@ -287,8 +242,7 @@ class ExerciseTable extends DataClass implements Insertable<ExerciseTable> {
|
||||
Value<DateTime?> expiresIn = const Value.absent()}) =>
|
||||
ExerciseTable(
|
||||
id: id ?? this.id,
|
||||
exercisebase:
|
||||
exercisebase.present ? exercisebase.value : this.exercisebase,
|
||||
exercisebase: exercisebase.present ? exercisebase.value : this.exercisebase,
|
||||
muscle: muscle.present ? muscle.value : this.muscle,
|
||||
category: category.present ? category.value : this.category,
|
||||
variation: variation.present ? variation.value : this.variation,
|
||||
@@ -312,8 +266,8 @@ class ExerciseTable extends DataClass implements Insertable<ExerciseTable> {
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(id, exercisebase, muscle, category, variation,
|
||||
language, equipment, expiresIn);
|
||||
int get hashCode =>
|
||||
Object.hash(id, exercisebase, muscle, category, variation, language, equipment, expiresIn);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
@@ -409,8 +363,7 @@ class ExerciseTableItemsCompanion extends UpdateCompanion<ExerciseTable> {
|
||||
if (exercisebase.present) {
|
||||
final converter = $ExerciseTableItemsTable.$converterexercisebasen;
|
||||
|
||||
map['exercisebase'] =
|
||||
Variable<String>(converter.toSql(exercisebase.value));
|
||||
map['exercisebase'] = Variable<String>(converter.toSql(exercisebase.value));
|
||||
}
|
||||
if (muscle.present) {
|
||||
final converter = $ExerciseTableItemsTable.$convertermusclen;
|
||||
@@ -461,8 +414,7 @@ class ExerciseTableItemsCompanion extends UpdateCompanion<ExerciseTable> {
|
||||
|
||||
abstract class _$ExerciseDatabase extends GeneratedDatabase {
|
||||
_$ExerciseDatabase(QueryExecutor e) : super(e);
|
||||
late final $ExerciseTableItemsTable exerciseTableItems =
|
||||
$ExerciseTableItemsTable(this);
|
||||
late final $ExerciseTableItemsTable exerciseTableItems = $ExerciseTableItemsTable(this);
|
||||
@override
|
||||
Iterable<TableInfo<Table, Object?>> get allTables =>
|
||||
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
|
||||
|
||||
@@ -44,14 +44,10 @@ class ExerciseBaseConverter extends TypeConverter<ExerciseBase, String> {
|
||||
final Map<String, dynamic> baseData = json.decode(fromDb);
|
||||
|
||||
final category = ExerciseCategory.fromJson(baseData['categories']);
|
||||
final musclesPrimary =
|
||||
baseData['muscless'].map((e) => Muscle.fromJson(e)).toList();
|
||||
final musclesSecondary =
|
||||
baseData['musclesSecondary'].map((e) => Muscle.fromJson(e)).toList();
|
||||
final equipment =
|
||||
baseData['equipments'].map((e) => Equipment.fromJson(e)).toList();
|
||||
final images =
|
||||
baseData['images'].map((e) => ExerciseImage.fromJson(e)).toList();
|
||||
final musclesPrimary = baseData['muscless'].map((e) => Muscle.fromJson(e)).toList();
|
||||
final musclesSecondary = baseData['musclesSecondary'].map((e) => Muscle.fromJson(e)).toList();
|
||||
final equipment = baseData['equipments'].map((e) => Equipment.fromJson(e)).toList();
|
||||
final images = baseData['images'].map((e) => ExerciseImage.fromJson(e)).toList();
|
||||
final videos = baseData['videos'].map((e) => Video.fromJson(e)).toList();
|
||||
|
||||
final List<Translation> exercises = [];
|
||||
@@ -62,14 +58,10 @@ class ExerciseBaseConverter extends TypeConverter<ExerciseBase, String> {
|
||||
description: exerciseData['description'],
|
||||
baseId: baseData['id'],
|
||||
);
|
||||
exercise.aliases = exerciseData['aliases']
|
||||
.map((e) => Alias.fromJson(e))
|
||||
.toList()
|
||||
.cast<Alias>();
|
||||
exercise.notes = exerciseData['notes']
|
||||
.map((e) => Comment.fromJson(e))
|
||||
.toList()
|
||||
.cast<Comment>();
|
||||
exercise.aliases =
|
||||
exerciseData['aliases'].map((e) => Alias.fromJson(e)).toList().cast<Alias>();
|
||||
exercise.notes =
|
||||
exerciseData['notes'].map((e) => Comment.fromJson(e)).toList().cast<Comment>();
|
||||
exercise.language = Language.fromJson(exerciseData['languageObj']);
|
||||
exercises.add(exercise);
|
||||
}
|
||||
@@ -124,14 +116,12 @@ class EquipmentConverter extends TypeConverter<Equipment, String> {
|
||||
}
|
||||
}
|
||||
|
||||
class ExerciseCategoryConverter
|
||||
extends TypeConverter<ExerciseCategory, String> {
|
||||
class ExerciseCategoryConverter extends TypeConverter<ExerciseCategory, String> {
|
||||
const ExerciseCategoryConverter();
|
||||
|
||||
@override
|
||||
ExerciseCategory fromSql(String fromDb) {
|
||||
return ExerciseCategory.fromJson(
|
||||
json.decode(fromDb) as Map<String, dynamic>);
|
||||
return ExerciseCategory.fromJson(json.decode(fromDb) as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -26,10 +26,7 @@ class WgerHttpException implements Exception {
|
||||
/// JSON. Will use the response as-is if it fails.
|
||||
WgerHttpException(dynamic responseBody) {
|
||||
if (responseBody == null) {
|
||||
errors = {
|
||||
'unknown_error':
|
||||
'An unknown error occurred, no further information available'
|
||||
};
|
||||
errors = {'unknown_error': 'An unknown error occurred, no further information available'};
|
||||
} else {
|
||||
try {
|
||||
errors = {'unknown_error': json.decode(responseBody)};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
double chartGetInterval(DateTime first, DateTime last, {divider = 3}) {
|
||||
final dayDiff = last.difference(first);
|
||||
|
||||
return dayDiff.inMilliseconds == 0
|
||||
? 1000
|
||||
: dayDiff.inMilliseconds.abs() / divider;
|
||||
return dayDiff.inMilliseconds == 0 ? 1000 : dayDiff.inMilliseconds.abs() / divider;
|
||||
}
|
||||
|
||||
@@ -14,8 +14,7 @@ String? validateName(String? name, BuildContext context) {
|
||||
}
|
||||
|
||||
if (name.length < MIN_CHARS_NAME || name.length > MAX_CHARS_NAME) {
|
||||
return AppLocalizations.of(context)
|
||||
.enterCharacters(MIN_CHARS_NAME, MAX_CHARS_NAME);
|
||||
return AppLocalizations.of(context).enterCharacters(MIN_CHARS_NAME, MAX_CHARS_NAME);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -27,8 +26,7 @@ String? validateDescription(String? name, BuildContext context) {
|
||||
}
|
||||
|
||||
if (name.length < MIN_CHARS_DESCRIPTION) {
|
||||
return AppLocalizations.of(context)
|
||||
.enterMinCharacters(MIN_CHARS_DESCRIPTION);
|
||||
return AppLocalizations.of(context).enterMinCharacters(MIN_CHARS_DESCRIPTION);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -60,6 +60,5 @@ String? timeToString(TimeOfDay? time) {
|
||||
if (time == null) {
|
||||
return null;
|
||||
}
|
||||
return const DefaultMaterialLocalizations()
|
||||
.formatTimeOfDay(time, alwaysUse24HourFormat: true);
|
||||
return const DefaultMaterialLocalizations().formatTimeOfDay(time, alwaysUse24HourFormat: true);
|
||||
}
|
||||
|
||||
@@ -42,9 +42,7 @@ String repText(
|
||||
// rather "8 repetitions". If there is weight we want to output "8 x 50kg",
|
||||
// since the repetitions are implied. If other units are used, we always
|
||||
// print them
|
||||
if (repetitionUnitObj.id != REP_UNIT_REPETITIONS ||
|
||||
weight == 0 ||
|
||||
weight == null) {
|
||||
if (repetitionUnitObj.id != REP_UNIT_REPETITIONS || weight == 0 || weight == null) {
|
||||
out.add(repetitionUnitObj.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,4 @@ import 'package:flutter/foundation.dart';
|
||||
// Note: we're not using Platform.isAndroid etc because during tests these would+
|
||||
// always take the value of the current platform. TargetPlatform is always Android
|
||||
// during tests, but can be changed to check for correct UI switches, etc.
|
||||
final isDesktop = [TargetPlatform.linux, TargetPlatform.macOS]
|
||||
.contains(defaultTargetPlatform);
|
||||
final isDesktop = [TargetPlatform.linux, TargetPlatform.macOS].contains(defaultTargetPlatform);
|
||||
|
||||
@@ -49,8 +49,7 @@ void showErrorDialog(dynamic exception, BuildContext context) {
|
||||
);
|
||||
}
|
||||
|
||||
void showHttpExceptionErrorDialog(
|
||||
WgerHttpException exception, BuildContext context) async {
|
||||
void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext context) async {
|
||||
log('showHttpExceptionErrorDialog: ');
|
||||
log(exception.toString());
|
||||
log('-------------------');
|
||||
@@ -59,8 +58,7 @@ void showHttpExceptionErrorDialog(
|
||||
for (final key in exception.errors!.keys) {
|
||||
// Error headers
|
||||
// Ensure that the error heading first letter is capitalized.
|
||||
final String errorHeaderMsg =
|
||||
key[0].toUpperCase() + key.substring(1, key.length);
|
||||
final String errorHeaderMsg = key[0].toUpperCase() + key.substring(1, key.length);
|
||||
|
||||
errorList.add(
|
||||
Text(
|
||||
@@ -131,8 +129,7 @@ dynamic showDeleteDialog(
|
||||
),
|
||||
onPressed: () {
|
||||
exerciseData[exercise]!.removeWhere((el) => el.id == log.id);
|
||||
Provider.of<WorkoutPlansProvider>(context, listen: false)
|
||||
.deleteLog(
|
||||
Provider.of<WorkoutPlansProvider>(context, listen: false).deleteLog(
|
||||
log,
|
||||
);
|
||||
|
||||
|
||||
@@ -81,21 +81,19 @@ class MyApp extends StatelessWidget {
|
||||
create: (ctx) => AuthProvider(),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, ExercisesProvider>(
|
||||
create: (context) => ExercisesProvider(WgerBaseProvider(
|
||||
Provider.of<AuthProvider>(context, listen: false))),
|
||||
create: (context) => ExercisesProvider(
|
||||
WgerBaseProvider(Provider.of<AuthProvider>(context, listen: false))),
|
||||
update: (context, base, previous) =>
|
||||
previous ?? ExercisesProvider(WgerBaseProvider(base)),
|
||||
),
|
||||
ChangeNotifierProxyProvider2<AuthProvider, ExercisesProvider,
|
||||
WorkoutPlansProvider>(
|
||||
ChangeNotifierProxyProvider2<AuthProvider, ExercisesProvider, WorkoutPlansProvider>(
|
||||
create: (context) => WorkoutPlansProvider(
|
||||
WgerBaseProvider(Provider.of<AuthProvider>(context, listen: false)),
|
||||
Provider.of<ExercisesProvider>(context, listen: false),
|
||||
[],
|
||||
),
|
||||
update: (context, auth, exercises, previous) =>
|
||||
previous ??
|
||||
WorkoutPlansProvider(WgerBaseProvider(auth), exercises, []),
|
||||
previous ?? WorkoutPlansProvider(WgerBaseProvider(auth), exercises, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, NutritionPlansProvider>(
|
||||
create: (context) => NutritionPlansProvider(
|
||||
@@ -116,8 +114,7 @@ class MyApp extends StatelessWidget {
|
||||
create: (context) => UserProvider(
|
||||
WgerBaseProvider(Provider.of<AuthProvider>(context, listen: false)),
|
||||
),
|
||||
update: (context, base, previous) =>
|
||||
previous ?? UserProvider(WgerBaseProvider(base)),
|
||||
update: (context, base, previous) => previous ?? UserProvider(WgerBaseProvider(base)),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, BodyWeightProvider>(
|
||||
create: (context) => BodyWeightProvider(
|
||||
@@ -127,10 +124,9 @@ class MyApp extends StatelessWidget {
|
||||
previous ?? BodyWeightProvider(WgerBaseProvider(base)),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, GalleryProvider>(
|
||||
create: (context) => GalleryProvider(
|
||||
Provider.of<AuthProvider>(context, listen: false), []),
|
||||
update: (context, auth, previous) =>
|
||||
previous ?? GalleryProvider(auth, []),
|
||||
create: (context) =>
|
||||
GalleryProvider(Provider.of<AuthProvider>(context, listen: false), []),
|
||||
update: (context, auth, previous) => previous ?? GalleryProvider(auth, []),
|
||||
),
|
||||
ChangeNotifierProxyProvider<AuthProvider, AddExerciseProvider>(
|
||||
create: (context) => AddExerciseProvider(
|
||||
@@ -153,8 +149,7 @@ class MyApp extends StatelessWidget {
|
||||
: FutureBuilder(
|
||||
future: auth.tryAutoLogin(),
|
||||
builder: (ctx, authResultSnapshot) =>
|
||||
authResultSnapshot.connectionState ==
|
||||
ConnectionState.waiting
|
||||
authResultSnapshot.connectionState == ConnectionState.waiting
|
||||
? SplashScreen()
|
||||
: AuthScreen(),
|
||||
),
|
||||
@@ -164,10 +159,8 @@ class MyApp extends StatelessWidget {
|
||||
GalleryScreen.routeName: (ctx) => const GalleryScreen(),
|
||||
GymModeScreen.routeName: (ctx) => GymModeScreen(),
|
||||
HomeTabsScreen.routeName: (ctx) => HomeTabsScreen(),
|
||||
MeasurementCategoriesScreen.routeName: (ctx) =>
|
||||
MeasurementCategoriesScreen(),
|
||||
MeasurementEntriesScreen.routeName: (ctx) =>
|
||||
MeasurementEntriesScreen(),
|
||||
MeasurementCategoriesScreen.routeName: (ctx) => MeasurementCategoriesScreen(),
|
||||
MeasurementEntriesScreen.routeName: (ctx) => MeasurementEntriesScreen(),
|
||||
NutritionScreen.routeName: (ctx) => NutritionScreen(),
|
||||
NutritionalDiaryScreen.routeName: (ctx) => NutritionalDiaryScreen(),
|
||||
NutritionalPlanScreen.routeName: (ctx) => NutritionalPlanScreen(),
|
||||
@@ -175,8 +168,7 @@ class MyApp extends StatelessWidget {
|
||||
WorkoutPlanScreen.routeName: (ctx) => WorkoutPlanScreen(),
|
||||
WorkoutPlansScreen.routeName: (ctx) => WorkoutPlansScreen(),
|
||||
ExercisesScreen.routeName: (ctx) => const ExercisesScreen(),
|
||||
ExerciseDetailScreen.routeName: (ctx) =>
|
||||
const ExerciseDetailScreen(),
|
||||
ExerciseDetailScreen.routeName: (ctx) => const ExerciseDetailScreen(),
|
||||
AddExerciseScreen.routeName: (ctx) => const AddExerciseScreen(),
|
||||
AboutPage.routeName: (ctx) => const AboutPage(),
|
||||
},
|
||||
|
||||
@@ -45,7 +45,6 @@ class WeightEntry {
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory WeightEntry.fromJson(Map<String, dynamic> json) =>
|
||||
_$WeightEntryFromJson(json);
|
||||
factory WeightEntry.fromJson(Map<String, dynamic> json) => _$WeightEntryFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$WeightEntryToJson(this);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ WeightEntry _$WeightEntryFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WeightEntryToJson(WeightEntry instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$WeightEntryToJson(WeightEntry instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'weight': numToString(instance.weight),
|
||||
'date': toDate(instance.date),
|
||||
|
||||
@@ -162,8 +162,7 @@ class ExerciseBase extends Equatable {
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory ExerciseBase.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExerciseBaseFromJson(json);
|
||||
factory ExerciseBase.fromJson(Map<String, dynamic> json) => _$ExerciseBaseFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ExerciseBaseToJson(this);
|
||||
|
||||
|
||||
@@ -24,32 +24,24 @@ ExerciseBase _$ExerciseBaseFromJson(Map<String, dynamic> json) {
|
||||
return ExerciseBase(
|
||||
id: json['id'] as int?,
|
||||
uuid: json['uuid'] as String?,
|
||||
created: json['created'] == null
|
||||
? null
|
||||
: DateTime.parse(json['created'] as String),
|
||||
lastUpdate: json['last_update'] == null
|
||||
? null
|
||||
: DateTime.parse(json['last_update'] as String),
|
||||
created: json['created'] == null ? null : DateTime.parse(json['created'] as String),
|
||||
lastUpdate: json['last_update'] == null ? null : DateTime.parse(json['last_update'] as String),
|
||||
variationId: json['variations'] as int?,
|
||||
category: json['categories'] == null
|
||||
? null
|
||||
: ExerciseCategory.fromJson(json['categories'] as Map<String, dynamic>),
|
||||
)
|
||||
..categoryId = json['category'] as int
|
||||
..musclesIds =
|
||||
(json['muscles'] as List<dynamic>).map((e) => e as int).toList()
|
||||
..musclesSecondaryIds = (json['muscles_secondary'] as List<dynamic>)
|
||||
.map((e) => e as int)
|
||||
.toList()
|
||||
..equipmentIds =
|
||||
(json['equipment'] as List<dynamic>).map((e) => e as int).toList()
|
||||
..musclesIds = (json['muscles'] as List<dynamic>).map((e) => e as int).toList()
|
||||
..musclesSecondaryIds =
|
||||
(json['muscles_secondary'] as List<dynamic>).map((e) => e as int).toList()
|
||||
..equipmentIds = (json['equipment'] as List<dynamic>).map((e) => e as int).toList()
|
||||
..translations = (json['translations'] as List<dynamic>)
|
||||
.map((e) => Translation.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$ExerciseBaseToJson(ExerciseBase instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$ExerciseBaseToJson(ExerciseBase instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uuid': instance.uuid,
|
||||
'variations': instance.variationId,
|
||||
@@ -60,8 +52,7 @@ Map<String, dynamic> _$ExerciseBaseToJson(ExerciseBase instance) =>
|
||||
'muscles': instance.musclesIds,
|
||||
'muscless': instance.muscles.map((e) => e.toJson()).toList(),
|
||||
'muscles_secondary': instance.musclesSecondaryIds,
|
||||
'musclesSecondary':
|
||||
instance.musclesSecondary.map((e) => e.toJson()).toList(),
|
||||
'musclesSecondary': instance.musclesSecondary.map((e) => e.toJson()).toList(),
|
||||
'equipment': instance.equipmentIds,
|
||||
'equipments': instance.equipment.map((e) => e.toJson()).toList(),
|
||||
'images': instance.images.map((e) => e.toJson()).toList(),
|
||||
|
||||
@@ -40,8 +40,7 @@ class ExerciseCategory extends Equatable {
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory ExerciseCategory.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExerciseCategoryFromJson(json);
|
||||
factory ExerciseCategory.fromJson(Map<String, dynamic> json) => _$ExerciseCategoryFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ExerciseCategoryToJson(this);
|
||||
|
||||
@override
|
||||
|
||||
@@ -17,8 +17,7 @@ ExerciseCategory _$ExerciseCategoryFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$ExerciseCategoryToJson(ExerciseCategory instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$ExerciseCategoryToJson(ExerciseCategory instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
|
||||
@@ -38,7 +38,6 @@ class Comment {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory Comment.fromJson(Map<String, dynamic> json) =>
|
||||
_$CommentFromJson(json);
|
||||
factory Comment.fromJson(Map<String, dynamic> json) => _$CommentFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$CommentToJson(this);
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ class Equipment extends Equatable {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory Equipment.fromJson(Map<String, dynamic> json) =>
|
||||
_$EquipmentFromJson(json);
|
||||
factory Equipment.fromJson(Map<String, dynamic> json) => _$EquipmentFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$EquipmentToJson(this);
|
||||
|
||||
@override
|
||||
|
||||
@@ -25,6 +25,5 @@ class ExerciseBaseData with _$ExerciseBaseData {
|
||||
required List<Video> videos,
|
||||
}) = _ExerciseBaseData;
|
||||
|
||||
factory ExerciseBaseData.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExerciseBaseDataFromJson(json);
|
||||
factory ExerciseBaseData.fromJson(Map<String, dynamic> json) => _$ExerciseBaseDataFromJson(json);
|
||||
}
|
||||
|
||||
@@ -34,14 +34,12 @@ mixin _$ExerciseBaseData {
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
$ExerciseBaseDataCopyWith<ExerciseBaseData> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
$ExerciseBaseDataCopyWith<ExerciseBaseData> get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ExerciseBaseDataCopyWith<$Res> {
|
||||
factory $ExerciseBaseDataCopyWith(
|
||||
ExerciseBaseData value, $Res Function(ExerciseBaseData) then) =
|
||||
factory $ExerciseBaseDataCopyWith(ExerciseBaseData value, $Res Function(ExerciseBaseData) then) =
|
||||
_$ExerciseBaseDataCopyWithImpl<$Res, ExerciseBaseData>;
|
||||
@useResult
|
||||
$Res call(
|
||||
@@ -121,10 +119,9 @@ class _$ExerciseBaseDataCopyWithImpl<$Res, $Val extends ExerciseBaseData>
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ExerciseBaseDataImplCopyWith<$Res>
|
||||
implements $ExerciseBaseDataCopyWith<$Res> {
|
||||
factory _$$ExerciseBaseDataImplCopyWith(_$ExerciseBaseDataImpl value,
|
||||
$Res Function(_$ExerciseBaseDataImpl) then) =
|
||||
abstract class _$$ExerciseBaseDataImplCopyWith<$Res> implements $ExerciseBaseDataCopyWith<$Res> {
|
||||
factory _$$ExerciseBaseDataImplCopyWith(
|
||||
_$ExerciseBaseDataImpl value, $Res Function(_$ExerciseBaseDataImpl) then) =
|
||||
__$$ExerciseBaseDataImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
@@ -144,8 +141,8 @@ abstract class _$$ExerciseBaseDataImplCopyWith<$Res>
|
||||
class __$$ExerciseBaseDataImplCopyWithImpl<$Res>
|
||||
extends _$ExerciseBaseDataCopyWithImpl<$Res, _$ExerciseBaseDataImpl>
|
||||
implements _$$ExerciseBaseDataImplCopyWith<$Res> {
|
||||
__$$ExerciseBaseDataImplCopyWithImpl(_$ExerciseBaseDataImpl _value,
|
||||
$Res Function(_$ExerciseBaseDataImpl) _then)
|
||||
__$$ExerciseBaseDataImplCopyWithImpl(
|
||||
_$ExerciseBaseDataImpl _value, $Res Function(_$ExerciseBaseDataImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@@ -210,8 +207,7 @@ class _$ExerciseBaseDataImpl implements _ExerciseBaseData {
|
||||
required this.uuid,
|
||||
required this.category,
|
||||
required final List<Muscle> muscles,
|
||||
@JsonKey(name: 'muscles_secondary')
|
||||
required final List<Muscle> musclesSecondary,
|
||||
@JsonKey(name: 'muscles_secondary') required final List<Muscle> musclesSecondary,
|
||||
required final List<Equipment> equipment,
|
||||
required final List<ExerciseData> exercises,
|
||||
required final List<ExerciseImage> images,
|
||||
@@ -246,8 +242,7 @@ class _$ExerciseBaseDataImpl implements _ExerciseBaseData {
|
||||
@override
|
||||
@JsonKey(name: 'muscles_secondary')
|
||||
List<Muscle> get musclesSecondary {
|
||||
if (_musclesSecondary is EqualUnmodifiableListView)
|
||||
return _musclesSecondary;
|
||||
if (_musclesSecondary is EqualUnmodifiableListView) return _musclesSecondary;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_musclesSecondary);
|
||||
}
|
||||
@@ -296,15 +291,11 @@ class _$ExerciseBaseDataImpl implements _ExerciseBaseData {
|
||||
other is _$ExerciseBaseDataImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.uuid, uuid) || other.uuid == uuid) &&
|
||||
(identical(other.category, category) ||
|
||||
other.category == category) &&
|
||||
(identical(other.category, category) || other.category == category) &&
|
||||
const DeepCollectionEquality().equals(other._muscles, _muscles) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._musclesSecondary, _musclesSecondary) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._equipment, _equipment) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._exercises, _exercises) &&
|
||||
const DeepCollectionEquality().equals(other._musclesSecondary, _musclesSecondary) &&
|
||||
const DeepCollectionEquality().equals(other._equipment, _equipment) &&
|
||||
const DeepCollectionEquality().equals(other._exercises, _exercises) &&
|
||||
const DeepCollectionEquality().equals(other._images, _images) &&
|
||||
const DeepCollectionEquality().equals(other._videos, _videos));
|
||||
}
|
||||
@@ -327,8 +318,7 @@ class _$ExerciseBaseDataImpl implements _ExerciseBaseData {
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ExerciseBaseDataImplCopyWith<_$ExerciseBaseDataImpl> get copyWith =>
|
||||
__$$ExerciseBaseDataImplCopyWithImpl<_$ExerciseBaseDataImpl>(
|
||||
this, _$identity);
|
||||
__$$ExerciseBaseDataImplCopyWithImpl<_$ExerciseBaseDataImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -344,15 +334,13 @@ abstract class _ExerciseBaseData implements ExerciseBaseData {
|
||||
required final String uuid,
|
||||
required final ExerciseCategory category,
|
||||
required final List<Muscle> muscles,
|
||||
@JsonKey(name: 'muscles_secondary')
|
||||
required final List<Muscle> musclesSecondary,
|
||||
@JsonKey(name: 'muscles_secondary') required final List<Muscle> musclesSecondary,
|
||||
required final List<Equipment> equipment,
|
||||
required final List<ExerciseData> exercises,
|
||||
required final List<ExerciseImage> images,
|
||||
required final List<Video> videos}) = _$ExerciseBaseDataImpl;
|
||||
|
||||
factory _ExerciseBaseData.fromJson(Map<String, dynamic> json) =
|
||||
_$ExerciseBaseDataImpl.fromJson;
|
||||
factory _ExerciseBaseData.fromJson(Map<String, dynamic> json) = _$ExerciseBaseDataImpl.fromJson;
|
||||
|
||||
@override
|
||||
int get id;
|
||||
|
||||
@@ -6,13 +6,11 @@ part of 'exercise_base_data.dart';
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$ExerciseBaseDataImpl _$$ExerciseBaseDataImplFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$ExerciseBaseDataImpl _$$ExerciseBaseDataImplFromJson(Map<String, dynamic> json) =>
|
||||
_$ExerciseBaseDataImpl(
|
||||
id: json['id'] as int,
|
||||
uuid: json['uuid'] as String,
|
||||
category:
|
||||
ExerciseCategory.fromJson(json['category'] as Map<String, dynamic>),
|
||||
category: ExerciseCategory.fromJson(json['category'] as Map<String, dynamic>),
|
||||
muscles: (json['muscles'] as List<dynamic>)
|
||||
.map((e) => Muscle.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
@@ -33,8 +31,7 @@ _$ExerciseBaseDataImpl _$$ExerciseBaseDataImplFromJson(
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ExerciseBaseDataImplToJson(
|
||||
_$ExerciseBaseDataImpl instance) =>
|
||||
Map<String, dynamic> _$$ExerciseBaseDataImplToJson(_$ExerciseBaseDataImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uuid': instance.uuid,
|
||||
|
||||
@@ -18,6 +18,5 @@ class ExerciseData with _$ExerciseData {
|
||||
required List<Comment> notes,
|
||||
}) = _ExerciseData;
|
||||
|
||||
factory ExerciseData.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExerciseDataFromJson(json);
|
||||
factory ExerciseData.fromJson(Map<String, dynamic> json) => _$ExerciseDataFromJson(json);
|
||||
}
|
||||
|
||||
@@ -33,14 +33,12 @@ mixin _$ExerciseData {
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
$ExerciseDataCopyWith<ExerciseData> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
$ExerciseDataCopyWith<ExerciseData> get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ExerciseDataCopyWith<$Res> {
|
||||
factory $ExerciseDataCopyWith(
|
||||
ExerciseData value, $Res Function(ExerciseData) then) =
|
||||
factory $ExerciseDataCopyWith(ExerciseData value, $Res Function(ExerciseData) then) =
|
||||
_$ExerciseDataCopyWithImpl<$Res, ExerciseData>;
|
||||
@useResult
|
||||
$Res call(
|
||||
@@ -114,8 +112,7 @@ class _$ExerciseDataCopyWithImpl<$Res, $Val extends ExerciseData>
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ExerciseDataImplCopyWith<$Res>
|
||||
implements $ExerciseDataCopyWith<$Res> {
|
||||
abstract class _$$ExerciseDataImplCopyWith<$Res> implements $ExerciseDataCopyWith<$Res> {
|
||||
factory _$$ExerciseDataImplCopyWith(
|
||||
_$ExerciseDataImpl value, $Res Function(_$ExerciseDataImpl) then) =
|
||||
__$$ExerciseDataImplCopyWithImpl<$Res>;
|
||||
@@ -249,11 +246,9 @@ class _$ExerciseDataImpl implements _ExerciseData {
|
||||
other is _$ExerciseDataImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.uuid, uuid) || other.uuid == uuid) &&
|
||||
(identical(other.languageId, languageId) ||
|
||||
other.languageId == languageId) &&
|
||||
(identical(other.languageId, languageId) || other.languageId == languageId) &&
|
||||
(identical(other.baseId, baseId) || other.baseId == baseId) &&
|
||||
(identical(other.description, description) ||
|
||||
other.description == description) &&
|
||||
(identical(other.description, description) || other.description == description) &&
|
||||
(identical(other.name, name) || other.name == name) &&
|
||||
const DeepCollectionEquality().equals(other._aliases, _aliases) &&
|
||||
const DeepCollectionEquality().equals(other._notes, _notes));
|
||||
@@ -261,16 +256,8 @@ class _$ExerciseDataImpl implements _ExerciseData {
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
id,
|
||||
uuid,
|
||||
languageId,
|
||||
baseId,
|
||||
description,
|
||||
name,
|
||||
const DeepCollectionEquality().hash(_aliases),
|
||||
const DeepCollectionEquality().hash(_notes));
|
||||
int get hashCode => Object.hash(runtimeType, id, uuid, languageId, baseId, description, name,
|
||||
const DeepCollectionEquality().hash(_aliases), const DeepCollectionEquality().hash(_notes));
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@@ -297,8 +284,7 @@ abstract class _ExerciseData implements ExerciseData {
|
||||
required final List<Alias> aliases,
|
||||
required final List<Comment> notes}) = _$ExerciseDataImpl;
|
||||
|
||||
factory _ExerciseData.fromJson(Map<String, dynamic> json) =
|
||||
_$ExerciseDataImpl.fromJson;
|
||||
factory _ExerciseData.fromJson(Map<String, dynamic> json) = _$ExerciseDataImpl.fromJson;
|
||||
|
||||
@override
|
||||
int get id;
|
||||
|
||||
@@ -27,8 +27,7 @@ _$ExerciseDataImpl _$$ExerciseDataImplFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$$ExerciseDataImplToJson(_$ExerciseDataImpl instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$$ExerciseDataImplToJson(_$ExerciseDataImpl instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uuid': instance.uuid,
|
||||
'language': instance.languageId,
|
||||
|
||||
@@ -46,8 +46,7 @@ class ExerciseImage {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory ExerciseImage.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExerciseImageFromJson(json);
|
||||
factory ExerciseImage.fromJson(Map<String, dynamic> json) => _$ExerciseImageFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ExerciseImageToJson(this);
|
||||
|
||||
@override
|
||||
|
||||
@@ -20,8 +20,7 @@ ExerciseImage _$ExerciseImageFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$ExerciseImageToJson(ExerciseImage instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$ExerciseImageToJson(ExerciseImage instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uuid': instance.uuid,
|
||||
'exercise_base': instance.exerciseBaseId,
|
||||
|
||||
@@ -39,8 +39,7 @@ class Language extends Equatable {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory Language.fromJson(Map<String, dynamic> json) =>
|
||||
_$LanguageFromJson(json);
|
||||
factory Language.fromJson(Map<String, dynamic> json) => _$LanguageFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$LanguageToJson(this);
|
||||
|
||||
@override
|
||||
|
||||
@@ -52,8 +52,7 @@ class Muscle extends Equatable {
|
||||
List<Object?> get props => [id, name, isFront];
|
||||
|
||||
String nameTranslated(BuildContext context) {
|
||||
return name +
|
||||
(nameEn.isNotEmpty ? ' (${getTranslation(nameEn, context)})' : '');
|
||||
return name + (nameEn.isNotEmpty ? ' (${getTranslation(nameEn, context)})' : '');
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -86,8 +86,7 @@ class Translation extends Equatable {
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory Translation.fromJson(Map<String, dynamic> json) =>
|
||||
_$TranslationFromJson(json);
|
||||
factory Translation.fromJson(Map<String, dynamic> json) => _$TranslationFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$TranslationToJson(this);
|
||||
|
||||
|
||||
@@ -22,16 +22,13 @@ Translation _$TranslationFromJson(Map<String, dynamic> json) {
|
||||
return Translation(
|
||||
id: json['id'] as int?,
|
||||
uuid: json['uuid'] as String?,
|
||||
created: json['created'] == null
|
||||
? null
|
||||
: DateTime.parse(json['created'] as String),
|
||||
created: json['created'] == null ? null : DateTime.parse(json['created'] as String),
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
baseId: json['exercise_base'] as int?,
|
||||
)
|
||||
..languageId = json['language'] as int
|
||||
..languageObj =
|
||||
Language.fromJson(json['languageObj'] as Map<String, dynamic>)
|
||||
..languageObj = Language.fromJson(json['languageObj'] as Map<String, dynamic>)
|
||||
..notes = (json['notes'] as List<dynamic>)
|
||||
.map((e) => Comment.fromJson(e as Map<String, dynamic>))
|
||||
.toList()
|
||||
@@ -40,8 +37,7 @@ Translation _$TranslationFromJson(Map<String, dynamic> json) {
|
||||
.toList();
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$TranslationToJson(Translation instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$TranslationToJson(Translation instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uuid': instance.uuid,
|
||||
'language': instance.languageId,
|
||||
|
||||
@@ -30,7 +30,6 @@ class Variation {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory Variation.fromJson(Map<String, dynamic> json) =>
|
||||
_$VariationFromJson(json);
|
||||
factory Variation.fromJson(Map<String, dynamic> json) => _$VariationFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$VariationToJson(this);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ MeasurementCategory _$MeasurementCategoryFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$MeasurementCategoryToJson(
|
||||
MeasurementCategory instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$MeasurementCategoryToJson(MeasurementCategory instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'unit': instance.unit,
|
||||
|
||||
@@ -29,12 +29,7 @@ class MeasurementEntry extends Equatable {
|
||||
required this.notes,
|
||||
});
|
||||
|
||||
MeasurementEntry copyWith(
|
||||
{int? id,
|
||||
int? category,
|
||||
DateTime? date,
|
||||
num? value,
|
||||
String? notes}) =>
|
||||
MeasurementEntry copyWith({int? id, int? category, DateTime? date, num? value, String? notes}) =>
|
||||
MeasurementEntry(
|
||||
id: id ?? this.id,
|
||||
category: category ?? this.category,
|
||||
@@ -44,8 +39,7 @@ class MeasurementEntry extends Equatable {
|
||||
);
|
||||
|
||||
// Boilerplate
|
||||
factory MeasurementEntry.fromJson(Map<String, dynamic> json) =>
|
||||
_$MeasurementEntryFromJson(json);
|
||||
factory MeasurementEntry.fromJson(Map<String, dynamic> json) => _$MeasurementEntryFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MeasurementEntryToJson(this);
|
||||
|
||||
|
||||
@@ -20,8 +20,7 @@ MeasurementEntry _$MeasurementEntryFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$MeasurementEntryToJson(MeasurementEntry instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$MeasurementEntryToJson(MeasurementEntry instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'category': instance.category,
|
||||
'date': toDate(instance.date),
|
||||
|
||||
@@ -81,8 +81,7 @@ class IngredientImage {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory IngredientImage.fromJson(Map<String, dynamic> json) =>
|
||||
_$IngredientImageFromJson(json);
|
||||
factory IngredientImage.fromJson(Map<String, dynamic> json) => _$IngredientImageFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$IngredientImageToJson(this);
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ IngredientImage _$IngredientImageFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$IngredientImageToJson(IngredientImage instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$IngredientImageToJson(IngredientImage instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uuid': instance.uuid,
|
||||
'ingredient_id': instance.ingredientId,
|
||||
|
||||
@@ -46,11 +46,7 @@ class Ingredient {
|
||||
final num carbohydrates;
|
||||
|
||||
/// g per 100g of product
|
||||
@JsonKey(
|
||||
required: true,
|
||||
fromJson: stringToNum,
|
||||
toJson: numToString,
|
||||
name: 'carbohydrates_sugar')
|
||||
@JsonKey(required: true, fromJson: stringToNum, toJson: numToString, name: 'carbohydrates_sugar')
|
||||
final num carbohydratesSugar;
|
||||
|
||||
/// g per 100g of product
|
||||
@@ -62,11 +58,7 @@ class Ingredient {
|
||||
final num fat;
|
||||
|
||||
/// g per 100g of product
|
||||
@JsonKey(
|
||||
required: true,
|
||||
fromJson: stringToNum,
|
||||
toJson: numToString,
|
||||
name: 'fat_saturated')
|
||||
@JsonKey(required: true, fromJson: stringToNum, toJson: numToString, name: 'fat_saturated')
|
||||
final num fatSaturated;
|
||||
|
||||
/// g per 100g of product
|
||||
@@ -96,8 +88,7 @@ class Ingredient {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory Ingredient.fromJson(Map<String, dynamic> json) =>
|
||||
_$IngredientFromJson(json);
|
||||
factory Ingredient.fromJson(Map<String, dynamic> json) => _$IngredientFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$IngredientToJson(this);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ Ingredient _$IngredientFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$IngredientToJson(Ingredient instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$IngredientToJson(Ingredient instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'code': instance.code,
|
||||
'name': instance.name,
|
||||
|
||||
@@ -13,16 +13,14 @@ IngredientWeightUnit _$IngredientWeightUnitFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
return IngredientWeightUnit(
|
||||
id: json['id'] as int,
|
||||
weightUnit:
|
||||
WeightUnit.fromJson(json['weight_unit'] as Map<String, dynamic>),
|
||||
weightUnit: WeightUnit.fromJson(json['weight_unit'] as Map<String, dynamic>),
|
||||
ingredient: Ingredient.fromJson(json['ingredient'] as Map<String, dynamic>),
|
||||
grams: json['grams'] as int,
|
||||
amount: (json['amount'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$IngredientWeightUnitToJson(
|
||||
IngredientWeightUnit instance) =>
|
||||
Map<String, dynamic> _$IngredientWeightUnitToJson(IngredientWeightUnit instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'weight_unit': instance.weightUnit,
|
||||
|
||||
@@ -67,8 +67,7 @@ class Log {
|
||||
this.comment,
|
||||
});
|
||||
|
||||
Log.fromMealItem(MealItem mealItem, this.planId, this.mealId,
|
||||
[DateTime? dateTime]) {
|
||||
Log.fromMealItem(MealItem mealItem, this.planId, this.mealId, [DateTime? dateTime]) {
|
||||
ingredientId = mealItem.ingredientId;
|
||||
ingredientObj = mealItem.ingredientObj;
|
||||
weightUnitId = mealItem.weightUnitId;
|
||||
@@ -87,9 +86,8 @@ class Log {
|
||||
final out = NutritionalValues();
|
||||
|
||||
//final weight = amount;
|
||||
final weight = weightUnitObj == null
|
||||
? amount
|
||||
: amount * weightUnitObj!.amount * weightUnitObj!.grams;
|
||||
final weight =
|
||||
weightUnitObj == null ? amount : amount * weightUnitObj!.amount * weightUnitObj!.grams;
|
||||
|
||||
out.energy = ingredientObj.energy * weight / 100;
|
||||
out.protein = ingredientObj.protein * weight / 100;
|
||||
|
||||
@@ -9,14 +9,7 @@ part of 'log.dart';
|
||||
Log _$LogFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(
|
||||
json,
|
||||
requiredKeys: const [
|
||||
'id',
|
||||
'plan',
|
||||
'datetime',
|
||||
'ingredient',
|
||||
'weight_unit',
|
||||
'amount'
|
||||
],
|
||||
requiredKeys: const ['id', 'plan', 'datetime', 'ingredient', 'weight_unit', 'amount'],
|
||||
);
|
||||
return Log(
|
||||
id: json['id'] as int?,
|
||||
|
||||
@@ -38,11 +38,7 @@ class Meal {
|
||||
@JsonKey(name: 'name')
|
||||
late String name;
|
||||
|
||||
@JsonKey(
|
||||
includeFromJson: false,
|
||||
includeToJson: false,
|
||||
name: 'meal_items',
|
||||
defaultValue: [])
|
||||
@JsonKey(includeFromJson: false, includeToJson: false, name: 'meal_items', defaultValue: [])
|
||||
List<MealItem> mealItems = [];
|
||||
|
||||
Meal({
|
||||
|
||||
@@ -67,8 +67,7 @@ class MealItem {
|
||||
MealItem.empty();
|
||||
|
||||
// Boilerplate
|
||||
factory MealItem.fromJson(Map<String, dynamic> json) =>
|
||||
_$MealItemFromJson(json);
|
||||
factory MealItem.fromJson(Map<String, dynamic> json) => _$MealItemFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$MealItemToJson(this);
|
||||
|
||||
|
||||
@@ -62,15 +62,12 @@ class NutritionalPlan {
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory NutritionalPlan.fromJson(Map<String, dynamic> json) =>
|
||||
_$NutritionalPlanFromJson(json);
|
||||
factory NutritionalPlan.fromJson(Map<String, dynamic> json) => _$NutritionalPlanFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$NutritionalPlanToJson(this);
|
||||
|
||||
String getLabel(BuildContext context) {
|
||||
return description != ''
|
||||
? description
|
||||
: AppLocalizations.of(context).nutritionalPlan;
|
||||
return description != '' ? description : AppLocalizations.of(context).nutritionalPlan;
|
||||
}
|
||||
|
||||
/// Calculations
|
||||
@@ -89,9 +86,7 @@ class NutritionalPlan {
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
|
||||
return logEntriesValues.containsKey(today)
|
||||
? logEntriesValues[today]!
|
||||
: NutritionalValues();
|
||||
return logEntriesValues.containsKey(today) ? logEntriesValues[today]! : NutritionalValues();
|
||||
}
|
||||
|
||||
NutritionalValues get nutritionalValues7DayAvg {
|
||||
@@ -114,12 +109,9 @@ class NutritionalPlan {
|
||||
/// Calculates the percentage each macro nutrient adds to the total energy
|
||||
BaseNutritionalValues energyPercentage(NutritionalValues values) {
|
||||
return BaseNutritionalValues(
|
||||
values.protein > 0
|
||||
? ((values.protein * ENERGY_PROTEIN * 100) / values.energy)
|
||||
: 0,
|
||||
values.protein > 0 ? ((values.protein * ENERGY_PROTEIN * 100) / values.energy) : 0,
|
||||
values.carbohydrates > 0
|
||||
? ((values.carbohydrates * ENERGY_CARBOHYDRATES * 100) /
|
||||
values.energy)
|
||||
? ((values.carbohydrates * ENERGY_CARBOHYDRATES * 100) / values.energy)
|
||||
: 0,
|
||||
values.fat > 0 ? ((values.fat * ENERGY_FAT * 100) / values.energy) : 0,
|
||||
);
|
||||
@@ -139,8 +131,7 @@ class NutritionalPlan {
|
||||
Map<DateTime, NutritionalValues> get logEntriesValues {
|
||||
final out = <DateTime, NutritionalValues>{};
|
||||
for (final log in logs) {
|
||||
final date =
|
||||
DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
|
||||
final date = DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
|
||||
|
||||
if (!out.containsKey(date)) {
|
||||
out[date] = NutritionalValues();
|
||||
@@ -165,8 +156,7 @@ class NutritionalPlan {
|
||||
final List<Log> out = [];
|
||||
for (final log in logs) {
|
||||
final dateKey = DateTime(date.year, date.month, date.day);
|
||||
final logKey =
|
||||
DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
|
||||
final logKey = DateTime(log.datetime.year, log.datetime.month, log.datetime.day);
|
||||
|
||||
if (dateKey == logKey) {
|
||||
out.add(log);
|
||||
@@ -183,8 +173,7 @@ class NutritionalPlan {
|
||||
final List<MealItem> out = [];
|
||||
for (final meal in meals) {
|
||||
for (final mealItem in meal.mealItems) {
|
||||
final ingredientInList =
|
||||
out.where((e) => e.ingredientId == mealItem.ingredientId);
|
||||
final ingredientInList = out.where((e) => e.ingredientId == mealItem.ingredientId);
|
||||
|
||||
if (ingredientInList.isEmpty) {
|
||||
out.add(mealItem);
|
||||
|
||||
@@ -18,8 +18,7 @@ NutritionalPlan _$NutritionalPlanFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$NutritionalPlanToJson(NutritionalPlan instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$NutritionalPlanToJson(NutritionalPlan instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'description': instance.description,
|
||||
'creation_date': toDate(instance.creationDate),
|
||||
|
||||
@@ -89,8 +89,8 @@ class NutritionalValues {
|
||||
|
||||
@override
|
||||
//ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
int get hashCode => Object.hash(energy, protein, carbohydrates,
|
||||
carbohydratesSugar, fat, fatSaturated, fibres, sodium);
|
||||
int get hashCode => Object.hash(
|
||||
energy, protein, carbohydrates, carbohydratesSugar, fat, fatSaturated, fibres, sodium);
|
||||
}
|
||||
|
||||
class BaseNutritionalValues {
|
||||
|
||||
@@ -34,7 +34,6 @@ class WeightUnit {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory WeightUnit.fromJson(Map<String, dynamic> json) =>
|
||||
_$WeightUnitFromJson(json);
|
||||
factory WeightUnit.fromJson(Map<String, dynamic> json) => _$WeightUnitFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$WeightUnitToJson(this);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ WeightUnit _$WeightUnitFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
|
||||
@@ -42,7 +42,6 @@ class Profile {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory Profile.fromJson(Map<String, dynamic> json) =>
|
||||
_$ProfileFromJson(json);
|
||||
factory Profile.fromJson(Map<String, dynamic> json) => _$ProfileFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ProfileToJson(this);
|
||||
}
|
||||
|
||||
@@ -9,12 +9,7 @@ part of 'profile.dart';
|
||||
Profile _$ProfileFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(
|
||||
json,
|
||||
requiredKeys: const [
|
||||
'username',
|
||||
'email_verified',
|
||||
'is_trustworthy',
|
||||
'email'
|
||||
],
|
||||
requiredKeys: const ['username', 'email_verified', 'is_trustworthy', 'email'],
|
||||
);
|
||||
return Profile(
|
||||
username: json['username'] as String,
|
||||
|
||||
@@ -75,8 +75,7 @@ class Day {
|
||||
final now = DateTime.now();
|
||||
final firstDayOfWeek = now.subtract(Duration(days: now.weekday));
|
||||
|
||||
return DateFormat(DateFormat.WEEKDAY, locale)
|
||||
.format(firstDayOfWeek.add(Duration(days: day)));
|
||||
return DateFormat(DateFormat.WEEKDAY, locale).format(firstDayOfWeek.add(Duration(days: day)));
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
|
||||
@@ -111,8 +111,7 @@ class Log {
|
||||
|
||||
/// Returns the text representation for a single setting, used in the gym mode
|
||||
String get singleLogRepTextNoNl {
|
||||
return repText(reps, repetitionUnitObj, weight, weightUnitObj, rir)
|
||||
.replaceAll('\n', '');
|
||||
return repText(reps, repetitionUnitObj, weight, weightUnitObj, rir).replaceAll('\n', '');
|
||||
}
|
||||
|
||||
/// Override the equals operator
|
||||
@@ -133,8 +132,8 @@ class Log {
|
||||
|
||||
@override
|
||||
//ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
int get hashCode => Object.hash(
|
||||
exerciseBaseId, weight, weightUnitId, reps, repetitionUnitId, rir);
|
||||
int get hashCode =>
|
||||
Object.hash(exerciseBaseId, weight, weightUnitId, reps, repetitionUnitId, rir);
|
||||
|
||||
//@override
|
||||
//int get hashCode => super.hashCode;
|
||||
|
||||
@@ -34,7 +34,6 @@ class RepetitionUnit {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory RepetitionUnit.fromJson(Map<String, dynamic> json) =>
|
||||
_$RepetitionUnitFromJson(json);
|
||||
factory RepetitionUnit.fromJson(Map<String, dynamic> json) => _$RepetitionUnitFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$RepetitionUnitToJson(this);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ RepetitionUnit _$RepetitionUnitFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$RepetitionUnitToJson(RepetitionUnit instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$RepetitionUnitToJson(RepetitionUnit instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
|
||||
@@ -41,18 +41,10 @@ class WorkoutSession {
|
||||
@JsonKey(required: false, defaultValue: '')
|
||||
late String notes;
|
||||
|
||||
@JsonKey(
|
||||
required: true,
|
||||
name: 'time_start',
|
||||
toJson: timeToString,
|
||||
fromJson: stringToTime)
|
||||
@JsonKey(required: true, name: 'time_start', toJson: timeToString, fromJson: stringToTime)
|
||||
late TimeOfDay timeStart;
|
||||
|
||||
@JsonKey(
|
||||
required: true,
|
||||
name: 'time_end',
|
||||
toJson: timeToString,
|
||||
fromJson: stringToTime)
|
||||
@JsonKey(required: true, name: 'time_end', toJson: timeToString, fromJson: stringToTime)
|
||||
late TimeOfDay timeEnd;
|
||||
|
||||
WorkoutSession();
|
||||
@@ -73,8 +65,7 @@ class WorkoutSession {
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory WorkoutSession.fromJson(Map<String, dynamic> json) =>
|
||||
_$WorkoutSessionFromJson(json);
|
||||
factory WorkoutSession.fromJson(Map<String, dynamic> json) => _$WorkoutSessionFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$WorkoutSessionToJson(this);
|
||||
|
||||
String? get impressionAsString {
|
||||
|
||||
@@ -9,14 +9,7 @@ part of 'session.dart';
|
||||
WorkoutSession _$WorkoutSessionFromJson(Map<String, dynamic> json) {
|
||||
$checkKeys(
|
||||
json,
|
||||
requiredKeys: const [
|
||||
'id',
|
||||
'workout',
|
||||
'date',
|
||||
'impression',
|
||||
'time_start',
|
||||
'time_end'
|
||||
],
|
||||
requiredKeys: const ['id', 'workout', 'date', 'impression', 'time_start', 'time_end'],
|
||||
);
|
||||
return WorkoutSession()
|
||||
..id = json['id'] as int?
|
||||
@@ -28,8 +21,7 @@ WorkoutSession _$WorkoutSessionFromJson(Map<String, dynamic> json) {
|
||||
..timeEnd = stringToTime(json['time_end'] as String?);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WorkoutSessionToJson(WorkoutSession instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$WorkoutSessionToJson(WorkoutSession instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'workout': instance.workoutId,
|
||||
'date': toDate(instance.date),
|
||||
|
||||
@@ -114,9 +114,7 @@ class Set {
|
||||
|
||||
/// Returns all settings for the given exercise
|
||||
List<Setting> filterSettingsByExercise(ExerciseBase exerciseBase) {
|
||||
return settings
|
||||
.where((element) => element.exerciseBaseId == exerciseBase.id)
|
||||
.toList();
|
||||
return settings.where((element) => element.exerciseBaseId == exerciseBase.id).toList();
|
||||
}
|
||||
|
||||
/// Returns a list with all repetitions for the given exercise
|
||||
|
||||
@@ -29,18 +29,7 @@ part 'setting.g.dart';
|
||||
class Setting {
|
||||
/// Allowed RiR values. This list must be kept in sync with RIR_OPTIONS in the
|
||||
/// wger server
|
||||
static const POSSIBLE_RIR_VALUES = [
|
||||
'',
|
||||
'0',
|
||||
'0.5',
|
||||
'1',
|
||||
'1.5',
|
||||
'2',
|
||||
'2.5',
|
||||
'3',
|
||||
'3.5',
|
||||
'4'
|
||||
];
|
||||
static const POSSIBLE_RIR_VALUES = ['', '0', '0.5', '1', '1.5', '2', '2.5', '3', '3.5', '4'];
|
||||
static const DEFAULT_RIR = '';
|
||||
|
||||
@JsonKey(required: true)
|
||||
@@ -99,8 +88,7 @@ class Setting {
|
||||
Setting.empty();
|
||||
|
||||
// Boilerplate
|
||||
factory Setting.fromJson(Map<String, dynamic> json) =>
|
||||
_$SettingFromJson(json);
|
||||
factory Setting.fromJson(Map<String, dynamic> json) => _$SettingFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SettingToJson(this);
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ class WeightUnit {
|
||||
});
|
||||
|
||||
// Boilerplate
|
||||
factory WeightUnit.fromJson(Map<String, dynamic> json) =>
|
||||
_$WeightUnitFromJson(json);
|
||||
factory WeightUnit.fromJson(Map<String, dynamic> json) => _$WeightUnitFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$WeightUnitToJson(this);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ WeightUnit _$WeightUnitFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$WeightUnitToJson(WeightUnit instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
|
||||
@@ -63,8 +63,7 @@ class WorkoutPlan {
|
||||
}
|
||||
|
||||
// Boilerplate
|
||||
factory WorkoutPlan.fromJson(Map<String, dynamic> json) =>
|
||||
_$WorkoutPlanFromJson(json);
|
||||
factory WorkoutPlan.fromJson(Map<String, dynamic> json) => _$WorkoutPlanFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$WorkoutPlanToJson(this);
|
||||
|
||||
@@ -74,11 +73,8 @@ class WorkoutPlan {
|
||||
/// means here that the values are the same, i.e. logs with the same weight,
|
||||
/// reps, etc. are considered equal. Workout ID, Log ID and date are not
|
||||
/// considered.
|
||||
List<Log> filterLogsByExerciseBase(ExerciseBase exerciseBase,
|
||||
{bool unique = false}) {
|
||||
var out = logs
|
||||
.where((element) => element.exerciseBaseId == exerciseBase.id)
|
||||
.toList();
|
||||
List<Log> filterLogsByExerciseBase(ExerciseBase exerciseBase, {bool unique = false}) {
|
||||
var out = logs.where((element) => element.exerciseBaseId == exerciseBase.id).toList();
|
||||
|
||||
if (unique) {
|
||||
out = out.toSet().toList();
|
||||
|
||||
@@ -19,8 +19,7 @@ WorkoutPlan _$WorkoutPlanFromJson(Map<String, dynamic> json) {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$WorkoutPlanToJson(WorkoutPlan instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$WorkoutPlanToJson(WorkoutPlan instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'creation_date': instance.creationDate.toIso8601String(),
|
||||
'name': instance.name,
|
||||
|
||||
@@ -65,13 +65,11 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
|
||||
set descriptionEn(String description) => _descriptionEn = description;
|
||||
|
||||
set descriptionTrans(String description) =>
|
||||
_descriptionTranslation = description;
|
||||
set descriptionTrans(String description) => _descriptionTranslation = description;
|
||||
|
||||
set alternateNamesEn(List<String> names) => _alternativeNamesEn = names;
|
||||
|
||||
set alternateNamesTrans(List<String> names) =>
|
||||
_alternativeNamesTranslation = names;
|
||||
set alternateNamesTrans(List<String> names) => _alternativeNamesTranslation = names;
|
||||
|
||||
set equipment(List<Equipment> equipment) => _equipment = equipment;
|
||||
|
||||
@@ -187,8 +185,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
exerciseTranslationEn = await addExerciseTranslation(exerciseTranslationEn);
|
||||
for (final alias in _alternativeNamesEn) {
|
||||
if (alias.isNotEmpty) {
|
||||
exerciseTranslationEn.aliases
|
||||
.add(await addExerciseAlias(alias, exerciseTranslationEn.id!));
|
||||
exerciseTranslationEn.aliases.add(await addExerciseAlias(alias, exerciseTranslationEn.id!));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,8 +193,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
if (language != null) {
|
||||
Translation exerciseTranslationLang = exerciseTranslation;
|
||||
exerciseTranslationLang.base = base;
|
||||
exerciseTranslationLang =
|
||||
await addExerciseTranslation(exerciseTranslationLang);
|
||||
exerciseTranslationLang = await addExerciseTranslation(exerciseTranslationLang);
|
||||
for (final alias in _alternativeNamesTranslation) {
|
||||
if (alias.isNotEmpty) {
|
||||
exerciseTranslationLang.aliases.add(
|
||||
@@ -221,8 +217,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
Future<ExerciseBase> addExerciseBase() async {
|
||||
final Uri postUri = baseProvider.makeUrl(_exerciseBaseUrlPath);
|
||||
|
||||
final Map<String, dynamic> newBaseMap =
|
||||
await baseProvider.post(base.toJson(), postUri);
|
||||
final Map<String, dynamic> newBaseMap = await baseProvider.post(base.toJson(), postUri);
|
||||
final ExerciseBase newExerciseBase = ExerciseBase.fromJson(newBaseMap);
|
||||
notifyListeners();
|
||||
|
||||
@@ -233,8 +228,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
final Uri postUri = baseProvider.makeUrl(_exerciseVariationPath);
|
||||
|
||||
// We send an empty dictionary since at the moment the variations only have an ID
|
||||
final Map<String, dynamic> variationMap =
|
||||
await baseProvider.post({}, postUri);
|
||||
final Map<String, dynamic> variationMap = await baseProvider.post({}, postUri);
|
||||
final Variation newVariation = Variation.fromJson(variationMap);
|
||||
_variationId = newVariation.id;
|
||||
notifyListeners();
|
||||
@@ -243,8 +237,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
|
||||
Future<void> addImages(ExerciseBase base) async {
|
||||
for (final image in _exerciseImages) {
|
||||
final request =
|
||||
http.MultipartRequest('POST', baseProvider.makeUrl(_imagesUrlPath));
|
||||
final request = http.MultipartRequest('POST', baseProvider.makeUrl(_imagesUrlPath));
|
||||
request.headers.addAll(baseProvider.getDefaultHeaders(includeAuth: true));
|
||||
|
||||
request.files.add(await http.MultipartFile.fromPath('image', image.path));
|
||||
@@ -260,8 +253,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
Future<Translation> addExerciseTranslation(Translation exercise) async {
|
||||
final Uri postUri = baseProvider.makeUrl(_exerciseTranslationUrlPath);
|
||||
|
||||
final Map<String, dynamic> newTranslation =
|
||||
await baseProvider.post(exercise.toJson(), postUri);
|
||||
final Map<String, dynamic> newTranslation = await baseProvider.post(exercise.toJson(), postUri);
|
||||
final Translation newExercise = Translation.fromJson(newTranslation);
|
||||
notifyListeners();
|
||||
|
||||
@@ -272,8 +264,7 @@ class AddExerciseProvider with ChangeNotifier {
|
||||
final alias = Alias(exerciseId: exerciseId, alias: name);
|
||||
final Uri postUri = baseProvider.makeUrl(_exerciseAliasPath);
|
||||
|
||||
final Alias newAlias =
|
||||
Alias.fromJson(await baseProvider.post(alias.toJson(), postUri));
|
||||
final Alias newAlias = Alias.fromJson(await baseProvider.post(alias.toJson(), postUri));
|
||||
notifyListeners();
|
||||
|
||||
return newAlias;
|
||||
|
||||
@@ -63,14 +63,12 @@ class AuthProvider with ChangeNotifier {
|
||||
AndroidMetadata.metaDataAsMap.then((value) => metadata = value!);
|
||||
} else if (Platform.isLinux || Platform.isMacOS) {
|
||||
metadata = {
|
||||
MANIFEST_KEY_CHECK_UPDATE:
|
||||
Platform.environment[MANIFEST_KEY_CHECK_UPDATE] ?? '',
|
||||
MANIFEST_KEY_CHECK_UPDATE: Platform.environment[MANIFEST_KEY_CHECK_UPDATE] ?? '',
|
||||
MANIFEST_KEY_API: Platform.environment[MANIFEST_KEY_API] ?? ''
|
||||
};
|
||||
}
|
||||
} on PlatformException {
|
||||
throw Exception(
|
||||
'An error occurred reading the metadata from AndroidManifest');
|
||||
throw Exception('An error occurred reading the metadata from AndroidManifest');
|
||||
} catch (error) {}
|
||||
}
|
||||
}
|
||||
@@ -101,8 +99,7 @@ class AuthProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
/// Checking if there is a new version of the application.
|
||||
Future<bool> applicationUpdateRequired(
|
||||
[String? version, Map<String, String>? metadata]) async {
|
||||
Future<bool> applicationUpdateRequired([String? version, Map<String, String>? metadata]) async {
|
||||
metadata ??= this.metadata;
|
||||
if (!metadata.containsKey(MANIFEST_KEY_CHECK_UPDATE) ||
|
||||
metadata[MANIFEST_KEY_CHECK_UPDATE] == 'false') {
|
||||
@@ -125,10 +122,7 @@ class AuthProvider with ChangeNotifier {
|
||||
required String serverUrl}) async {
|
||||
// Register
|
||||
try {
|
||||
final Map<String, String> data = {
|
||||
'username': username,
|
||||
'password': password
|
||||
};
|
||||
final Map<String, String> data = {'username': username, 'password': password};
|
||||
if (email != '') {
|
||||
data['email'] = email;
|
||||
}
|
||||
@@ -136,8 +130,7 @@ class AuthProvider with ChangeNotifier {
|
||||
makeUri(serverUrl, REGISTRATION_URL),
|
||||
headers: {
|
||||
HttpHeaders.contentTypeHeader: 'application/json; charset=UTF-8',
|
||||
HttpHeaders.authorizationHeader:
|
||||
'Token ${metadata[MANIFEST_KEY_API]}',
|
||||
HttpHeaders.authorizationHeader: 'Token ${metadata[MANIFEST_KEY_API]}',
|
||||
HttpHeaders.userAgentHeader: getAppNameHeader(),
|
||||
},
|
||||
body: json.encode(data),
|
||||
|
||||
@@ -51,8 +51,7 @@ class WgerBaseProvider {
|
||||
}
|
||||
|
||||
/// Helper function to make a URL.
|
||||
Uri makeUrl(String path,
|
||||
{int? id, String? objectMethod, Map<String, dynamic>? query}) {
|
||||
Uri makeUrl(String path, {int? id, String? objectMethod, Map<String, dynamic>? query}) {
|
||||
return makeUri(auth.serverUrl!, path, id, objectMethod, query);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,8 +77,7 @@ class BodyWeightProvider with ChangeNotifier {
|
||||
|
||||
Future<WeightEntry> addEntry(WeightEntry entry) async {
|
||||
// Create entry and return it
|
||||
final data = await baseProvider.post(
|
||||
entry.toJson(), baseProvider.makeUrl(BODY_WEIGHT_URL));
|
||||
final data = await baseProvider.post(entry.toJson(), baseProvider.makeUrl(BODY_WEIGHT_URL));
|
||||
final WeightEntry weightEntry = WeightEntry.fromJson(data);
|
||||
_entries.add(weightEntry);
|
||||
_entries.sort((a, b) => b.date.compareTo(a.date));
|
||||
@@ -97,8 +96,7 @@ class BodyWeightProvider with ChangeNotifier {
|
||||
|
||||
Future<void> deleteEntry(int id) async {
|
||||
// Send the request and remove the entry from the list...
|
||||
final existingEntryIndex =
|
||||
_entries.indexWhere((element) => element.id == id);
|
||||
final existingEntryIndex = _entries.indexWhere((element) => element.id == id);
|
||||
final existingWeightEntry = _entries[existingEntryIndex];
|
||||
_entries.removeAt(existingEntryIndex);
|
||||
notifyListeners();
|
||||
|
||||
@@ -137,8 +137,7 @@ class ExercisesProvider with ChangeNotifier {
|
||||
title: 'Equipment',
|
||||
items: Map.fromEntries(
|
||||
_equipment.map(
|
||||
(singleEquipment) =>
|
||||
MapEntry<Equipment, bool>(singleEquipment, false),
|
||||
(singleEquipment) => MapEntry<Equipment, bool>(singleEquipment, false),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -168,15 +167,13 @@ class ExercisesProvider with ChangeNotifier {
|
||||
|
||||
// Filter by exercise category and equipment (REPLACE WITH HTTP REQUEST)
|
||||
filteredExerciseBases = filteredItems.where((exercise) {
|
||||
final bool isInAnyCategory =
|
||||
filters!.exerciseCategories.selected.contains(exercise.category);
|
||||
final bool isInAnyCategory = filters!.exerciseCategories.selected.contains(exercise.category);
|
||||
|
||||
final bool doesContainAnyEquipment = filters!.equipment.selected.any(
|
||||
(selectedEquipment) => exercise.equipment.contains(selectedEquipment),
|
||||
);
|
||||
|
||||
return (isInAnyCategory ||
|
||||
filters!.exerciseCategories.selected.isEmpty) &&
|
||||
return (isInAnyCategory || filters!.exerciseCategories.selected.isEmpty) &&
|
||||
(doesContainAnyEquipment || filters!.equipment.selected.isEmpty);
|
||||
}).toList();
|
||||
}
|
||||
@@ -204,8 +201,7 @@ class ExercisesProvider with ChangeNotifier {
|
||||
/// returned exercises. Since this is typically called by one exercise, we are
|
||||
/// not interested in seeing that same exercise returned in the list of variations.
|
||||
/// If this parameter is not passed, all exercises are returned.
|
||||
List<ExerciseBase> findExerciseBasesByVariationId(int id,
|
||||
{int? exerciseBaseIdToExclude}) {
|
||||
List<ExerciseBase> findExerciseBasesByVariationId(int id, {int? exerciseBaseIdToExclude}) {
|
||||
var out = _exerciseBases.where((base) => base.variationId == id).toList();
|
||||
|
||||
if (exerciseBaseIdToExclude != null) {
|
||||
@@ -247,24 +243,22 @@ class ExercisesProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> fetchAndSetCategories() async {
|
||||
final categories = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_categoriesUrlPath));
|
||||
final categories = await baseProvider.fetchPaginated(baseProvider.makeUrl(_categoriesUrlPath));
|
||||
for (final category in categories) {
|
||||
_categories.add(ExerciseCategory.fromJson(category));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchAndSetVariations() async {
|
||||
final variations = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_exerciseVariationsUrlPath));
|
||||
final variations =
|
||||
await baseProvider.fetchPaginated(baseProvider.makeUrl(_exerciseVariationsUrlPath));
|
||||
for (final variation in variations) {
|
||||
_variations.add(Variation.fromJson(variation));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchAndSetMuscles() async {
|
||||
final muscles = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_musclesUrlPath));
|
||||
final muscles = await baseProvider.fetchPaginated(baseProvider.makeUrl(_musclesUrlPath));
|
||||
|
||||
for (final muscle in muscles) {
|
||||
_muscles.add(Muscle.fromJson(muscle));
|
||||
@@ -272,8 +266,7 @@ class ExercisesProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> fetchAndSetEquipment() async {
|
||||
final equipments = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_equipmentUrlPath));
|
||||
final equipments = await baseProvider.fetchPaginated(baseProvider.makeUrl(_equipmentUrlPath));
|
||||
|
||||
for (final equipment in equipments) {
|
||||
_equipment.add(Equipment.fromJson(equipment));
|
||||
@@ -281,8 +274,7 @@ class ExercisesProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> fetchAndSetLanguages() async {
|
||||
final languageData = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_languageUrlPath));
|
||||
final languageData = await baseProvider.fetchPaginated(baseProvider.makeUrl(_languageUrlPath));
|
||||
|
||||
for (final language in languageData) {
|
||||
_languages.add(Language.fromJson(language));
|
||||
@@ -302,8 +294,7 @@ class ExercisesProvider with ChangeNotifier {
|
||||
baseProvider.makeUrl(_exerciseBaseInfoUrlPath, id: exerciseBaseId),
|
||||
);
|
||||
|
||||
final newBase =
|
||||
readExerciseBaseFromBaseInfo(ExerciseBaseData.fromJson(baseData));
|
||||
final newBase = readExerciseBaseFromBaseInfo(ExerciseBaseData.fromJson(baseData));
|
||||
|
||||
// TODO: save to cache. Since we can't easily generate the JSON, perhaps just reload?
|
||||
_exerciseBases.add(newBase);
|
||||
@@ -383,8 +374,7 @@ class ExercisesProvider with ChangeNotifier {
|
||||
// Only uncomment if need to delete the table, (only for testing purposes).
|
||||
// await database.delete(database.exerciseTableItems).go();
|
||||
// Fetch the list of rows from ExercisesDataTable. ExerciseTable is the Type of the Row
|
||||
final List<ExerciseTable> items =
|
||||
await database.select(database.exerciseTableItems).get();
|
||||
final List<ExerciseTable> items = await database.select(database.exerciseTableItems).get();
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await checkExerciseCacheVersion();
|
||||
@@ -420,8 +410,7 @@ class ExercisesProvider with ChangeNotifier {
|
||||
|
||||
// Load categories, muscles, equipment and languages
|
||||
final data = await Future.wait<dynamic>([
|
||||
baseProvider.fetch(baseProvider
|
||||
.makeUrl(_exerciseBaseInfoUrlPath, query: {'limit': '1000'})),
|
||||
baseProvider.fetch(baseProvider.makeUrl(_exerciseBaseInfoUrlPath, query: {'limit': '1000'})),
|
||||
fetchAndSetCategories(),
|
||||
fetchAndSetMuscles(),
|
||||
fetchAndSetEquipment(),
|
||||
@@ -433,41 +422,27 @@ class ExercisesProvider with ChangeNotifier {
|
||||
final List<ExerciseBaseData> exerciseBaseData =
|
||||
exerciseData.map((e) => ExerciseBaseData.fromJson(e)).toList();
|
||||
|
||||
_exerciseBases = exerciseBaseData
|
||||
.map((e) => readExerciseBaseFromBaseInfo(e))
|
||||
.toList()
|
||||
.cast<ExerciseBase>();
|
||||
_exerciseBases =
|
||||
exerciseBaseData.map((e) => readExerciseBaseFromBaseInfo(e)).toList().cast<ExerciseBase>();
|
||||
try {
|
||||
// Save the result to the cache
|
||||
for (int i = 0; i < _exerciseBases.length; i++) {
|
||||
await database.into(database.exerciseTableItems).insert(
|
||||
ExerciseTableItemsCompanion.insert(
|
||||
category: (i < _categories.length)
|
||||
? Value(_categories[i])
|
||||
: const Value(null),
|
||||
equipment: (i < _equipment.length)
|
||||
? Value(_equipment[i])
|
||||
: const Value(null),
|
||||
exercisebase: (i < _exerciseBases.length)
|
||||
? Value(_exerciseBases[i])
|
||||
: const Value(null),
|
||||
muscle: (i < _muscles.length)
|
||||
? Value(_muscles[i])
|
||||
: const Value(null),
|
||||
variation: (i < _variations.length)
|
||||
? Value(_variations[i])
|
||||
: const Value(null),
|
||||
language: (i < _languages.length)
|
||||
? Value(_languages[i])
|
||||
: const Value(null),
|
||||
category: (i < _categories.length) ? Value(_categories[i]) : const Value(null),
|
||||
equipment: (i < _equipment.length) ? Value(_equipment[i]) : const Value(null),
|
||||
exercisebase:
|
||||
(i < _exerciseBases.length) ? Value(_exerciseBases[i]) : const Value(null),
|
||||
muscle: (i < _muscles.length) ? Value(_muscles[i]) : const Value(null),
|
||||
variation: (i < _variations.length) ? Value(_variations[i]) : const Value(null),
|
||||
language: (i < _languages.length) ? Value(_languages[i]) : const Value(null),
|
||||
),
|
||||
);
|
||||
}
|
||||
// final List<ExerciseTable> items = await database.select(database.exerciseTableItems).get();
|
||||
final cacheData = {
|
||||
'expiresIn': DateTime.now()
|
||||
.add(const Duration(days: EXERCISE_CACHE_DAYS))
|
||||
.toIso8601String(),
|
||||
'expiresIn':
|
||||
DateTime.now().add(const Duration(days: EXERCISE_CACHE_DAYS)).toIso8601String(),
|
||||
};
|
||||
log("Saved ${_exerciseBases.length} exercises to cache. Valid till ${cacheData['expiresIn']}");
|
||||
|
||||
@@ -485,8 +460,7 @@ class ExercisesProvider with ChangeNotifier {
|
||||
/// We could do this locally, but the server has better text searching capabilities
|
||||
/// with postgresql.
|
||||
Future<List<ExerciseBase>> searchExercise(String name,
|
||||
{String languageCode = LANGUAGE_SHORT_ENGLISH,
|
||||
bool searchEnglish = false}) async {
|
||||
{String languageCode = LANGUAGE_SHORT_ENGLISH, bool searchEnglish = false}) async {
|
||||
if (name.length <= 1) {
|
||||
return [];
|
||||
}
|
||||
@@ -554,10 +528,8 @@ class Filters {
|
||||
List<FilterCategory> get filterCategories => [exerciseCategories, equipment];
|
||||
|
||||
bool get isNothingMarked {
|
||||
final isExerciseCategoryMarked =
|
||||
exerciseCategories.items.values.any((isMarked) => isMarked);
|
||||
final isEquipmentMarked =
|
||||
equipment.items.values.any((isMarked) => isMarked);
|
||||
final isExerciseCategoryMarked = exerciseCategories.items.values.any((isMarked) => isMarked);
|
||||
final isEquipmentMarked = equipment.items.values.any((isMarked) => isMarked);
|
||||
return !isExerciseCategoryMarked && !isEquipmentMarked;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
List<gallery.Image> images = [];
|
||||
|
||||
GalleryProvider(AuthProvider auth, List<gallery.Image> entries,
|
||||
[http.Client? client])
|
||||
GalleryProvider(AuthProvider auth, List<gallery.Image> entries, [http.Client? client])
|
||||
: images = entries,
|
||||
super(auth, client);
|
||||
|
||||
@@ -64,8 +63,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
|
||||
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
|
||||
});
|
||||
request.files
|
||||
.add(await http.MultipartFile.fromPath('image', imageFile.path));
|
||||
request.files.add(await http.MultipartFile.fromPath('image', imageFile.path));
|
||||
request.fields['date'] = toDate(image.date)!;
|
||||
request.fields['description'] = image.description;
|
||||
|
||||
@@ -79,8 +77,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> editImage(gallery.Image image, XFile? imageFile) async {
|
||||
final request =
|
||||
http.MultipartRequest('PATCH', makeUrl(_galleryUrlPath, id: image.id));
|
||||
final request = http.MultipartRequest('PATCH', makeUrl(_galleryUrlPath, id: image.id));
|
||||
request.headers.addAll({
|
||||
HttpHeaders.authorizationHeader: 'Token ${auth.token}',
|
||||
HttpHeaders.userAgentHeader: auth.getAppNameHeader(),
|
||||
@@ -88,8 +85,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
// Only send the image if a new one was selected
|
||||
if (imageFile != null) {
|
||||
request.files
|
||||
.add(await http.MultipartFile.fromPath('image', imageFile.path));
|
||||
request.files.add(await http.MultipartFile.fromPath('image', imageFile.path));
|
||||
}
|
||||
|
||||
// Update image info
|
||||
|
||||
@@ -68,15 +68,13 @@ class MeasurementProvider with ChangeNotifier {
|
||||
final categoryIndex = _categories.indexOf(category);
|
||||
|
||||
// Process the response
|
||||
final requestUrl = baseProvider
|
||||
.makeUrl(_entryUrl, query: {'category': category.id.toString()});
|
||||
final requestUrl = baseProvider.makeUrl(_entryUrl, query: {'category': category.id.toString()});
|
||||
final data = await baseProvider.fetch(requestUrl);
|
||||
final List<MeasurementEntry> loadedEntries = [];
|
||||
for (final entry in data['results']) {
|
||||
loadedEntries.add(MeasurementEntry.fromJson(entry));
|
||||
}
|
||||
final MeasurementCategory editedCategory =
|
||||
category.copyWith(entries: loadedEntries);
|
||||
final MeasurementCategory editedCategory = category.copyWith(entries: loadedEntries);
|
||||
_categories.removeAt(categoryIndex);
|
||||
_categories.insert(categoryIndex, editedCategory);
|
||||
notifyListeners();
|
||||
@@ -85,18 +83,15 @@ class MeasurementProvider with ChangeNotifier {
|
||||
/// Fetches and sets the measurement categories and their entries
|
||||
Future<void> fetchAndSetAllCategoriesAndEntries() async {
|
||||
await fetchAndSetCategories();
|
||||
await Future.wait(
|
||||
_categories.map((e) => fetchAndSetCategoryEntries(e.id!)).toList());
|
||||
await Future.wait(_categories.map((e) => fetchAndSetCategoryEntries(e.id!)).toList());
|
||||
}
|
||||
|
||||
/// Adds a measurement category
|
||||
Future<void> addCategory(MeasurementCategory category) async {
|
||||
final Uri postUri = baseProvider.makeUrl(_categoryUrl);
|
||||
|
||||
final Map<String, dynamic> newCategoryMap =
|
||||
await baseProvider.post(category.toJson(), postUri);
|
||||
final MeasurementCategory newCategory =
|
||||
MeasurementCategory.fromJson(newCategoryMap);
|
||||
final Map<String, dynamic> newCategoryMap = await baseProvider.post(category.toJson(), postUri);
|
||||
final MeasurementCategory newCategory = MeasurementCategory.fromJson(newCategoryMap);
|
||||
_categories.add(newCategory);
|
||||
_categories.sort((a, b) => a.name.compareTo(b.name));
|
||||
notifyListeners();
|
||||
@@ -123,16 +118,14 @@ class MeasurementProvider with ChangeNotifier {
|
||||
Future<void> editCategory(int id, String? newName, String? newUnit) async {
|
||||
final MeasurementCategory oldCategory = findCategoryById(id);
|
||||
final int categoryIndex = _categories.indexOf(oldCategory);
|
||||
final MeasurementCategory tempNewCategory =
|
||||
oldCategory.copyWith(name: newName, unit: newUnit);
|
||||
final MeasurementCategory tempNewCategory = oldCategory.copyWith(name: newName, unit: newUnit);
|
||||
|
||||
final Map<String, dynamic> response = await baseProvider.patch(
|
||||
tempNewCategory.toJson(),
|
||||
baseProvider.makeUrl(_categoryUrl, id: id),
|
||||
);
|
||||
final MeasurementCategory newCategory =
|
||||
MeasurementCategory.fromJson(response)
|
||||
.copyWith(entries: oldCategory.entries);
|
||||
MeasurementCategory.fromJson(response).copyWith(entries: oldCategory.entries);
|
||||
_categories.removeAt(categoryIndex);
|
||||
_categories.insert(categoryIndex, newCategory);
|
||||
notifyListeners();
|
||||
@@ -142,8 +135,7 @@ class MeasurementProvider with ChangeNotifier {
|
||||
Future<void> addEntry(MeasurementEntry entry) async {
|
||||
final Uri postUri = baseProvider.makeUrl(_entryUrl);
|
||||
|
||||
final Map<String, dynamic> newEntryMap =
|
||||
await baseProvider.post(entry.toJson(), postUri);
|
||||
final Map<String, dynamic> newEntryMap = await baseProvider.post(entry.toJson(), postUri);
|
||||
final MeasurementEntry newEntry = MeasurementEntry.fromJson(newEntryMap);
|
||||
|
||||
final MeasurementCategory category = findCategoryById(newEntry.category);
|
||||
@@ -191,8 +183,8 @@ class MeasurementProvider with ChangeNotifier {
|
||||
date: newDate,
|
||||
);
|
||||
|
||||
final Map<String, dynamic> response = await baseProvider.patch(
|
||||
tempNewEntry.toJson(), baseProvider.makeUrl(_entryUrl, id: id));
|
||||
final Map<String, dynamic> response =
|
||||
await baseProvider.patch(tempNewEntry.toJson(), baseProvider.makeUrl(_entryUrl, id: id));
|
||||
|
||||
final MeasurementEntry newEntry = MeasurementEntry.fromJson(response);
|
||||
category.entries.removeAt(entryIndex);
|
||||
|
||||
@@ -46,8 +46,7 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
List<NutritionalPlan> _plans = [];
|
||||
List<Ingredient> _ingredients = [];
|
||||
|
||||
NutritionPlansProvider(this.baseProvider, List<NutritionalPlan> entries)
|
||||
: _plans = entries;
|
||||
NutritionPlansProvider(this.baseProvider, List<NutritionalPlan> entries) : _plans = entries;
|
||||
|
||||
List<NutritionalPlan> get items {
|
||||
return [..._plans];
|
||||
@@ -92,8 +91,8 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
/// Fetches and sets all plans sparsely, i.e. only with the data on the plan
|
||||
/// object itself and no child attributes
|
||||
Future<void> fetchAndSetAllPlansSparse() async {
|
||||
final data = await baseProvider.fetchPaginated(
|
||||
baseProvider.makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}));
|
||||
final data = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_nutritionalPlansPath, query: {'limit': '1000'}));
|
||||
_plans = [];
|
||||
for (final planData in data) {
|
||||
final plan = NutritionalPlan.fromJson(planData);
|
||||
@@ -105,8 +104,7 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
|
||||
/// Fetches and sets all plans fully, i.e. with all corresponding child objects
|
||||
Future<void> fetchAndSetAllPlansFull() async {
|
||||
final data = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_nutritionalPlansPath));
|
||||
final data = await baseProvider.fetchPaginated(baseProvider.makeUrl(_nutritionalPlansPath));
|
||||
for (final entry in data) {
|
||||
await fetchAndSetPlanFull(entry['id']);
|
||||
}
|
||||
@@ -196,8 +194,7 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
_plans.removeAt(existingPlanIndex);
|
||||
notifyListeners();
|
||||
|
||||
final response =
|
||||
await baseProvider.deleteRequest(_nutritionalPlansPath, id);
|
||||
final response = await baseProvider.deleteRequest(_nutritionalPlansPath, id);
|
||||
|
||||
if (response.statusCode >= 400) {
|
||||
_plans.insert(existingPlanIndex, existingPlan);
|
||||
@@ -254,8 +251,7 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
|
||||
/// Adds a meal item to a meal
|
||||
Future<MealItem> addMealItem(MealItem mealItem, Meal meal) async {
|
||||
final data = await baseProvider.post(
|
||||
mealItem.toJson(), baseProvider.makeUrl(_mealItemPath));
|
||||
final data = await baseProvider.post(mealItem.toJson(), baseProvider.makeUrl(_mealItemPath));
|
||||
|
||||
mealItem = MealItem.fromJson(data);
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
@@ -275,8 +271,7 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
|
||||
// Try to delete
|
||||
final response =
|
||||
await baseProvider.deleteRequest(_mealItemPath, mealItem.id!);
|
||||
final response = await baseProvider.deleteRequest(_mealItemPath, mealItem.id!);
|
||||
if (response.statusCode >= 400) {
|
||||
meal.mealItems.insert(mealItemIndex, existingMealItem);
|
||||
notifyListeners();
|
||||
@@ -319,8 +314,7 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
if (prefs.containsKey(PREFS_INGREDIENTS)) {
|
||||
final ingredientData = json.decode(prefs.getString(PREFS_INGREDIENTS)!);
|
||||
if (DateTime.parse(ingredientData['expiresIn']).isAfter(DateTime.now())) {
|
||||
ingredientData['ingredients']
|
||||
.forEach((e) => _ingredients.add(Ingredient.fromJson(e)));
|
||||
ingredientData['ingredients'].forEach((e) => _ingredients.add(Ingredient.fromJson(e)));
|
||||
log("Read ${ingredientData['ingredients'].length} ingredients from cache. Valid till ${ingredientData['expiresIn']}");
|
||||
return;
|
||||
}
|
||||
@@ -329,9 +323,7 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
// Initialise an empty cache
|
||||
final ingredientData = {
|
||||
'date': DateTime.now().toIso8601String(),
|
||||
'expiresIn': DateTime.now()
|
||||
.add(const Duration(days: DAYS_TO_CACHE))
|
||||
.toIso8601String(),
|
||||
'expiresIn': DateTime.now().add(const Duration(days: DAYS_TO_CACHE)).toIso8601String(),
|
||||
'ingredients': []
|
||||
};
|
||||
prefs.setString(PREFS_INGREDIENTS, json.encode(ingredientData));
|
||||
@@ -355,8 +347,8 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
|
||||
// Send the request
|
||||
final response = await baseProvider.fetch(
|
||||
baseProvider.makeUrl(_ingredientSearchPath,
|
||||
query: {'term': name, 'language': languages.join(',')}),
|
||||
baseProvider
|
||||
.makeUrl(_ingredientSearchPath, query: {'term': name, 'language': languages.join(',')}),
|
||||
);
|
||||
|
||||
// Process the response
|
||||
@@ -398,14 +390,12 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
/// Log custom ingredient to nutrition diary
|
||||
Future<void> logIngredientToDiary(MealItem mealItem, int planId,
|
||||
[DateTime? dateTime]) async {
|
||||
Future<void> logIngredientToDiary(MealItem mealItem, int planId, [DateTime? dateTime]) async {
|
||||
final plan = findById(planId);
|
||||
mealItem.ingredientObj = await fetchIngredient(mealItem.ingredientId);
|
||||
final Log log = Log.fromMealItem(mealItem, plan.id!, null, dateTime);
|
||||
|
||||
final data = await baseProvider.post(
|
||||
log.toJson(), baseProvider.makeUrl(_nutritionDiaryPath));
|
||||
final data = await baseProvider.post(log.toJson(), baseProvider.makeUrl(_nutritionDiaryPath));
|
||||
log.id = data['id'];
|
||||
plan.logs.add(log);
|
||||
notifyListeners();
|
||||
@@ -425,11 +415,7 @@ class NutritionPlansProvider with ChangeNotifier {
|
||||
final data = await baseProvider.fetchPaginated(
|
||||
baseProvider.makeUrl(
|
||||
_nutritionDiaryPath,
|
||||
query: {
|
||||
'plan': plan.id.toString(),
|
||||
'limit': '999',
|
||||
'ordering': 'datetime'
|
||||
},
|
||||
query: {'plan': plan.id.toString(), 'limit': '999', 'ordering': 'datetime'},
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ class UserProvider with ChangeNotifier {
|
||||
|
||||
/// Fetch the current user's profile
|
||||
Future<void> fetchAndSetProfile() async {
|
||||
final userData =
|
||||
await baseProvider.fetch(baseProvider.makeUrl(PROFILE_URL));
|
||||
final userData = await baseProvider.fetch(baseProvider.makeUrl(PROFILE_URL));
|
||||
try {
|
||||
profile = Profile.fromJson(userData);
|
||||
} catch (error) {
|
||||
|
||||
@@ -53,8 +53,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
List<WeightUnit> _weightUnits = [];
|
||||
List<RepetitionUnit> _repetitionUnit = [];
|
||||
|
||||
WorkoutPlansProvider(
|
||||
this.baseProvider, ExercisesProvider exercises, List<WorkoutPlan> entries)
|
||||
WorkoutPlansProvider(this.baseProvider, ExercisesProvider exercises, List<WorkoutPlan> entries)
|
||||
: _exercises = exercises,
|
||||
_workoutPlans = entries;
|
||||
|
||||
@@ -76,8 +75,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
|
||||
/// Return the default weight unit (kg)
|
||||
WeightUnit get defaultWeightUnit {
|
||||
return _weightUnits
|
||||
.firstWhere((element) => element.id == DEFAULT_WEIGHT_UNIT);
|
||||
return _weightUnits.firstWhere((element) => element.id == DEFAULT_WEIGHT_UNIT);
|
||||
}
|
||||
|
||||
List<RepetitionUnit> get repetitionUnits {
|
||||
@@ -86,8 +84,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
|
||||
/// Return the default weight unit (reps)
|
||||
RepetitionUnit get defaultRepetitionUnit {
|
||||
return _repetitionUnit
|
||||
.firstWhere((element) => element.id == REP_UNIT_REPETITIONS);
|
||||
return _repetitionUnit.firstWhere((element) => element.id == REP_UNIT_REPETITIONS);
|
||||
}
|
||||
|
||||
List<WorkoutPlan> getPlans() {
|
||||
@@ -194,8 +191,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
// Days
|
||||
final List<Day> days = [];
|
||||
final daysData = await baseProvider.fetch(
|
||||
baseProvider
|
||||
.makeUrl(_daysUrlPath, query: {'training': plan.id.toString()}),
|
||||
baseProvider.makeUrl(_daysUrlPath, query: {'training': plan.id.toString()}),
|
||||
);
|
||||
for (final dayEntry in daysData['results']) {
|
||||
final day = Day.fromJson(dayEntry);
|
||||
@@ -203,8 +199,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
// Sets
|
||||
final List<Set> sets = [];
|
||||
final setData = await baseProvider.fetch(
|
||||
baseProvider
|
||||
.makeUrl(_setsUrlPath, query: {'exerciseday': day.id.toString()}),
|
||||
baseProvider.makeUrl(_setsUrlPath, query: {'exerciseday': day.id.toString()}),
|
||||
);
|
||||
for (final setEntry in setData['results']) {
|
||||
final workoutSet = Set.fromJson(setEntry);
|
||||
@@ -213,22 +208,20 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
|
||||
// Settings
|
||||
final List<Setting> settings = [];
|
||||
final settingData =
|
||||
allSettingsData['results'].where((s) => s['set'] == workoutSet.id);
|
||||
final settingData = allSettingsData['results'].where((s) => s['set'] == workoutSet.id);
|
||||
|
||||
for (final settingEntry in settingData) {
|
||||
final workoutSetting = Setting.fromJson(settingEntry);
|
||||
|
||||
workoutSetting.exerciseBase = await _exercises
|
||||
.fetchAndSetExerciseBase(workoutSetting.exerciseBaseId);
|
||||
workoutSetting.exerciseBase =
|
||||
await _exercises.fetchAndSetExerciseBase(workoutSetting.exerciseBaseId);
|
||||
workoutSetting.weightUnit = _weightUnits.firstWhere(
|
||||
(e) => e.id == workoutSetting.weightUnitId,
|
||||
);
|
||||
workoutSetting.repetitionUnit = _repetitionUnit.firstWhere(
|
||||
(e) => e.id == workoutSetting.repetitionUnitId,
|
||||
);
|
||||
if (!workoutSet.exerciseBasesIds
|
||||
.contains(workoutSetting.exerciseBaseId)) {
|
||||
if (!workoutSet.exerciseBasesIds.contains(workoutSetting.exerciseBaseId)) {
|
||||
workoutSet.addExerciseBase(workoutSetting.exerciseBaseObj);
|
||||
}
|
||||
|
||||
@@ -252,12 +245,9 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
for (final logEntry in logData) {
|
||||
try {
|
||||
final log = Log.fromJson(logEntry);
|
||||
log.weightUnit =
|
||||
_weightUnits.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.repetitionUnit =
|
||||
_repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.exerciseBase =
|
||||
await _exercises.fetchAndSetExerciseBase(log.exerciseBaseId);
|
||||
log.weightUnit = _weightUnits.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.repetitionUnit = _repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.exerciseBase = await _exercises.fetchAndSetExerciseBase(log.exerciseBaseId);
|
||||
plan.logs.add(log);
|
||||
} catch (e) {
|
||||
dev.log('fire! fire!');
|
||||
@@ -271,8 +261,8 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<WorkoutPlan> addWorkout(WorkoutPlan workout) async {
|
||||
final data = await baseProvider.post(
|
||||
workout.toJson(), baseProvider.makeUrl(_workoutPlansUrlPath));
|
||||
final data =
|
||||
await baseProvider.post(workout.toJson(), baseProvider.makeUrl(_workoutPlansUrlPath));
|
||||
final plan = WorkoutPlan.fromJson(data);
|
||||
_workoutPlans.insert(0, plan);
|
||||
notifyListeners();
|
||||
@@ -280,14 +270,13 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> editWorkout(WorkoutPlan workout) async {
|
||||
await baseProvider.patch(workout.toJson(),
|
||||
baseProvider.makeUrl(_workoutPlansUrlPath, id: workout.id));
|
||||
await baseProvider.patch(
|
||||
workout.toJson(), baseProvider.makeUrl(_workoutPlansUrlPath, id: workout.id));
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> deleteWorkout(int id) async {
|
||||
final existingWorkoutIndex =
|
||||
_workoutPlans.indexWhere((element) => element.id == id);
|
||||
final existingWorkoutIndex = _workoutPlans.indexWhere((element) => element.id == id);
|
||||
final existingWorkout = _workoutPlans[existingWorkoutIndex];
|
||||
_workoutPlans.removeAt(existingWorkoutIndex);
|
||||
notifyListeners();
|
||||
@@ -301,8 +290,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> fetchLogData(
|
||||
WorkoutPlan workout, ExerciseBase base) async {
|
||||
Future<Map<String, dynamic>> fetchLogData(WorkoutPlan workout, ExerciseBase base) async {
|
||||
final data = await baseProvider.fetch(
|
||||
baseProvider.makeUrl(
|
||||
_workoutPlansUrlPath,
|
||||
@@ -316,8 +304,8 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
|
||||
/// Fetch and set weight units for workout (kg, lb, plate, etc.)
|
||||
Future<void> fetchAndSetRepetitionUnits() async {
|
||||
final response = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_repetitionUnitUrlPath));
|
||||
final response =
|
||||
await baseProvider.fetchPaginated(baseProvider.makeUrl(_repetitionUnitUrlPath));
|
||||
for (final unit in response) {
|
||||
_repetitionUnit.add(RepetitionUnit.fromJson(unit));
|
||||
}
|
||||
@@ -325,8 +313,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
|
||||
/// Fetch and set weight units for workout (kg, lb, plate, etc.)
|
||||
Future<void> fetchAndSetWeightUnits() async {
|
||||
final response = await baseProvider
|
||||
.fetchPaginated(baseProvider.makeUrl(_weightUnitUrlPath));
|
||||
final response = await baseProvider.fetchPaginated(baseProvider.makeUrl(_weightUnitUrlPath));
|
||||
for (final unit in response) {
|
||||
_weightUnits.add(WeightUnit.fromJson(unit));
|
||||
}
|
||||
@@ -344,8 +331,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
unitData['weightUnit'].forEach(
|
||||
(e) => _weightUnits.add(WeightUnit.fromJson(e)),
|
||||
);
|
||||
dev.log(
|
||||
"Read workout units data from cache. Valid till ${unitData['expiresIn']}");
|
||||
dev.log("Read workout units data from cache. Valid till ${unitData['expiresIn']}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -357,9 +343,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
// Save the result to the cache
|
||||
final exerciseData = {
|
||||
'date': DateTime.now().toIso8601String(),
|
||||
'expiresIn': DateTime.now()
|
||||
.add(const Duration(days: DAYS_TO_CACHE))
|
||||
.toIso8601String(),
|
||||
'expiresIn': DateTime.now().add(const Duration(days: DAYS_TO_CACHE)).toIso8601String(),
|
||||
'repetitionUnits': _repetitionUnit.map((e) => e.toJson()).toList(),
|
||||
'weightUnit': _weightUnits.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
@@ -375,8 +359,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
* Saves a new day instance to the DB and adds it to the given workout
|
||||
*/
|
||||
day.workoutId = workout.id!;
|
||||
final data = await baseProvider.post(
|
||||
day.toJson(), baseProvider.makeUrl(_daysUrlPath));
|
||||
final data = await baseProvider.post(day.toJson(), baseProvider.makeUrl(_daysUrlPath));
|
||||
day = Day.fromJson(data);
|
||||
day.sets = [];
|
||||
workout.days.insert(0, day);
|
||||
@@ -385,8 +368,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> editDay(Day day) async {
|
||||
await baseProvider.patch(
|
||||
day.toJson(), baseProvider.makeUrl(_daysUrlPath, id: day.id));
|
||||
await baseProvider.patch(day.toJson(), baseProvider.makeUrl(_daysUrlPath, id: day.id));
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -505,8 +487,7 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<WorkoutSession> addSession(WorkoutSession session) async {
|
||||
final data = await baseProvider.post(
|
||||
session.toJson(), baseProvider.makeUrl(_sessionUrlPath));
|
||||
final data = await baseProvider.post(session.toJson(), baseProvider.makeUrl(_sessionUrlPath));
|
||||
final newSession = WorkoutSession.fromJson(data);
|
||||
notifyListeners();
|
||||
return newSession;
|
||||
@@ -516,16 +497,13 @@ class WorkoutPlansProvider with ChangeNotifier {
|
||||
* Logs
|
||||
*/
|
||||
Future<Log> addLog(Log log) async {
|
||||
final data = await baseProvider.post(
|
||||
log.toJson(), baseProvider.makeUrl(_logsUrlPath));
|
||||
final data = await baseProvider.post(log.toJson(), baseProvider.makeUrl(_logsUrlPath));
|
||||
final newLog = Log.fromJson(data);
|
||||
|
||||
log.id = newLog.id;
|
||||
log.weightUnit = _weightUnits.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.repetitionUnit =
|
||||
_repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.exerciseBase =
|
||||
await _exercises.fetchAndSetExerciseBase(log.exerciseBaseId);
|
||||
log.repetitionUnit = _repetitionUnit.firstWhere((e) => e.id == log.weightUnitId);
|
||||
log.exerciseBase = await _exercises.fetchAndSetExerciseBase(log.exerciseBaseId);
|
||||
|
||||
final plan = findById(log.workoutPlan);
|
||||
plan.logs.add(log);
|
||||
|
||||
@@ -25,9 +25,7 @@ class AddExerciseScreen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final profile = context.read<UserProvider>().profile;
|
||||
|
||||
return profile!.isTrustworthy
|
||||
? const AddExerciseStepper()
|
||||
: const EmailNotVerified();
|
||||
return profile!.isTrustworthy ? const AddExerciseStepper() : const EmailNotVerified();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,18 +70,13 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
final addExerciseProvider =
|
||||
context.read<AddExerciseProvider>();
|
||||
final exerciseProvider =
|
||||
context.read<ExercisesProvider>();
|
||||
final addExerciseProvider = context.read<AddExerciseProvider>();
|
||||
final exerciseProvider = context.read<ExercisesProvider>();
|
||||
|
||||
final baseId = await addExerciseProvider.addExercise();
|
||||
final base = await exerciseProvider
|
||||
.fetchAndSetExerciseBase(baseId);
|
||||
final name = base
|
||||
.getExercise(
|
||||
Localizations.localeOf(context).languageCode)
|
||||
.name;
|
||||
final base = await exerciseProvider.fetchAndSetExerciseBase(baseId);
|
||||
final name =
|
||||
base.getExercise(Localizations.localeOf(context).languageCode).name;
|
||||
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
@@ -95,8 +88,7 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> {
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(AppLocalizations.of(context).success),
|
||||
content: Text(
|
||||
AppLocalizations.of(context).cacheWarning),
|
||||
content: Text(AppLocalizations.of(context).cacheWarning),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(name),
|
||||
|
||||
@@ -68,8 +68,7 @@ class AuthScreen extends StatelessWidget {
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 20.0),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 8.0, horizontal: 94.0),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 94.0),
|
||||
child: const Text(
|
||||
'wger',
|
||||
style: TextStyle(
|
||||
@@ -138,10 +137,8 @@ class _AuthCardState extends State<AuthCard> {
|
||||
//
|
||||
// If not, the user will not be able to register via the app
|
||||
try {
|
||||
final metadata =
|
||||
Provider.of<AuthProvider>(context, listen: false).metadata;
|
||||
if (metadata.containsKey(MANIFEST_KEY_API) &&
|
||||
metadata[MANIFEST_KEY_API] == '') {
|
||||
final metadata = Provider.of<AuthProvider>(context, listen: false).metadata;
|
||||
if (metadata.containsKey(MANIFEST_KEY_API) && metadata[MANIFEST_KEY_API] == '') {
|
||||
_canRegister = false;
|
||||
}
|
||||
} on PlatformException {
|
||||
@@ -163,10 +160,8 @@ class _AuthCardState extends State<AuthCard> {
|
||||
// Login existing user
|
||||
late Map<String, LoginActions> res;
|
||||
if (_authMode == AuthMode.Login) {
|
||||
res = await Provider.of<AuthProvider>(context, listen: false).login(
|
||||
_authData['username']!,
|
||||
_authData['password']!,
|
||||
_authData['serverUrl']!);
|
||||
res = await Provider.of<AuthProvider>(context, listen: false)
|
||||
.login(_authData['username']!, _authData['password']!, _authData['serverUrl']!);
|
||||
|
||||
// Register new user
|
||||
} else {
|
||||
@@ -234,8 +229,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
elevation: 8.0,
|
||||
child: Container(
|
||||
width: deviceSize.width * 0.9,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 15.0, vertical: 0.025 * deviceSize.height),
|
||||
padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 0.025 * deviceSize.height),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: SingleChildScrollView(
|
||||
@@ -262,9 +256,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
|
||||
return null;
|
||||
},
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.deny(RegExp(r'\s\b|\b\s'))
|
||||
],
|
||||
inputFormatters: [FilteringTextInputFormatter.deny(RegExp(r'\s\b|\b\s'))],
|
||||
onSaved: (value) {
|
||||
_authData['username'] = value!;
|
||||
},
|
||||
@@ -299,9 +291,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
labelText: AppLocalizations.of(context).password,
|
||||
prefixIcon: const Icon(Icons.password),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(isObscure
|
||||
? Icons.visibility_off
|
||||
: Icons.visibility),
|
||||
icon: Icon(isObscure ? Icons.visibility_off : Icons.visibility),
|
||||
onPressed: () {
|
||||
isObscure = !isObscure;
|
||||
updateState(() {});
|
||||
@@ -328,13 +318,10 @@ class _AuthCardState extends State<AuthCard> {
|
||||
return TextFormField(
|
||||
key: const Key('inputPassword2'),
|
||||
decoration: InputDecoration(
|
||||
labelText:
|
||||
AppLocalizations.of(context).confirmPassword,
|
||||
labelText: AppLocalizations.of(context).confirmPassword,
|
||||
prefixIcon: const Icon(Icons.password),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(confirmIsObscure
|
||||
? Icons.visibility_off
|
||||
: Icons.visibility),
|
||||
icon: Icon(confirmIsObscure ? Icons.visibility_off : Icons.visibility),
|
||||
onPressed: () {
|
||||
confirmIsObscure = !confirmIsObscure;
|
||||
updateState(() {});
|
||||
@@ -347,8 +334,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
validator: _authMode == AuthMode.Signup
|
||||
? (value) {
|
||||
if (value != _passwordController.text) {
|
||||
return AppLocalizations.of(context)
|
||||
.passwordsDontMatch;
|
||||
return AppLocalizations.of(context).passwordsDontMatch;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -366,10 +352,8 @@ class _AuthCardState extends State<AuthCard> {
|
||||
child: TextFormField(
|
||||
key: const Key('inputServer'),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context)
|
||||
.customServerUrl,
|
||||
helperText: AppLocalizations.of(context)
|
||||
.customServerHint,
|
||||
labelText: AppLocalizations.of(context).customServerUrl,
|
||||
helperText: AppLocalizations.of(context).customServerHint,
|
||||
helperMaxLines: 4),
|
||||
controller: _serverUrlController,
|
||||
validator: (value) {
|
||||
@@ -384,10 +368,8 @@ class _AuthCardState extends State<AuthCard> {
|
||||
},
|
||||
onSaved: (value) {
|
||||
// Remove any trailing slash
|
||||
if (value!.lastIndexOf('/') ==
|
||||
(value.length - 1)) {
|
||||
value =
|
||||
value.substring(0, value.lastIndexOf('/'));
|
||||
if (value!.lastIndexOf('/') == (value.length - 1)) {
|
||||
value = value.substring(0, value.lastIndexOf('/'));
|
||||
}
|
||||
_authData['serverUrl'] = value;
|
||||
},
|
||||
@@ -431,8 +413,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
child: Center(
|
||||
child: _isLoading
|
||||
? const CircularProgressIndicator(
|
||||
valueColor:
|
||||
AlwaysStoppedAnimation(Colors.white),
|
||||
valueColor: AlwaysStoppedAnimation(Colors.white),
|
||||
)
|
||||
: Text(
|
||||
_authMode == AuthMode.Login
|
||||
@@ -467,8 +448,7 @@ class _AuthCardState extends State<AuthCard> {
|
||||
text.substring(0, text.lastIndexOf('?') + 1),
|
||||
),
|
||||
Text(
|
||||
text.substring(
|
||||
text.lastIndexOf('?') + 1, text.length),
|
||||
text.substring(text.lastIndexOf('?') + 1, text.length),
|
||||
style: const TextStyle(
|
||||
//color: wgerPrimaryColor,
|
||||
fontWeight: FontWeight.w700,
|
||||
|
||||
@@ -27,14 +27,11 @@ class ExerciseDetailScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final exerciseBase =
|
||||
ModalRoute.of(context)!.settings.arguments as ExerciseBase;
|
||||
final exerciseBase = ModalRoute.of(context)!.settings.arguments as ExerciseBase;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(exerciseBase
|
||||
.getExercise(Localizations.localeOf(context).languageCode)
|
||||
.name),
|
||||
title: Text(exerciseBase.getExercise(Localizations.localeOf(context).languageCode).name),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
|
||||
@@ -21,8 +21,7 @@ class _ExercisesScreenState extends State<ExercisesScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//final size = MediaQuery.of(context).size;
|
||||
final exercisesList =
|
||||
Provider.of<ExercisesProvider>(context).filteredExerciseBases;
|
||||
final exercisesList = Provider.of<ExercisesProvider>(context).filteredExerciseBases;
|
||||
|
||||
return Scaffold(
|
||||
appBar: EmptyAppBar(AppLocalizations.of(context).exercises),
|
||||
|
||||
@@ -55,8 +55,7 @@ class FormScreen extends StatelessWidget {
|
||||
appBar: AppBar(title: Text(args.title)),
|
||||
body: args.hasListView
|
||||
? Scrollable(
|
||||
viewportBuilder:
|
||||
(BuildContext context, ViewportOffset position) => Padding(
|
||||
viewportBuilder: (BuildContext context, ViewportOffset position) => Padding(
|
||||
padding: args.padding,
|
||||
child: args.widget,
|
||||
),
|
||||
|
||||
@@ -44,8 +44,7 @@ class HomeTabsScreen extends StatefulWidget {
|
||||
_HomeTabsScreenState createState() => _HomeTabsScreenState();
|
||||
}
|
||||
|
||||
class _HomeTabsScreenState extends State<HomeTabsScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
class _HomeTabsScreenState extends State<HomeTabsScreen> with SingleTickerProviderStateMixin {
|
||||
late Future<void> _initialData;
|
||||
int _selectedIndex = 0;
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ class MeasurementEntriesScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final categoryId = ModalRoute.of(context)!.settings.arguments as int;
|
||||
final category =
|
||||
Provider.of<MeasurementProvider>(context).findCategoryById(categoryId);
|
||||
final category = Provider.of<MeasurementProvider>(context).findCategoryById(categoryId);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -63,26 +62,21 @@ class MeasurementEntriesScreen extends StatelessWidget {
|
||||
builder: (BuildContext contextDialog) {
|
||||
return AlertDialog(
|
||||
content: Text(
|
||||
AppLocalizations.of(context)
|
||||
.confirmDelete(category.name),
|
||||
AppLocalizations.of(context).confirmDelete(category.name),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(MaterialLocalizations.of(context)
|
||||
.cancelButtonLabel),
|
||||
onPressed: () =>
|
||||
Navigator.of(contextDialog).pop(),
|
||||
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
|
||||
onPressed: () => Navigator.of(contextDialog).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
AppLocalizations.of(context).delete,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error),
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
onPressed: () {
|
||||
// Confirmed, delete the workout
|
||||
Provider.of<MeasurementProvider>(context,
|
||||
listen: false)
|
||||
Provider.of<MeasurementProvider>(context, listen: false)
|
||||
.deleteCategory(category.id!);
|
||||
|
||||
// Close the popup
|
||||
@@ -92,8 +86,7 @@ class MeasurementEntriesScreen extends StatelessWidget {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context)
|
||||
.successfullyDeleted,
|
||||
AppLocalizations.of(context).successfullyDeleted,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -39,13 +39,11 @@ class NutritionalDiaryScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final args =
|
||||
ModalRoute.of(context)!.settings.arguments as NutritionalDiaryArguments;
|
||||
final args = ModalRoute.of(context)!.settings.arguments as NutritionalDiaryArguments;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(DateFormat.yMd(Localizations.localeOf(context).languageCode)
|
||||
.format(args.date)),
|
||||
title: Text(DateFormat.yMd(Localizations.localeOf(context).languageCode).format(args.date)),
|
||||
),
|
||||
body: Consumer<NutritionPlansProvider>(
|
||||
builder: (context, nutritionProvider, child) => SingleChildScrollView(
|
||||
|
||||
@@ -35,15 +35,13 @@ class NutritionalPlanScreen extends StatelessWidget {
|
||||
static const routeName = '/nutritional-plan-detail';
|
||||
|
||||
Future<NutritionalPlan> _loadFullPlan(BuildContext context, int planId) {
|
||||
return Provider.of<NutritionPlansProvider>(context, listen: false)
|
||||
.fetchAndSetPlanFull(planId);
|
||||
return Provider.of<NutritionPlansProvider>(context, listen: false).fetchAndSetPlanFull(planId);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const appBarForeground = Colors.white;
|
||||
final nutritionalPlan =
|
||||
ModalRoute.of(context)!.settings.arguments as NutritionalPlan;
|
||||
final nutritionalPlan = ModalRoute.of(context)!.settings.arguments as NutritionalPlan;
|
||||
|
||||
return Scaffold(
|
||||
//appBar: getAppBar(nutritionalPlan),
|
||||
@@ -111,14 +109,10 @@ class NutritionalPlanScreen extends StatelessWidget {
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
title: Text(
|
||||
nutritionalPlan.getLabel(context),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleLarge
|
||||
?.copyWith(color: appBarForeground),
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(color: appBarForeground),
|
||||
),
|
||||
background: const Image(
|
||||
image: AssetImage(
|
||||
'assets/images/backgrounds/nutritional_plans.jpg'),
|
||||
image: AssetImage('assets/images/backgrounds/nutritional_plans.jpg'),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -49,8 +49,7 @@ class NutritionScreen extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
body: Consumer<NutritionPlansProvider>(
|
||||
builder: (context, nutritionProvider, child) =>
|
||||
NutritionalPlansList(nutritionProvider),
|
||||
builder: (context, nutritionProvider, child) => NutritionalPlansList(nutritionProvider),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,8 +71,7 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const appBarForeground = Colors.white;
|
||||
final workoutPlan =
|
||||
ModalRoute.of(context)!.settings.arguments as WorkoutPlan;
|
||||
final workoutPlan = ModalRoute.of(context)!.settings.arguments as WorkoutPlan;
|
||||
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
@@ -85,14 +84,10 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
title: Text(
|
||||
workoutPlan.name,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleLarge
|
||||
?.copyWith(color: appBarForeground),
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(color: appBarForeground),
|
||||
),
|
||||
background: const Image(
|
||||
image:
|
||||
AssetImage('assets/images/backgrounds/workout_plans.jpg'),
|
||||
image: AssetImage('assets/images/backgrounds/workout_plans.jpg'),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
@@ -138,8 +133,7 @@ class _WorkoutPlanScreenState extends State<WorkoutPlanScreen> {
|
||||
),
|
||||
FutureBuilder(
|
||||
future: _loadFullWorkout(context, workoutPlan.id!),
|
||||
builder: (context, AsyncSnapshot<WorkoutPlan> snapshot) =>
|
||||
SliverList(
|
||||
builder: (context, AsyncSnapshot<WorkoutPlan> snapshot) => SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
[
|
||||
if (snapshot.connectionState == ConnectionState.waiting)
|
||||
|
||||
@@ -50,8 +50,7 @@ class WorkoutPlansScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
body: Consumer<WorkoutPlansProvider>(
|
||||
builder: (context, workoutProvider, child) =>
|
||||
WorkoutPlansList(workoutProvider),
|
||||
builder: (context, workoutProvider, child) => WorkoutPlansList(workoutProvider),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,12 +44,8 @@ const FlexSubThemesData wgerSubThemeData = FlexSubThemesData(
|
||||
);
|
||||
|
||||
const String wgerDisplayFont = 'RobotoCondensed';
|
||||
const List<FontVariation> displayFontBoldWeight = <FontVariation>[
|
||||
FontVariation('wght', 600)
|
||||
];
|
||||
const List<FontVariation> displayFontHeavyWeight = <FontVariation>[
|
||||
FontVariation('wght', 800)
|
||||
];
|
||||
const List<FontVariation> displayFontBoldWeight = <FontVariation>[FontVariation('wght', 600)];
|
||||
const List<FontVariation> displayFontHeavyWeight = <FontVariation>[FontVariation('wght', 800)];
|
||||
|
||||
// Make a light ColorScheme from the seeds.
|
||||
final ColorScheme schemeLight = SeedColorScheme.fromSeeds(
|
||||
|
||||
@@ -17,8 +17,7 @@ class AddExerciseDropdownButton extends StatefulWidget {
|
||||
final FormFieldSetter<String?>? onSaved;
|
||||
|
||||
@override
|
||||
_AddExerciseDropdownButtonState createState() =>
|
||||
_AddExerciseDropdownButtonState();
|
||||
_AddExerciseDropdownButtonState createState() => _AddExerciseDropdownButtonState();
|
||||
}
|
||||
|
||||
class _AddExerciseDropdownButtonState extends State<AddExerciseDropdownButton> {
|
||||
@@ -40,8 +39,7 @@ class _AddExerciseDropdownButtonState extends State<AddExerciseDropdownButton> {
|
||||
},
|
||||
value: _selectedItem,
|
||||
decoration: InputDecoration(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
),
|
||||
|
||||
@@ -20,12 +20,10 @@ class AddExerciseMultiselectButton<T> extends StatefulWidget {
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_AddExerciseMultiselectButtonState createState() =>
|
||||
_AddExerciseMultiselectButtonState<T>();
|
||||
_AddExerciseMultiselectButtonState createState() => _AddExerciseMultiselectButtonState<T>();
|
||||
}
|
||||
|
||||
class _AddExerciseMultiselectButtonState<T>
|
||||
extends State<AddExerciseMultiselectButton> {
|
||||
class _AddExerciseMultiselectButtonState<T> extends State<AddExerciseMultiselectButton> {
|
||||
List<T> _selectedItems = [];
|
||||
|
||||
@override
|
||||
@@ -35,9 +33,8 @@ class _AddExerciseMultiselectButtonState<T>
|
||||
child: MultiSelectDialogField(
|
||||
initialValue: widget.initialItems,
|
||||
onSaved: widget.onSaved,
|
||||
items: widget.items
|
||||
.map((item) => MultiSelectItem<T>(item, widget.displayName(item)))
|
||||
.toList(),
|
||||
items:
|
||||
widget.items.map((item) => MultiSelectItem<T>(item, widget.displayName(item))).toList(),
|
||||
onConfirm: (value) {
|
||||
setState(() {
|
||||
_selectedItems = value.cast<T>();
|
||||
|
||||
@@ -28,15 +28,13 @@ class AddExerciseTextArea extends StatelessWidget {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextFormField(
|
||||
keyboardType:
|
||||
isMultiline ? TextInputType.multiline : TextInputType.text,
|
||||
keyboardType: isMultiline ? TextInputType.multiline : TextInputType.text,
|
||||
maxLines: isMultiline ? null : DEFAULT_LINES,
|
||||
minLines: isMultiline ? MULTILINE_MIN_LINES : DEFAULT_LINES,
|
||||
validator: validator,
|
||||
onSaved: onSaved,
|
||||
decoration: InputDecoration(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
),
|
||||
|
||||
@@ -17,8 +17,7 @@ mixin ExerciseImagePickerMixin {
|
||||
|
||||
bool _validateFileType(File file) {
|
||||
final extension = file.path.split('.').last;
|
||||
return validFileExtensions
|
||||
.any((element) => extension == element.toLowerCase());
|
||||
return validFileExtensions.any((element) => extension == element.toLowerCase());
|
||||
}
|
||||
|
||||
void pickImages(BuildContext context, {bool pickFromCamera = false}) async {
|
||||
@@ -26,8 +25,7 @@ mixin ExerciseImagePickerMixin {
|
||||
|
||||
List<XFile>? images;
|
||||
if (pickFromCamera) {
|
||||
final pictureTaken =
|
||||
await imagePicker.pickImage(source: ImageSource.camera);
|
||||
final pictureTaken = await imagePicker.pickImage(source: ImageSource.camera);
|
||||
images = pictureTaken == null ? null : [pictureTaken];
|
||||
} else {
|
||||
images = await imagePicker.pickMultiImage();
|
||||
@@ -52,8 +50,7 @@ mixin ExerciseImagePickerMixin {
|
||||
|
||||
if (!isFileValid) {
|
||||
if (context.mounted) {
|
||||
showDialog(
|
||||
context: context, builder: (context) => Text(errorMessage));
|
||||
showDialog(context: context, builder: (context) => Text(errorMessage));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ import 'package:provider/provider.dart';
|
||||
import '../../providers/add_exercise.dart';
|
||||
import 'mixins/image_picker_mixin.dart';
|
||||
|
||||
class PreviewExerciseImages extends StatelessWidget
|
||||
with ExerciseImagePickerMixin {
|
||||
class PreviewExerciseImages extends StatelessWidget with ExerciseImagePickerMixin {
|
||||
PreviewExerciseImages({
|
||||
Key? key,
|
||||
required this.selectedImages,
|
||||
@@ -36,14 +35,12 @@ class PreviewExerciseImages extends StatelessWidget
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(20)),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||
),
|
||||
child: IconButton(
|
||||
iconSize: 20,
|
||||
onPressed: () => context
|
||||
.read<AddExerciseProvider>()
|
||||
.removeExercise(file.path),
|
||||
onPressed: () =>
|
||||
context.read<AddExerciseProvider>().removeExercise(file.path),
|
||||
color: Colors.white,
|
||||
icon: const Icon(Icons.delete),
|
||||
),
|
||||
|
||||
@@ -35,16 +35,15 @@ class Step1Basics extends StatelessWidget {
|
||||
helperText: AppLocalizations.of(context).baseNameEnglish,
|
||||
isRequired: true,
|
||||
validator: (name) => validateName(name, context),
|
||||
onSaved: (String? name) =>
|
||||
addExerciseProvider.exerciseNameEn = name!,
|
||||
onSaved: (String? name) => addExerciseProvider.exerciseNameEn = name!,
|
||||
),
|
||||
AddExerciseTextArea(
|
||||
onChange: (value) => {},
|
||||
title: AppLocalizations.of(context).alternativeNames,
|
||||
isMultiline: true,
|
||||
helperText: AppLocalizations.of(context).oneNamePerLine,
|
||||
onSaved: (String? alternateName) => addExerciseProvider
|
||||
.alternateNamesEn = alternateName!.split('\n'),
|
||||
onSaved: (String? alternateName) =>
|
||||
addExerciseProvider.alternateNamesEn = alternateName!.split('\n'),
|
||||
),
|
||||
ExerciseCategoryInputWidget<ExerciseCategory>(
|
||||
key: const Key('category-dropdown'),
|
||||
@@ -58,8 +57,7 @@ class Step1Basics extends StatelessWidget {
|
||||
return AppLocalizations.of(context).selectEntry;
|
||||
}
|
||||
},
|
||||
displayName: (ExerciseCategory c) =>
|
||||
getTranslation(c.name, context),
|
||||
displayName: (ExerciseCategory c) => getTranslation(c.name, context),
|
||||
),
|
||||
AddExerciseMultiselectButton<Equipment>(
|
||||
key: const Key('equipment-multiselect'),
|
||||
@@ -86,10 +84,7 @@ class Step1Basics extends StatelessWidget {
|
||||
addExerciseProvider.primaryMuscles = muscles.cast<Muscle>();
|
||||
},
|
||||
displayName: (Muscle e) =>
|
||||
e.name +
|
||||
(e.nameEn.isNotEmpty
|
||||
? '\n(${getTranslation(e.nameEn, context)})'
|
||||
: ''),
|
||||
e.name + (e.nameEn.isNotEmpty ? '\n(${getTranslation(e.nameEn, context)})' : ''),
|
||||
),
|
||||
AddExerciseMultiselectButton<Muscle>(
|
||||
key: const Key('secondary-muscles-multiselect'),
|
||||
@@ -103,10 +98,7 @@ class Step1Basics extends StatelessWidget {
|
||||
addExerciseProvider.secondaryMuscles = muscles.cast<Muscle>();
|
||||
},
|
||||
displayName: (Muscle e) =>
|
||||
e.name +
|
||||
(e.nameEn.isNotEmpty
|
||||
? '\n(${getTranslation(e.nameEn, context)})'
|
||||
: ''),
|
||||
e.name + (e.nameEn.isNotEmpty ? '\n(${getTranslation(e.nameEn, context)})' : ''),
|
||||
),
|
||||
Consumer<AddExerciseProvider>(
|
||||
builder: (context, value, child) => MuscleRowWidget(
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user