Skip to content
20 changes: 10 additions & 10 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ linter:
# These rules are documented on and in the same order as
# the Dart Lint rules page to make maintenance easier
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
always_declare_return_types: false # definitely to be changed
always_declare_return_types: true
always_put_control_body_on_new_line: true
always_require_non_null_named_parameters: true
always_specify_types: false #to be changed
always_specify_types: false # decided against using it for now
annotate_overrides: true
avoid_bool_literals_in_conditional_expressions: true
avoid_classes_with_only_static_members: true
Expand All @@ -50,17 +50,17 @@ linter:
avoid_types_as_parameter_names: true
avoid_unnecessary_containers: true
avoid_unused_constructor_parameters: true
avoid_void_async: false # to be changed
avoid_void_async: false
await_only_futures: true
camel_case_extensions: true
camel_case_types: false # maybe to be changed
camel_case_types: false
cancel_subscriptions: true
cast_nullable_to_non_nullable: false # to be changed
constant_identifier_names: false
control_flow_in_finally: true
deprecated_consistency: true
directives_ordering: true
empty_catches: false # to be changed
empty_catches: false
empty_constructor_bodies: true
empty_statements: true
exhaustive_cases: true
Expand All @@ -72,7 +72,7 @@ linter:
leading_newlines_in_multiline_strings: true
library_names: true
library_prefixes: true
library_private_types_in_public_api: false # to be checked
library_private_types_in_public_api: false
list_remove_unrelated_type: true
missing_whitespace_between_adjacent_strings: false
no_adjacent_strings_in_list: true
Expand All @@ -90,7 +90,7 @@ linter:
prefer_asserts_in_initializer_lists: true
prefer_collection_literals: true
prefer_conditional_assignment: true
prefer_const_constructors: false # definitely to be changed
prefer_const_constructors: true
prefer_const_constructors_in_immutables: true
prefer_const_declarations: true
prefer_const_literals_to_create_immutables: true
Expand All @@ -115,7 +115,7 @@ linter:
prefer_null_aware_operators: true
prefer_single_quotes: true
prefer_spread_collections: true
prefer_typing_uninitialized_variables: false # to be changed
prefer_typing_uninitialized_variables: true
prefer_void_to_null: true
provide_deprecation_message: true
recursive_getters: true
Expand All @@ -127,7 +127,7 @@ linter:
throw_in_finally: true
tighten_type_of_initializing_formals: true
type_init_formals: true
unnecessary_await_in_return: false # to be changed
unnecessary_await_in_return: true
unnecessary_brace_in_string_interps: true
unnecessary_const: true
unnecessary_getters_setters: true
Expand All @@ -153,5 +153,5 @@ linter:
use_rethrow_when_possible: true
use_test_throws_matchers: true
valid_regexps: true
void_checks: true
void_checks: false

2 changes: 1 addition & 1 deletion lib/helpers/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ String? timeToString(TimeOfDay? time) {
if (time == null) {
return null;
}
return DefaultMaterialLocalizations().formatTimeOfDay(time, alwaysUse24HourFormat: true);
return const DefaultMaterialLocalizations().formatTimeOfDay(time, alwaysUse24HourFormat: true);
}
4 changes: 2 additions & 2 deletions lib/helpers/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext cont
final List<Widget> errorList = [];
for (final key in exception.errors!.keys) {
// Error headers
errorList.add(Text(key, style: TextStyle(fontWeight: FontWeight.bold)));
errorList.add(Text(key, style: const TextStyle(fontWeight: FontWeight.bold)));

// Error messages
if (exception.errors![key] is String) {
Expand All @@ -66,7 +66,7 @@ void showHttpExceptionErrorDialog(WgerHttpException exception, BuildContext cont
errorList.add(Text(value));
}
}
errorList.add(SizedBox(height: 8));
errorList.add(const SizedBox(height: 8));
}

showDialog(
Expand Down
1 change: 1 addition & 0 deletions lib/models/measurements/measurement_category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ class MeasurementCategory extends Equatable {
List<Object?> get props => [id, name, unit, entries];

// Helper function which makes the entries list of the toJson output null, as it isn't needed
//ignore: always_declare_return_types
static _nullValue(_) => null;
}
11 changes: 9 additions & 2 deletions lib/models/nutrition/nutritrional_values.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import 'dart:ui';

class NutritionalValues {
double energy = 0;
double protein = 0;
Expand Down Expand Up @@ -44,7 +46,7 @@ class NutritionalValues {
return energy * 4.184;
}

add(NutritionalValues data) {
void add(NutritionalValues data) {
energy += data.energy;
protein += data.protein;
carbohydrates += data.carbohydrates;
Expand All @@ -69,7 +71,7 @@ class NutritionalValues {
}

@override
//ignore: hash_and_equals
//ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(other) {
return other is NutritionalValues &&
energy == other.energy &&
Expand All @@ -86,6 +88,11 @@ class NutritionalValues {
String toString() {
return 'e: $energy, p: $protein, c: $carbohydrates, cS: $carbohydratesSugar, f: $fat, fS: $fatSaturated, fi: $fibres, s: $sodium';
}

@override
//ignore: avoid_equals_and_hash_code_on_mutable_classes
int get hashCode => hashValues(
energy, protein, carbohydrates, carbohydratesSugar, fat, fatSaturated, fibres, sodium);
}

class BaseNutritionalValues {
Expand Down
2 changes: 2 additions & 0 deletions lib/models/workouts/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class Log {
/// Two logs are considered equal if their content is equal. This is used e.g.
/// in lists where we want to have unique values
@override
//ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(o) {
return o is Log &&
exerciseId == o.exerciseId &&
Expand All @@ -131,6 +132,7 @@ class Log {
}

@override
//ignore: avoid_equals_and_hash_code_on_mutable_classes
int get hashCode => hashValues(exerciseId, weight, weightUnitId, reps, repetitionUnitId, rir);

//@override
Expand Down
2 changes: 1 addition & 1 deletion lib/models/workouts/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class WorkoutSession {
factory WorkoutSession.fromJson(Map<String, dynamic> json) => _$WorkoutSessionFromJson(json);
Map<String, dynamic> toJson() => _$WorkoutSessionToJson(this);

get impressionAsString {
String? get impressionAsString {
return IMPRESSION_MAP[impression];
}
}
2 changes: 1 addition & 1 deletion lib/providers/body_weight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BodyWeightProvider extends WgerBaseProvider with ChangeNotifier {
}

/// Clears all lists
clear() {
void clear() {
_entries = [];
}

Expand Down
28 changes: 14 additions & 14 deletions lib/providers/exercises.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {

static const daysToCache = 7;

static const _exerciseInfoUrlPath = 'exerciseinfo';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick question, why did you remove the underscore? Since this isn't a library, we know that we'll be not misusing methods or properties but if it's clear they are only meant for "internal" consumption, why not mark them as such?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I myself was confused why the analyzer complained about it. But it turns out that static variables cannot be private. (Couldn't find anything online about it but a short dartPad test proved this thesis). We can of course remove the static modifier instead of the _, but at that time I haven't thought about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh. I guess it kinda makes sense.

And in our case, in the end it doesn't really matter, they are constants anyway

static const _exerciseSearchPath = 'exercise/search';
static const exerciseInfoUrlPath = 'exerciseinfo';
static const exerciseSearchPath = 'exercise/search';

static const _exerciseCommentUrlPath = 'exercisecomment';
static const _exerciseImagesUrlPath = 'exerciseimage';
static const _categoriesUrlPath = 'exercisecategory';
static const _musclesUrlPath = 'muscle';
static const _equipmentUrlPath = 'equipment';
static const exerciseCommentUrlPath = 'exercisecomment';
static const exerciseImagesUrlPath = 'exerciseimage';
static const categoriesUrlPath = 'exercisecategory';
static const musclesUrlPath = 'muscle';
static const equipmentUrlPath = 'equipment';

final List<Exercise> _exercises;
final List<ExerciseCategory> _categories = [];
Expand All @@ -65,7 +65,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
}

Future<void> fetchAndSetCategories() async {
final response = await client.get(makeUrl(_categoriesUrlPath));
final response = await client.get(makeUrl(categoriesUrlPath));
final categories = json.decode(response.body) as Map<String, dynamic>;
try {
for (final category in categories['results']) {
Expand All @@ -77,7 +77,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
}

Future<void> fetchAndSetMuscles() async {
final response = await client.get(makeUrl(_musclesUrlPath));
final response = await client.get(makeUrl(musclesUrlPath));
final muscles = json.decode(response.body) as Map<String, dynamic>;
try {
for (final muscle in muscles['results']) {
Expand All @@ -89,7 +89,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
}

Future<void> fetchAndSetEquipment() async {
final response = await client.get(makeUrl(_equipmentUrlPath));
final response = await client.get(makeUrl(equipmentUrlPath));
final equipments = json.decode(response.body) as Map<String, dynamic>;
try {
for (final equipment in equipments['results']) {
Expand All @@ -111,7 +111,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
} on StateError {
// Get exercise from the server and save to cache

final data = await fetch(makeUrl(_exerciseInfoUrlPath, id: exerciseId));
final data = await fetch(makeUrl(exerciseInfoUrlPath, id: exerciseId));
final exercise = Exercise.fromJson(data);
_exercises.add(exercise);
final prefs = await SharedPreferences.getInstance();
Expand Down Expand Up @@ -145,7 +145,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {

final response = await client.get(
makeUrl(
_exerciseInfoUrlPath,
exerciseInfoUrlPath,
query: {'limit': '1000'},
),
headers: {
Expand All @@ -160,7 +160,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
// Save the result to the cache
final exerciseData = {
'date': DateTime.now().toIso8601String(),
'expiresIn': DateTime.now().add(Duration(days: daysToCache)).toIso8601String(),
'expiresIn': DateTime.now().add(const Duration(days: daysToCache)).toIso8601String(),
'exercises': _exercises.map((e) => e.toJson()).toList(),
'equipment': _equipment.map((e) => e.toJson()).toList(),
'categories': _categories.map((e) => e.toJson()).toList(),
Expand Down Expand Up @@ -188,7 +188,7 @@ class ExercisesProvider extends WgerBaseProvider with ChangeNotifier {
// Send the request
final response = await client.get(
makeUrl(
_exerciseSearchPath,
exerciseSearchPath,
query: {'term': name, 'language': languageCode},
),
headers: <String, String>{
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GalleryProvider extends WgerBaseProvider with ChangeNotifier {
super(auth, client);

/// Clears all lists
clear() {
void clear() {
images = [];
}

Expand Down
4 changes: 2 additions & 2 deletions lib/providers/nutrition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
}

/// Clears all lists
clear() {
void clear() {
_plans = [];
_ingredients = [];
}
Expand Down Expand Up @@ -292,7 +292,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
// Initialise an empty cache
final ingredientData = {
'date': DateTime.now().toIso8601String(),
'expiresIn': DateTime.now().add(Duration(days: DAYS_TO_CACHE)).toIso8601String(),
'expiresIn': DateTime.now().add(const Duration(days: DAYS_TO_CACHE)).toIso8601String(),
'ingredients': []
};
prefs.setString('ingredientData', json.encode(ingredientData));
Expand Down
4 changes: 2 additions & 2 deletions lib/providers/workout_plans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
}

/// Clears all lists
clear() {
void clear() {
_currentPlan = null;
_workoutPlans = [];
_weightUnits = [];
Expand Down Expand Up @@ -353,7 +353,7 @@ class WorkoutPlansProvider extends WgerBaseProvider with ChangeNotifier {
// Save the result to the cache
final exerciseData = {
'date': DateTime.now().toIso8601String(),
'expiresIn': DateTime.now().add(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(),
};
Expand Down
Loading