Browse Source

switching to new linter package flutter_lints and fix the first warnings

upgrade-2021-project
Stefan Haslinger 1 year ago
parent
commit
fbd7d1814b
  1. 2
      .flutter-plugins-dependencies
  2. 218
      analysis_options.yaml
  3. 2
      changelog.txt
  4. 6
      lib/actions/parse_activity.dart
  5. 18
      lib/models/activity.dart
  6. 4
      lib/models/activity_list.dart
  7. 7
      lib/models/activity_tagging.dart
  8. 3
      lib/models/athlete.dart
  9. 3
      lib/models/critical_power.dart
  10. 6
      lib/models/heart_rate_zone.dart
  11. 5
      lib/models/heart_rate_zone_schema.dart
  12. 30
      lib/models/interval.dart
  13. 4
      lib/models/interval_tagging.dart
  14. 30
      lib/models/lap.dart
  15. 4
      lib/models/lap_tagging.dart
  16. 6
      lib/models/power_zone.dart
  17. 5
      lib/models/power_zone_schema.dart
  18. 11
      lib/models/record_list.dart
  19. 12
      lib/models/tag_group.dart
  20. 5
      lib/models/weight.dart
  21. 5
      lib/screens/add_filter_screen.dart
  22. 4
      lib/screens/dashboard.dart
  23. 3
      lib/screens/select_interval_screen.dart
  24. 6
      lib/screens/show_activity_screen.dart
  25. 8
      lib/screens/strava_get_user.dart
  26. 3
      lib/utils/db.dart
  27. 4
      lib/utils/graph_utils.dart
  28. 30
      lib/utils/my_bar_chart.dart
  29. 8
      lib/utils/my_color.dart
  30. 9
      lib/utils/my_line_chart.dart
  31. 5
      lib/widgets/activities_feed_widget.dart
  32. 6
      lib/widgets/activity_widgets/activity_bargraph_widget.dart
  33. 2
      lib/widgets/activity_widgets/activity_ftp_widget.dart
  34. 5
      lib/widgets/activity_widgets/activity_heart_rate_widget.dart
  35. 5
      lib/widgets/activity_widgets/activity_power_widget.dart
  36. 5
      lib/widgets/activity_widgets/activity_tag_widget.dart
  37. 6
      lib/widgets/athlete_widgets/athlete_current_filter_widget.dart
  38. 3
      lib/widgets/athlete_widgets/athlete_distance_widget.dart
  39. 3
      lib/widgets/athlete_widgets/athlete_moving_time_widget.dart
  40. 11
      lib/widgets/athlete_widgets/athlete_settings_widget.dart
  41. 5
      lib/widgets/athlete_widgets/athlete_tag_group_widget.dart
  42. 5
      lib/widgets/athlete_widgets/edit_standalone_athlete_widget.dart
  43. 5
      lib/widgets/athlete_widgets/edit_strava_athlete_widget.dart
  44. 3
      lib/widgets/charts/activity_charts/activity_altitude_chart.dart
  45. 3
      lib/widgets/charts/activity_charts/activity_ecor_chart.dart
  46. 3
      lib/widgets/charts/activity_charts/activity_form_power_chart.dart
  47. 3
      lib/widgets/charts/activity_charts/activity_ground_time_chart.dart
  48. 3
      lib/widgets/charts/activity_charts/activity_heart_rate_chart.dart
  49. 9
      lib/widgets/charts/activity_charts/activity_intervals_chart.dart
  50. 3
      lib/widgets/charts/activity_charts/activity_leg_spring_stiffness_chart.dart
  51. 3
      lib/widgets/charts/activity_charts/activity_pace_chart.dart
  52. 3
      lib/widgets/charts/activity_charts/activity_power_chart.dart
  53. 3
      lib/widgets/charts/activity_charts/activity_power_per_heart_rate_chart.dart
  54. 3
      lib/widgets/charts/activity_charts/activity_power_ratio_chart.dart
  55. 3
      lib/widgets/charts/activity_charts/activity_speed_chart.dart
  56. 3
      lib/widgets/charts/activity_charts/activity_speed_per_heart_rate_chart.dart
  57. 3
      lib/widgets/charts/activity_charts/activity_stride_ratio_chart.dart
  58. 3
      lib/widgets/charts/activity_charts/activity_stryd_cadence_chart.dart
  59. 3
      lib/widgets/charts/activity_charts/activity_vertical_oscillation_chart.dart
  60. 5
      lib/widgets/interval_widgets/interval_heart_rate_widget.dart
  61. 7
      lib/widgets/interval_widgets/interval_power_widget.dart
  62. 5
      lib/widgets/interval_widgets/interval_tag_widget.dart
  63. 5
      lib/widgets/lap_widgets/lap_heart_rate_widget.dart
  64. 5
      lib/widgets/lap_widgets/lap_power_widget.dart
  65. 5
      lib/widgets/lap_widgets/lap_tag_widget.dart
  66. 3
      lib/widgets/laps_list_widget.dart
  67. 21
      pubspec.lock
  68. 1
      pubspec.yaml

2
.flutter-plugins-dependencies

File diff suppressed because one or more lines are too long

218
analysis_options.yaml

@ -1,199 +1,29 @@
# Specify analysis options.
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# Until there are meta linter rules, each desired lint must be explicitly enabled.
# See: https://github.com/dart-lang/linter/issues/288
#
# For a list of lints, see: http://dart-lang.github.io/linter/lints/
# See the configuration guide for more
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
#
# There are other similar analysis options files in the flutter repos,
# which should be kept in sync with this file:
#
# - analysis_options.yaml (this file)
# - packages/flutter/lib/analysis_options_user.yaml
# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
#
# This file contains the analysis options used by Flutter tools, such as IntelliJ,
# Android Studio, and the `flutter analyze` command.
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
errors:
missing_required_param: warning
missing_return: warning
# Ignore analyzer hints for updating pubspecs when using Future or
# Stream and not importing dart:async
# Please see https://github.com/flutter/flutter/pull/24528 for details.
sdk_version_async_exported_from_core: ignore
exclude:
- "lib/i18n/messages_*.dart"
# HAS:20200527 This is generated code, so I cannot influence it
- "lib/model/model.dart"
- "lib/model/model.g.dart"
# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml
linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
- always_declare_return_types
- always_put_control_body_on_new_line
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
- always_require_non_null_named_parameters
- always_specify_types
- annotate_overrides
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
# - avoid_as # required for implicit-casts: true
- avoid_bool_literals_in_conditional_expressions
# - avoid_catches_without_on_clauses # we do this commonly
# - avoid_catching_errors # we do this commonly
- avoid_classes_with_only_static_members
# - avoid_double_and_int_checks # only useful when targeting JS runtime
- avoid_empty_else
- avoid_equals_and_hash_code_on_mutable_classes
- avoid_field_initializers_in_const_classes
- avoid_function_literals_in_foreach_calls
# - avoid_implementing_value_types # not yet tested
- avoid_init_to_null
# - avoid_js_rounded_ints # only useful when targeting JS runtime
- avoid_null_checks_in_equality_operators
# - avoid_positional_boolean_parameters # not yet tested
# - avoid_print # not yet tested
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
# - avoid_redundant_argument_values # not yet tested
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
# - avoid_returning_null # there are plenty of valid reasons to return null
# - avoid_returning_null_for_future # not yet tested
- avoid_returning_null_for_void
# - avoid_returning_this # there are plenty of valid reasons to return this
# - avoid_setters_without_getters # not yet tested
# - avoid_shadowing_type_parameters # not yet tested
- avoid_single_cascade_in_expression_statements
- avoid_slow_async_io
- avoid_types_as_parameter_names
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
# - avoid_unnecessary_containers # not yet tested
- avoid_unused_constructor_parameters
- avoid_void_async
# - avoid_web_libraries_in_flutter # not yet tested
- await_only_futures
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
# - cascade_invocations # not yet tested
# - close_sinks # not reliable enough
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
- control_flow_in_finally
# - curly_braces_in_flow_control_structures # not yet tested
# - diagnostic_describe_all_properties # not yet tested
- directives_ordering
- empty_catches
- empty_constructor_bodies
- empty_statements
# - file_names # not yet tested
- flutter_style_todos
- hash_and_equals
- implementation_imports
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
- iterable_contains_unrelated_type
# - join_return_with_assignment # not yet tested
- library_names
- library_prefixes
# - lines_longer_than_80_chars # not yet tested
- list_remove_unrelated_type
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
# - missing_whitespace_between_adjacent_strings # not yet tested
- no_adjacent_strings_in_list
- no_duplicate_case_values
# - no_logic_in_create_state # not yet tested
# - no_runtimeType_toString # not yet tested
- non_constant_identifier_names
# - null_closures # not yet tested
# - omit_local_variable_types # opposite of always_specify_types
# - one_member_abstracts # too many false positives
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
# - parameter_assignments # we do this commonly
- prefer_adjacent_string_concatenation
- prefer_asserts_in_initializer_lists
# - prefer_asserts_with_message # not yet tested
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
# - prefer_constructors_over_static_methods # not yet tested
- prefer_contains
# - prefer_double_quotes # opposite of prefer_single_quotes
- prefer_equal_for_default_values
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_for_elements_to_map_fromIterable
- prefer_foreach
# - prefer_function_declarations_over_variables # not yet tested
- prefer_generic_function_type_aliases
- prefer_if_elements_to_conditional_expressions
- prefer_if_null_operators
- prefer_initializing_formals
- prefer_inlined_adds
# - prefer_int_literals # not yet tested
# - prefer_interpolation_to_compose_strings # not yet tested
- prefer_is_empty
- prefer_is_not_empty
- prefer_is_not_operator
- prefer_iterable_whereType
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
# - prefer_relative_imports # not yet tested
- prefer_single_quotes
- prefer_spread_collections
- prefer_typing_uninitialized_variables
- prefer_void_to_null
# - provide_deprecation_message # not yet tested
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
- recursive_getters
- slash_for_doc_comments
# - sort_child_properties_last # not yet tested
- sort_constructors_first
- sort_pub_dependencies
- sort_unnamed_constructors_first
- test_types_in_equals
- throw_in_finally
# - type_annotate_public_apis # subset of always_specify_types
- type_init_formals
# - unawaited_futures # too many false positives
# - unnecessary_await_in_return # not yet tested
- unnecessary_brace_in_string_interps
- unnecessary_const
# - unnecessary_final # conflicts with prefer_final_locals
- unnecessary_getters_setters
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_in_if_null_operators
- unnecessary_overrides
- unnecessary_parenthesis
- unnecessary_statements
- unnecessary_string_interpolations
- unnecessary_this
- unrelated_type_equality_checks
# - unsafe_html # not yet tested
- use_full_hex_values_for_flutter_colors
# - use_function_type_syntax_for_parameters # not yet tested
# - use_key_in_widget_constructors # not yet tested
- use_rethrow_when_possible
# - use_setters_to_change_properties # not yet tested
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
- valid_regexps
- void_checks
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

2
changelog.txt

@ -576,7 +576,7 @@
* `2019-09-19 16:58` [6480ce2](https://gitlab.informatom.com/3-schweinehunde/encrateia/-/commit/6480ce2) - refactoring
* `2019-09-19 16:46` [3a1432a](https://gitlab.informatom.com/3-schweinehunde/encrateia/-/commit/3a1432a) - switch to sqfentity
* `2019-09-18 16:51` [0825952](https://gitlab.informatom.com/3-schweinehunde/encrateia/-/commit/0825952) - create table athletes, if it does not exist
* `2019-09-18 14:50` [49f873a](https://gitlab.informatom.com/3-schweinehunde/encrateia/-/commit/49f873a) - persisting athlete, todo: create database and table
* `2019-09-18 14:50` [49f873a](https://gitlab.informatom.com/3-schweinehunde/encrateia/-/commit/49f873a) - persisting athlete, create database and table
* `2019-08-18 15:11` [6e6b0f5](https://gitlab.informatom.com/3-schweinehunde/encrateia/-/commit/6e6b0f5) - lots of small reformattings and reorganisations
* `2019-08-17 20:21` [3c79a87](https://gitlab.informatom.com/3-schweinehunde/encrateia/-/commit/3c79a87) - fix all linting issues
* `2019-08-17 11:51` [fe55e2a](https://gitlab.informatom.com/3-schweinehunde/encrateia/-/commit/fe55e2a) - store data in scoped model

6
lib/actions/parse_activity.dart

@ -23,9 +23,9 @@ Future<void> parseActivity({
try {
percentageStream = activity.parse(athlete: athlete);
await for (final int value in percentageStream) {
if (value == -2)
await flushbar?.dismiss();
else if (value == -1) {
if (value == -2) {
var object = await flushbar?.dismiss();
} else if (value == -1) {
await flushbar?.dismiss();
flushbar = Flushbar<Object>(
message: 'Analysing »${activity.name}«',

18
lib/models/activity.dart

@ -169,24 +169,27 @@ class Activity {
// calculated from other attributes:
double get avgPace {
if (avgSpeed != null && avgSpeed != 0)
if (avgSpeed != null && avgSpeed != 0) {
return 50 / 3 / avgSpeed;
else
} else {
return null;
}
}
double get avgSpeedPerHeartRate {
if (avgSpeed != null && heartRateAvailable)
if (avgSpeed != null && heartRateAvailable) {
return 60 * avgSpeed / avgHeartRate;
else
} else {
return null;
}
}
double get avgPowerPerHeartRate {
if (powerAvailable && heartRateAvailable)
if (powerAvailable && heartRateAvailable) {
return avgPower / avgHeartRate;
else
} else {
return null;
}
}
int get elevationDifference =>
@ -567,9 +570,10 @@ class Activity {
final DateTime startTime =
dateTimeFromStrava(dataMessage.get('start_time') as double);
if (name == 'new activity')
if (name == 'new activity') {
name =
'Activity on ' + DateFormat.yMMMMd('en_US').format(startTime);
}
_db
..timeStamp =
dateTimeFromStrava(dataMessage.get('timestamp') as double)

4
lib/models/activity_list.dart

@ -80,10 +80,10 @@ class ActivityList<E> extends DelegatingList<E> {
{
firstGroupWithData = false;
activityIds = activityIdsFromThisGroup;
} else
// For the others: intersect.
} else {
activityIds.removeWhere(
(int tagId) => !activityIdsFromThisGroup.contains(tagId));
}
}
}
}

7
lib/models/activity_tagging.dart

@ -39,9 +39,9 @@ class ActivityTagging {
.equals(tag.id)
.toSingle();
if (dbActivityTagging != null)
if (dbActivityTagging != null) {
return ActivityTagging._fromDb(dbActivityTagging);
else {
} else {
final ActivityTagging activityTagging = ActivityTagging(
activity: activity, tag: tag, system: system ?? false);
await activityTagging._db.save();
@ -61,8 +61,9 @@ class ActivityTagging {
.tagsId
.equals(tag.id)
.toSingle();
if (dbActivityTagging != null)
if (dbActivityTagging != null) {
return ActivityTagging._fromDb(dbActivityTagging);
}
return null;
}

3
lib/models/athlete.dart

@ -183,8 +183,9 @@ class Athlete {
await activity.deleteLaps();
// ignore: avoid_slow_async_io
if (await File(appDocDir.path + '/$stravaId.fit').exists())
if (await File(appDocDir.path + '/$stravaId.fit').exists()) {
await File(appDocDir.path + '/$stravaId.fit').delete();
}
}
await _db.getDbActivities().delete();
return await _db.delete();

3
lib/models/critical_power.dart

@ -13,11 +13,12 @@ class CriticalPower extends PowerDuration {
final List<DoublePlotPoint> plotPoints = <DoublePlotPoint>[];
powerMap.forEach((int duration, double power) {
if (duration > 60 && duration < 1200)
if (duration > 60 && duration < 1200) {
plotPoints.add(DoublePlotPoint(
domain: duration,
measure: power,
));
}
});
plotPoints.sort(

6
lib/models/heart_rate_zone.dart

@ -22,12 +22,14 @@ class HeartRateZone {
..upperPercentage = upperPercentage ?? 0
..color = color ?? 0xFFFFc107;
if (lowerPercentage != null)
if (lowerPercentage != null) {
_db.lowerLimit =
(lowerPercentage * heartRateZoneSchema.base / 100).round();
if (upperPercentage != null)
}
if (upperPercentage != null) {
_db.upperLimit =
(upperPercentage * heartRateZoneSchema.base / 100).round();
}
}
HeartRateZone._fromDb(this._db);

5
lib/models/heart_rate_zone_schema.dart

@ -148,9 +148,9 @@ class HeartRateZoneSchema {
.orderByDesc('date')
.top(1)
.toList();
if (dbHeartRateZoneSchemas.isNotEmpty)
if (dbHeartRateZoneSchemas.isNotEmpty) {
return HeartRateZoneSchema._fromDb(dbHeartRateZoneSchemas.first);
else
} else {
dbHeartRateZoneSchemas = await DbHeartRateZoneSchema()
.select()
.athletesId
@ -158,6 +158,7 @@ class HeartRateZoneSchema {
.orderBy('date')
.top(1)
.toList();
}
return (dbHeartRateZoneSchemas.isNotEmpty)
? HeartRateZoneSchema._fromDb(dbHeartRateZoneSchemas.first)
: null;

30
lib/models/interval.dart

@ -171,48 +171,54 @@ class Interval {
avgSpeed != null &&
avgSpeed > 0 &&
weight != null &&
weight > 0)
weight > 0) {
return avgPower / avgSpeed / weight;
else
} else {
return null;
}
}
double get avgPace {
if (avgSpeedByDistance != null && avgSpeedByDistance != 0)
if (avgSpeedByDistance != null && avgSpeedByDistance != 0) {
return 50 / 3 / avgSpeedByDistance;
else
} else {
return null;
}
}
double get avgSpeedPerHeartRate {
if (avgSpeed != null && avgHeartRate != null && avgHeartRate != 0)
if (avgSpeed != null && avgHeartRate != null && avgHeartRate != 0) {
return 100 * (avgSpeed / avgHeartRate);
else
} else {
return null;
}
}
double get avgPowerPerHeartRate {
if (avgPower != null &&
avgPower != -1 &&
avgHeartRate != null &&
avgHeartRate != null)
avgHeartRate != null) {
return avgPower / avgHeartRate;
else
} else {
return null;
}
}
int get elevationDifference {
if (totalAscent != null && totalDescent != null)
if (totalAscent != null && totalDescent != null) {
return totalAscent - totalDescent;
else
} else {
return null;
}
}
double get avgDoubleStrydCadence {
if (avgStrydCadence != null)
if (avgStrydCadence != null) {
return avgStrydCadence * 2;
else
} else {
return null;
}
}
// easier check for data availability

4
lib/models/interval_tagging.dart

@ -46,9 +46,9 @@ class IntervalTagging {
.equals(tag.id)
.toSingle();
if (dbIntervalTagging != null)
if (dbIntervalTagging != null) {
return IntervalTagging._fromDb(dbIntervalTagging);
else {
} else {
final IntervalTagging intervalTagging = IntervalTagging(
interval: interval,
tag: tag,

30
lib/models/lap.dart

@ -104,48 +104,54 @@ class Lap {
avgSpeed != null &&
avgSpeed > 0 &&
weight != null &&
weight > 0)
weight > 0) {
return avgPower / avgSpeed / weight;
else
} else {
return null;
}
}
double get avgPace {
if (avgSpeed != null && avgSpeed != 0)
if (avgSpeed != null && avgSpeed != 0) {
return 50 / 3 / avgSpeed;
else
} else {
return null;
}
}
double get avgSpeedPerHeartRate {
if (avgSpeed != null && avgHeartRate != null && avgHeartRate != 0)
if (avgSpeed != null && avgHeartRate != null && avgHeartRate != 0) {
return 100 * (avgSpeed / avgHeartRate);
else
} else {
return null;
}
}
double get avgPowerPerHeartRate {
if (avgPower != null &&
avgPower != -1 &&
avgHeartRate != null &&
avgHeartRate != null)
avgHeartRate != null) {
return avgPower / avgHeartRate;
else
} else {
return null;
}
}
int get elevationDifference {
if (totalAscent != null && totalDescent != null)
if (totalAscent != null && totalDescent != null) {
return totalAscent - totalDescent;
else
} else {
return null;
}
}
double get avgDoubleStrydCadence {
if (avgStrydCadence != null)
if (avgStrydCadence != null) {
return avgStrydCadence * 2;
else
} else {
return null;
}
}
// easier check for data availability

4
lib/models/lap_tagging.dart

@ -45,9 +45,9 @@ class LapTagging {
.equals(tag.id)
.toSingle();
if (dbLapTagging != null)
if (dbLapTagging != null) {
return LapTagging._fromDb(dbLapTagging);
else {
} else {
final LapTagging lapTagging = LapTagging(
lap: lap,
tag: tag,

6
lib/models/power_zone.dart

@ -22,10 +22,12 @@ class PowerZone {
..upperPercentage = upperPercentage ?? 0
..color = color ?? 0xFFFFc107;
if (lowerPercentage != null)
if (lowerPercentage != null) {
_db.lowerLimit = (lowerPercentage * powerZoneSchema.base / 100).round();
if (upperPercentage != null)
}
if (upperPercentage != null) {
_db.upperLimit = (upperPercentage * powerZoneSchema.base / 100).round();
}
}
PowerZone._fromDb(this._db);

5
lib/models/power_zone_schema.dart

@ -212,9 +212,9 @@ class PowerZoneSchema {
.orderByDesc('date')
.top(1)
.toList();
if (dbPowerZoneSchemas.isNotEmpty)
if (dbPowerZoneSchemas.isNotEmpty) {
return PowerZoneSchema._fromDb(dbPowerZoneSchemas.first);
else
} else {
dbPowerZoneSchemas = await DbPowerZoneSchema()
.select()
.athletesId
@ -222,6 +222,7 @@ class PowerZoneSchema {
.orderBy('date')
.top(1)
.toList();
}
return (dbPowerZoneSchemas.isNotEmpty)
? PowerZoneSchema._fromDb(dbPowerZoneSchemas.first)
: null;

11
lib/models/record_list.dart

@ -44,11 +44,12 @@ class RecordList<E> extends DelegatingList<E> {
if (record.event == 'record') {
if (record.speed != null && record.timeStamp != null) {
if (record.speed > 0) {
if (lastSpeed > 0)
if (lastSpeed > 0) {
movingTime +=
record.timeStamp.difference(lastTimestamp).inSeconds;
else
} else {
movingTime += 1;
}
}
lastTimestamp = record.timeStamp;
lastSpeed = record.speed;
@ -401,8 +402,9 @@ class RecordList<E> extends DelegatingList<E> {
.cast<double>();
for (final double altitude in altitudes) {
if (lastAltitude != 0 && altitude > lastAltitude)
if (lastAltitude != 0 && altitude > lastAltitude) {
sumOfAscents += altitude - lastAltitude;
}
lastAltitude = altitude;
}
return sumOfAscents;
@ -417,8 +419,9 @@ class RecordList<E> extends DelegatingList<E> {
.cast<double>();
for (final double altitude in altitudes) {
if (lastAltitude != 0 && altitude < lastAltitude)
if (lastAltitude != 0 && altitude < lastAltitude) {
sumOfDescents += lastAltitude - altitude;
}
lastAltitude = altitude;
}
return sumOfDescents;

12
lib/models/tag_group.dart

@ -68,9 +68,9 @@ class TagGroup {
.name
.equals('Auto Power Zones')
.toSingle();
if (dbTagGroup != null)
if (dbTagGroup != null) {
return TagGroup._fromDb(dbTagGroup);
else {
} else {
final TagGroup autoPowerTagGroup = TagGroup.by(
name: 'Auto Power Zones',
athlete: athlete,
@ -95,9 +95,9 @@ class TagGroup {
.name
.equals('Auto Heart Rate Zones')
.toSingle();
if (dbTagGroup != null)
if (dbTagGroup != null) {
return TagGroup._fromDb(dbTagGroup);
else {
} else {
final TagGroup autoHeartRateTagGroup = TagGroup.by(
name: 'Auto Heart Rate Zones',
athlete: athlete,
@ -119,9 +119,9 @@ class TagGroup {
.name
.equals('Effort')
.toSingle();
if (dbTagGroup != null)
if (dbTagGroup != null) {
return TagGroup._fromDb(dbTagGroup);
else {
} else {
final TagGroup autoEffortTagGroup = TagGroup.by(
name: 'Effort',
athlete: athlete,

5
lib/models/weight.dart

@ -41,9 +41,9 @@ class Weight {
.orderByDesc('date')
.top(1)
.toList();
if (dbWeights.isNotEmpty)
if (dbWeights.isNotEmpty) {
return Weight._fromDb(dbWeights.first);
else
} else {
dbWeights = await DbWeight()
.select()
.athletesId
@ -51,6 +51,7 @@ class Weight {
.orderBy('date')
.top(1)
.toList();
}
return (dbWeights.isNotEmpty) ? Weight._fromDb(dbWeights.first) : null;
}

5
lib/screens/add_filter_screen.dart

@ -80,11 +80,12 @@ class _AddFilterScreenState extends State<AddFilterScreen> {
),
onSelected: (bool selected) {
setState(() {
if (selected)
if (selected) {
widget.athlete.filters.add(tag.id);
else
} else {
widget.athlete.filters.removeWhere(
(int tagId) => tagId == tag.id);
}
});
},
selected: widget.athlete.filters.contains(tag.id),

4
lib/screens/dashboard.dart

@ -31,9 +31,9 @@ class _DashboardState extends State<Dashboard> {
@override
Widget build(BuildContext context) {
if (athletes.isEmpty)
if (athletes.isEmpty) {
return Container();
else {
} else {
return Scaffold(
appBar: AppBar(
backgroundColor: MyColor.primary,

3
lib/screens/select_interval_screen.dart

@ -51,7 +51,7 @@ class _SelectIntervalScreenState extends State<SelectIntervalScreen> {
),
),
);
} else
} else {
return Scaffold(
appBar: AppBar(
backgroundColor: MyColor.settings,
@ -59,6 +59,7 @@ class _SelectIntervalScreenState extends State<SelectIntervalScreen> {
),
body: const Text('Loading...'),
);
}
}
Future<void> getData() async {

6
lib/screens/show_activity_screen.dart

@ -548,9 +548,9 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
final Stream<int> percentageStream =
widget.activity.parse(athlete: widget.athlete);
await for (final int value in percentageStream) {
if (value == -2)
await flushbar?.dismiss();
else if (value == -1) {
if (value == -2) {
var object = await flushbar?.dismiss();
} else if (value == -1) {
await flushbar?.dismiss();
flushbar = Flushbar<Object>(
message: 'Analysing »${widget.activity.name}«',

8
lib/screens/strava_get_user.dart

@ -33,11 +33,9 @@ class _StravaGetUserState extends State<StravaGetUser> {
backgroundColor: MyColor.primary,
),
body: SafeArea(
child: Container(
child: Padding(
padding: const EdgeInsets.all(20),
child: Text(widget.athlete.stateText),
),
child: Padding(
padding: const EdgeInsets.all(20),
child: Text(widget.athlete.stateText),
),
),
);

3
lib/utils/db.dart

@ -12,8 +12,9 @@ class Db {
static bool _isConnected = false;
Future<bool> connect() async {
if (_isConnected == false)
if (_isConnected == false) {
_isConnected = await DbEncrateia().initializeDB();
}
return _isConnected;
}
}

4
lib/utils/graph_utils.dart

@ -41,9 +41,9 @@ class GraphUtils {
bottomMarginSpec: MarginSpec.fixedPixel(40),
);
static Container loadingContainer = Container(
static SizedBox loadingContainer = const SizedBox(
height: 100,
child: const Center(child: Text('Loading')),
child: Center(child: Text('Loading')),
);
static List<ChartTitle<num>> axis({String measureTitle}) {

30
lib/utils/my_bar_chart.dart

@ -56,9 +56,9 @@ class MyBarChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (_barZones.isEmpty && _value == null || _value <= 0)
if (_barZones.isEmpty && _value == null || _value <= 0) {
return const Text('no data');
else
} else {
return SizedBox(
width: _width,
height: _height,
@ -74,55 +74,59 @@ class MyBarChart extends StatelessWidget {
),
),
);
}
}
static List<BarZone> toBarZones({
List<PowerZone> powerZones,
List<HeartRateZone> heartRateZones,
}) {
if (powerZones != null)
if (powerZones != null) {
return BarZone.fromPowerZones(powerZones);
else if (heartRateZones != null)
} else if (heartRateZones != null) {
return BarZone.fromHeartRateZones(heartRateZones);
else
} else {
return <BarZone>[];
}
}
static double maxFromZones(
{List<PowerZone> powerZones,
List<HeartRateZone> heartRateZones,
num maximum}) {
if (maximum != null)
if (maximum != null) {
return maximum.toDouble();
else if (powerZones != null)
} else if (powerZones != null) {
return powerZones
.map((PowerZone powerZone) => powerZone.upperLimit.toDouble())
.reduce(math.max);
else if (heartRateZones != null)
} else if (heartRateZones != null) {
return heartRateZones
.map((HeartRateZone heartRateZone) =>
heartRateZone.upperLimit.toDouble())
.reduce(math.max);
else
} else {
return 100.0;
}
}
static double minFromZones(
{List<PowerZone> powerZones,
List<HeartRateZone> heartRateZones,
num minimum}) {
if (minimum != null)
if (minimum != null) {
return minimum.toDouble();
else if (powerZones != null)
} else if (powerZones != null) {
return powerZones
.map((PowerZone powerZone) => powerZone.lowerLimit.toDouble())
.reduce(math.min);
else if (heartRateZones != null)
} else if (heartRateZones != null) {
return heartRateZones
.map((HeartRateZone heartRateZone) =>
heartRateZone.lowerLimit.toDouble())
.reduce(math.min);
else
} else {
return 0.0;
}
}
}

8
lib/utils/my_color.dart

@ -76,11 +76,13 @@ class MyColor {
}) {
if (selected) {
if (ThemeData.estimateBrightnessForColor(backgroundColor) ==
Brightness.light)
Brightness.light) {
return black;
else
} else {
return white;
} else
}
} else {
return black;
}
}
}

9
lib/utils/my_line_chart.dart

@ -83,7 +83,7 @@ class MyLineChart extends LineChart {
double minimum,
double maximum,
}) {
if (powerZones != null)
if (powerZones != null) {
return NumericExtents(
powerZones
.map((PowerZone powerZone) => powerZone.lowerLimit)
@ -93,7 +93,7 @@ class MyLineChart extends LineChart {
.map((PowerZone powerZone) => powerZone.upperLimit)
.reduce(max) *
1.1);
else if (heartRateZones != null)
} else if (heartRateZones != null) {
return NumericExtents(
heartRateZones
.map(
@ -105,9 +105,10 @@ class MyLineChart extends LineChart {
(HeartRateZone heartRateZone) => heartRateZone.upperLimit)
.reduce(max) *
1.1);
else if (minimum != null)
} else if (minimum != null) {
return NumericExtents(minimum, maximum);
else
} else {
return null;
}
}
}

5
lib/widgets/activities_feed_widget.dart

@ -56,7 +56,7 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
itemCount: activities.length,
itemBuilder: (BuildContext context, int index) {
final Activity activity = activities[index];
if (activity.nonParsable == true)
if (activity.nonParsable == true) {
return ListTile(
leading: sportsIcon(sport: activity.sport),
title: Text(activity.name ?? 'Activity'),
@ -75,7 +75,7 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
getData();
},
);
else
} else {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
@ -167,6 +167,7 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
),
)
]);
}
},
);
}

6
lib/widgets/activity_widgets/activity_bargraph_widget.dart

@ -190,15 +190,17 @@ class _ActivityBarGraphWidgetState extends State<ActivityBarGraphWidget> {
}
_powerZoneSchema = await activity.powerZoneSchema;
if (_powerZoneSchema != null)
if (_powerZoneSchema != null) {
_powerZones = await _powerZoneSchema.powerZones;
}
_heartRateDistributions = await activity.powerZoneCounts();
_powerDistributions = await activity.heartRateZoneCounts();
_heartRateZoneSchema = await activity.heartRateZoneSchema;
if (_heartRateZoneSchema != null)
if (_heartRateZoneSchema != null) {
_heartRateZones = await _heartRateZoneSchema.heartRateZones;
}
setState(() => loading = false);
}

2
lib/widgets/activity_widgets/activity_ftp_widget.dart

@ -67,7 +67,7 @@ class _ActivityFtpWidgetState extends State<ActivityFtpWidget> {
);
}
} else {
return Container(
return SizedBox(
height: 100,
child: Center(
child: Text(loading ? 'Loading' : 'No data available'),

5
lib/widgets/activity_widgets/activity_heart_rate_widget.dart

@ -136,10 +136,11 @@ class _ActivityHeartRateWidgetState extends State<ActivityHeartRateWidget> {
records = RecordList<Event>(await activity.records);
heartRateZoneSchema = await activity.heartRateZoneSchema;
if (heartRateZoneSchema != null)
if (heartRateZoneSchema != null) {
heartRateZones = await heartRateZoneSchema.heartRateZones;
else
} else {
heartRateZones = <HeartRateZone>[];
}
setState(() => loading = false);
}
}

5
lib/widgets/activity_widgets/activity_power_widget.dart

@ -134,10 +134,11 @@ class _ActivityPowerWidgetState extends State<ActivityPowerWidget> {
records = RecordList<Event>(await activity.records);
powerZoneSchema = await activity.powerZoneSchema;
if (powerZoneSchema != null)
if (powerZoneSchema != null) {
powerZones = await powerZoneSchema.powerZones;
else
} else {
powerZones = <PowerZone>[];
}
setState(() => loading = false);
}
}

5
lib/widgets/activity_widgets/activity_tag_widget.dart

@ -31,11 +31,11 @@ class _ActivityTagWidgetState extends State<ActivityTagWidget> {
@override
Widget build(BuildContext context) {
if (tagGroups == null)
if (tagGroups == null) {
return const Center(
child: Text('Loading ...'),
);
else
} else {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:
@ -94,6 +94,7 @@ class _ActivityTagWidgetState extends State<ActivityTagWidget> {
),
),
);
}
}
Future<void> getData() async {

6
lib/widgets/athlete_widgets/athlete_current_filter_widget.dart

@ -29,8 +29,9 @@ class AthleteCurrentFilterWidget extends StatelessWidget {
widgets.add(const Text('('));
widgets.add(Text(' ${tagGroup.name}: '));
empty = false;
} else
} else {
widgets.add(const Text('OR'));
}
widgets.add(
Chip(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
@ -67,7 +68,8 @@ class AthleteCurrentFilterWidget extends StatelessWidget {
runSpacing: 15,
children: widgets,
);
} else
} else {
return Container();
}
}
}

3
lib/widgets/athlete_widgets/athlete_distance_widget.dart

@ -122,8 +122,9 @@ class _AthleteDistanceWidgetState extends State<AthleteDistanceWidget> {
if (activity.timeStamp.year != year) {
year = activity.timeStamp.year;
distanceSoFar = activity.distance;
} else
} else {
distanceSoFar += activity.distance;
}
activity.distanceSoFar = distanceSoFar;
}

3
lib/widgets/athlete_widgets/athlete_moving_time_widget.dart

@ -123,8 +123,9 @@ class _AthleteMovingTimeWidgetState extends State<AthleteMovingTimeWidget> {
if (activity.timeStamp.year != year) {
year = activity.timeStamp.year;
movingTimeSoFar = activity.movingTime;
} else
} else {
movingTimeSoFar += activity.movingTime;
}
activity.movingTimeSoFar = movingTimeSoFar;
}

11
lib/widgets/athlete_widgets/athlete_settings_widget.dart

@ -112,8 +112,9 @@ class _AthleteSettingsWidgetState extends State<AthleteSettingsWidget> {
Future<void> decreaseDownloadInterval() async {
widget.athlete.downloadInterval =
(widget.athlete.downloadInterval ?? 21) - 7;
if (widget.athlete.downloadInterval < 7)
if (widget.athlete.downloadInterval < 7) {
widget.athlete.downloadInterval = 7;
}
await widget.athlete.save();
setState(() {});
}
@ -128,14 +129,15 @@ class _AthleteSettingsWidgetState extends State<AthleteSettingsWidget> {
Future<void> decreaseRecordAggregationCount() async {
widget.athlete.recordAggregationCount =
((widget.athlete.recordAggregationCount ?? 16) / 2).round();
if (widget.athlete.recordAggregationCount < 1)
if (widget.athlete.recordAggregationCount < 1) {
widget.athlete.recordAggregationCount = 1;
}
await widget.athlete.save();
setState(() {});
}
Widget stravaTile({Athlete athlete}) {
if (athlete.id != null)
if (athlete.id != null) {
return ListTile(
leading: MyIcon.stravaDownload,
title: const Text('Strava ID / Username / Location'),
@ -145,7 +147,8 @@ class _AthleteSettingsWidgetState extends State<AthleteSettingsWidget> {
' / ' +
(athlete.geoState ?? '')),
);
else
} else {
return Container(width: 0, height: 0);
}
}
}

5
lib/widgets/athlete_widgets/athlete_tag_group_widget.dart

@ -70,10 +70,11 @@ class _AthleteTagGroupWidgetState extends State<AthleteTagGroupWidget> {
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) {
if (tagGroup.system)
if (tagGroup.system) {
return ShowTagGroupScreen(tagGroup: tagGroup);
else
} else {
return AddTagGroupScreen(tagGroup: tagGroup);
}
},
),
);

5
lib/widgets/athlete_widgets/edit_standalone_athlete_widget.dart

@ -75,7 +75,7 @@ class _EditStandaloneAthleteWidgetState
final List<PowerZoneSchema> powerZoneSchemas =
await widget.athlete.powerZoneSchemas;
if (powerZoneSchemas.isEmpty)
if (powerZoneSchemas.isEmpty) {
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
@ -83,7 +83,8 @@ class _EditStandaloneAthleteWidgetState
OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete),
),
);
else
} else {
Navigator.of(