switching to new linter package flutter_lints and fix the first warnings

upgrade-2021-project
Stefan Haslinger 2022-02-16 17:21:23 +01:00
parent fd3c4b775b
commit fbd7d1814b
68 changed files with 275 additions and 363 deletions

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -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

View File

@ -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}«',

View File

@ -169,25 +169,28 @@ 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 =>
ascentAvailable ? totalAscent - totalDescent : null;
@ -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)

View File

@ -80,13 +80,13 @@ class ActivityList<E> extends DelegatingList<E> {
{
firstGroupWithData = false;
activityIds = activityIdsFromThisGroup;
} else
// For the others: intersect.
} else {
activityIds.removeWhere(
(int tagId) => !activityIdsFromThisGroup.contains(tagId));
}
}
}
}
final List<Activity> activityList = _activities
.where((Activity activity) => activityIds.contains(activity.id))

View File

@ -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;
}

View File

@ -183,9 +183,10 @@ 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();
}

View File

@ -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(

View File

@ -22,13 +22,15 @@ 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);
DbHeartRateZone _db;

View File

@ -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;

View File

@ -171,49 +171,55 @@ 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
bool get powerAvailable => !<num>[null, -1].contains(avgPower);

View File

@ -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,

View File

@ -104,49 +104,55 @@ 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
bool get powerAvailable => !<num>[null, -1].contains(avgPower);

View File

@ -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,

View File

@ -22,11 +22,13 @@ 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);
DbPowerZone _db;

View File

@ -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;

View File

@ -44,12 +44,13 @@ 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;

View File

@ -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,

View File

@ -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;
}

View File

@ -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),

View File

@ -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,

View File

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

View File

@ -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}«',

View File

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

View File

@ -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;
}
}

View File

@ -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}) {

View File

@ -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,
@ -75,54 +75,58 @@ 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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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> {
),
)
]);
}
},
);
}

View File

@ -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);
}

View File

@ -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'),

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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:
@ -95,6 +95,7 @@ class _ActivityTagWidgetState extends State<ActivityTagWidget> {
),
);
}
}
Future<void> getData() async {
tagGroups = await TagGroup.includingActivityTaggings(

View File

@ -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();
}
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -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);
}
},
),
);

View File

@ -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(context).pop();
}
}
}

View File

@ -96,7 +96,7 @@ class _EditStravaAthleteWidgetState extends State<EditStravaAthleteWidget> {
final List<PowerZoneSchema> powerZoneSchemas =
await widget.athlete.powerZoneSchemas;
await flushbar.dismiss();
if (powerZoneSchemas.isEmpty)
if (powerZoneSchemas.isEmpty) {
Navigator.pushReplacement(
context,
MaterialPageRoute<BuildContext>(
@ -104,8 +104,9 @@ class _EditStravaAthleteWidgetState extends State<EditStravaAthleteWidget> {
OnBoardingPowerZoneSchemaScreen(athlete: widget.athlete),
),
);
else
} else {
Navigator.of(context).pop();
}
} else {
flushbar = Flushbar<Object>(
icon: MyIcon.error,

View File

@ -63,8 +63,9 @@ class ActivityAltitudeChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -67,8 +67,9 @@ class ActivityEcorChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -68,8 +68,9 @@ class ActivityFormPowerChart extends StatelessWidget {
maximum: maximum,
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -69,8 +69,9 @@ class ActivityGroundTimeChart extends StatelessWidget {
maximum: maximum,
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -66,8 +66,9 @@ class ActivityHeartRateChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -75,7 +75,7 @@ class _ActivityIntervalsChartState extends State<ActivityIntervalsChart> {
)
];
if (laps.isNotEmpty)
if (laps.isNotEmpty) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
@ -260,15 +260,14 @@ class _ActivityIntervalsChartState extends State<ActivityIntervalsChart> {
],
),
if (selectedRecord == null)
Container(
child: const Text('Select a record to continue.'),
),
const Text('Select a record to continue.'),
],
),
);
else
} else {
return GraphUtils.loadingContainer;
}
}
void moveSelectedRecord({int amount}) {
if (amount < 0) {

View File

@ -63,8 +63,9 @@ class ActivityLegSpringStiffnessChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -70,8 +70,9 @@ class ActivityPaceChart extends StatelessWidget {
flipVerticalAxis: true,
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -65,8 +65,9 @@ class ActivityPowerChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -63,8 +63,9 @@ class ActivityPowerPerHeartRateChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -63,8 +63,9 @@ class ActivityPowerRatioChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -69,8 +69,9 @@ class ActivitySpeedChart extends StatelessWidget {
maximum: maximum,
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -63,8 +63,9 @@ class ActivitySpeedPerHeartRateChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -63,8 +63,9 @@ class ActivityStrideRatioChart extends StatelessWidget {
const BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -69,8 +69,9 @@ class ActivityStrydCadenceChart extends StatelessWidget {
maximum: maximum,
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -69,8 +69,9 @@ class ActivityVerticalOscillationChart extends StatelessWidget {
maximum: maximum,
),
);
} else
} else {
return GraphUtils.loadingContainer;
}
},
);
}

View File

@ -124,10 +124,11 @@ class _IntervalHeartRateWidgetState extends State<IntervalHeartRateWidget> {
Future<void> getData() async {
records = RecordList<Event>(await widget.interval.records);
heartRateZoneSchema = await widget.interval.heartRateZoneSchema;
if (heartRateZoneSchema != null)
if (heartRateZoneSchema != null) {
heartRateZones = await heartRateZoneSchema.heartRateZones;
else
} else {
heartRateZones = <HeartRateZone>[];
}
setState(() => loading = false);
}
}

View File

@ -13,7 +13,7 @@ import '/utils/my_button.dart';
import '/widgets/charts/lap_charts/lap_power_chart.dart';
class IntervalPowerWidget extends StatefulWidget {
const IntervalPowerWidget({this.interval});
const IntervalPowerWidget({Key? key, this.interval}) : super(key: key);
final encrateia.Interval interval;
@ -118,10 +118,11 @@ class _IntervalPowerWidgetState extends State<IntervalPowerWidget> {
Future<void> getData() async {
records = RecordList<Event>(await widget.interval.records);
powerZoneSchema = await widget.interval.powerZoneSchema;
if (powerZoneSchema != null)
if (powerZoneSchema != null) {
powerZones = await powerZoneSchema.powerZones;
else
} else {
powerZones = <PowerZone>[];
}
setState(() => loading = false);
}
}

View File

@ -37,11 +37,11 @@ class _IntervalTagWidgetState extends State<IntervalTagWidget> {
@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:
@ -97,6 +97,7 @@ class _IntervalTagWidgetState extends State<IntervalTagWidget> {
),
);
}
}
Future<void> getData() async {
tagGroups = await TagGroup.includingIntervalTaggings(

View File

@ -120,10 +120,11 @@ class _LapHeartRateWidgetState extends State<LapHeartRateWidget> {
Future<void> getData() async {
records = RecordList<Event>(await widget.lap.records);
heartRateZoneSchema = await widget.lap.heartRateZoneSchema;
if (heartRateZoneSchema != null)
if (heartRateZoneSchema != null) {
heartRateZones = await heartRateZoneSchema.heartRateZones;
else
} else {
heartRateZones = <HeartRateZone>[];
}
setState(() => loading = false);
}
}

View File

@ -118,10 +118,11 @@ class _LapPowerWidgetState extends State<LapPowerWidget> {
Future<void> getData() async {
records = RecordList<Event>(await widget.lap.records);
powerZoneSchema = await widget.lap.powerZoneSchema;
if (powerZoneSchema != null)
if (powerZoneSchema != null) {
powerZones = await powerZoneSchema.powerZones;
else
} else {
powerZones = <PowerZone>[];
}
setState(() => loading = false);
}
}

View File

@ -37,11 +37,11 @@ class _LapTagWidgetState extends State<LapTagWidget> {
@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:
@ -95,6 +95,7 @@ class _LapTagWidgetState extends State<LapTagWidget> {
),
);
}
}
Future<void> getData() async {
tagGroups = await TagGroup.includingLapTaggings(

View File

@ -96,11 +96,12 @@ class _LapsListWidgetState extends State<LapsListWidget> {
),
),
);
} else
} else {
return Center(
child: Text(loading ? 'Loading' : 'No data available'),
);
}
}
Future<void> copyToInterval({Lap lap}) async {
final List<Event> records = await lap.records;

View File

@ -293,6 +293,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.2"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_markdown:
dependency: "direct main"
description:
@ -349,13 +356,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
flutter_staggered_grid_view:
dependency: "direct main"
description:
name: flutter_staggered_grid_view
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1"
flutter_web_plugins:
dependency: transitive
description: flutter
@ -452,6 +452,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.4.0"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
logging:
dependency: transitive
description:

View File

@ -43,6 +43,7 @@ dependencies:
dev_dependencies:
build_runner: ^2.1.7
build_verify: ^3.0.0
flutter_lints: ^1.0.4
flutter:
uses-material-design: true