Skip to content

Commit

Permalink
increase lints and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Aug 5, 2023
1 parent 994c800 commit ee44cc1
Show file tree
Hide file tree
Showing 115 changed files with 479 additions and 473 deletions.
27 changes: 23 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,28 @@ analyzer:

linter:
rules:
avoid_print: true
cancel_subscriptions: true
prefer_single_quotes: true
prefer_const_constructors: true
prefer_const_declarations: true
require_trailing_commas: true
always_declare_return_types: true
avoid_catches_without_on_clauses: true
avoid_equals_and_hash_code_on_mutable_classes: true
avoid_types_on_closure_parameters: true
cancel_subscriptions: true
directives_ordering: true
eol_at_end_of_file: true
omit_local_variable_types: true
prefer_asserts_in_initializer_lists: true
prefer_const_constructors: true
prefer_final_in_for_each: true
prefer_final_locals: true
prefer_null_aware_method_calls: true
prefer_null_aware_operators: true
sort_constructors_first: true
sort_unnamed_constructors_first: true
sort_pub_dependencies: true
type_annotate_public_apis: true
unawaited_futures: true
unnecessary_lambdas: true
unnecessary_parenthesis: true
use_named_constants: true
use_super_parameters: true
4 changes: 2 additions & 2 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:yaru_widgets/yaru_widgets.dart';

class UbuntuSettingsApp extends StatefulWidget {
const UbuntuSettingsApp({
Key? key,
}) : super(key: key);
super.key,
});

@override
State<UbuntuSettingsApp> createState() => _UbuntuSettingsAppState();
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/l10n.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

export 'package:flutter_gen/gen_l10n/app_localizations.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void main() async {
),
Provider<DisplayService>(
create: (_) => DisplayService(),
dispose: (_, DisplayService service) => service.dispose(),
dispose: (_, service) => service.dispose(),
),
],
child: const UbuntuSettingsApp(),
Expand Down
8 changes: 4 additions & 4 deletions lib/services/date_time_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ extension _DateTimeRemoteObject on DBusRemoteObject {

Future<void> setTimeZone(String timezone) async {
final args = [DBusString(timezone), const DBusBoolean(false)];
callMethod(_kDateTimeInterface, _kSetTimezoneMethodName, args);
await callMethod(_kDateTimeInterface, _kSetTimezoneMethodName, args);
}

Future<void> setTime(int time) async {
bool? ntp = await getNtp();
final ntp = await getNtp();
if (ntp == null || ntp == true) return;
final args = [
DBusInt64(time),
const DBusBoolean(false),
const DBusBoolean(false)
];
callMethod(_kDateTimeInterface, _kSetTimeMethodName, args);
await callMethod(_kDateTimeInterface, _kSetTimeMethodName, args);
}

Future<DateTime?> getDateTime() async {
Expand All @@ -156,7 +156,7 @@ extension _DateTimeRemoteObject on DBusRemoteObject {
Future<void> setNtp(bool? value) async {
if (value == null) return;
final args = [DBusBoolean(value), const DBusBoolean(false)];
callMethod(_kDateTimeInterface, _kSetNtpMethodName, args);
await callMethod(_kDateTimeInterface, _kSetNtpMethodName, args);
}
}

Expand Down
13 changes: 6 additions & 7 deletions lib/services/display/display_dbus_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:dbus/dbus.dart';
import 'package:settings/services/display/objects/dbus_displays_config.dart';
import 'package:settings/generated/dbus/display-config-remote-object.dart';
import 'package:settings/services/display/objects/dbus_displays_config.dart';

const _displaysInterface = 'org.gnome.Mutter.DisplayConfig';

Expand All @@ -24,8 +24,7 @@ const _displayPath = '/org/gnome/Mutter/DisplayConfig';
class DisplayDBusService {
DisplayDBusService() : _object = _createObject() {
/// Listen to signal stream, when a change occur, we update our data
_object.monitorsChanged
.listen((OrgGnomeMutterDisplayConfigMonitorsChanged signal) {
_object.monitorsChanged.listen((signal) {
if (signal.name == 'MonitorsChanged') {
getCurrent();
}
Expand All @@ -49,8 +48,8 @@ class DisplayDBusService {
}

Future<DBusDisplaysConfig> getCurrent() async {
List<DBusValue>? state = await _object.callGetCurrentState();
List<dynamic> list = state.map((e) => _toNative(e)).toList();
final state = await _object.callGetCurrentState();
final list = state.map(_toNative).toList();
return DBusDisplaysConfig(list);
}

Expand All @@ -73,9 +72,9 @@ class DisplayDBusService {
output =
value.map((key, value) => MapEntry(_toNative(key), _toNative(value)));
} else if (value is Iterable) {
output = value.map((e) => _toNative(e)).toList();
output = value.map(_toNative).toList();
} else if (value is DBusArray) {
output = value.toNative().map((e) => _toNative(e)).toList();
output = value.toNative().map(_toNative).toList();
} else if (value is DBusValue) {
output = value.toNative();
} else {
Expand Down
18 changes: 9 additions & 9 deletions lib/services/display/display_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DisplayService {
: _displayDBusService = DisplayDBusService(),
_currentNotifier = ValueNotifier(null),
_initialNotifier = ValueNotifier(null) {
_loadState(notifyStream: true).then((DisplaysConfiguration value) {
_loadState(notifyStream: true).then((value) {
_initialNotifier.value = value;
_currentNotifier.value = value;
});
Expand Down Expand Up @@ -54,13 +54,13 @@ class DisplayService {
/// never pass here)
if (_currentNotifier.value == null) {}

final DBusDisplaysConfig displayConfig =
final displayConfig =
await _displayDBusService.getCurrent();

List<DBusStruct> logicalParameterValues = [];
final logicalParameterValues = <DBusStruct>[];

for (int i = 0; i < displayConfig.monitorsLength; i++) {
final DisplayMonitorConfiguration confMonitor =
for (var i = 0; i < displayConfig.monitorsLength; i++) {
final confMonitor =
_currentNotifier.value!.configurations[i];

// x ; y ; scale ; transform(rotation) ; primary ; monitors
Expand Down Expand Up @@ -106,7 +106,7 @@ class DisplayService {
}

Future<DisplaysConfiguration> _loadState({required bool notifyStream}) {
final Future<DisplaysConfiguration> future = _displayDBusService
final future = _displayDBusService
.getCurrent()
.then(_mapToModel)
.then((value) => latest = value);
Expand All @@ -118,10 +118,10 @@ class DisplayService {
}

DisplaysConfiguration _mapToModel(DBusDisplaysConfig dbusConfiguration) {
final int monitorsCount = dbusConfiguration.monitorsLength;
final List<DisplayMonitorConfiguration> confs = [];
final monitorsCount = dbusConfiguration.monitorsLength;
final confs = <DisplayMonitorConfiguration>[];

for (int i = 0; i < monitorsCount; i++) {
for (var i = 0; i < monitorsCount; i++) {
/// map data only if there's a current option
/// if no current option
/// => monitor not used
Expand Down
10 changes: 8 additions & 2 deletions lib/services/display/objects/dbus_displays_config.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: type_annotate_public_apis

class DBusDisplaysConfig {
DBusDisplaysConfig(List<dynamic> list)
: serial = list[0],
Expand Down Expand Up @@ -26,10 +28,14 @@ class DBusDisplaysConfig {

/// * a(siiddada{sv}) modes: available modes
List<Option> availableOptions(index) =>
(_monitors[index][1] as List<dynamic>).map((e) => Option(e)).toList();
(_monitors[index][1] as List<dynamic>).map(
(e) {
return Option(e);
},
).toList();

Option? currentOption(index) {
final List<Option> options = availableOptions(index);
final options = availableOptions(index);
bool predicate(Option option) => option.isCurrent;
if (options.any(predicate)) {
return options.where(predicate).first;
Expand Down
8 changes: 4 additions & 4 deletions lib/services/house_keeping_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const _kRemoveTempFiles = 'RemoveTempFiles';
const _kRecentlyUsedFilePathSuffix = '/.local/share/recently-used.xbel';

class HouseKeepingService {
final DBusRemoteObject _object;

HouseKeepingService() : _object = _createObject();
final DBusRemoteObject _object;

static DBusRemoteObject _createObject() {
return DBusRemoteObject(
Expand All @@ -31,11 +31,11 @@ class HouseKeepingService {
void removeTempFiles() => _object.removeTempFiles();

void clearRecentlyUsed() {
final String path =
final path =
Platform.environment['HOME']! + _kRecentlyUsedFilePathSuffix;
if (Platform.environment['HOME'] == null) return;
var file = File(path);
var sink = file.openWrite();
final file = File(path);
final sink = file.openWrite();
const cleanContent = '''<?xml version="1.0" encoding="UTF-8"?>
<xbel version="1.0" xmlns:bookmark="http://www.freedesktop.org/standards/desktop-bookmarks" xmlns:mime="http://www.freedesktop.org/standards/shared-mime-info">
</xbel>''';
Expand Down
12 changes: 6 additions & 6 deletions lib/services/input_source_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import 'dart:io';
import 'package:xml/xml.dart';

class InputSourceService {
static const pathToXml = '/usr/share/X11/xkb/rules/base.xml';
late final List<InputSource> inputSources;

InputSourceService() {
inputSources = _loadInputSources();
}
static const pathToXml = '/usr/share/X11/xkb/rules/base.xml';
late final List<InputSource> inputSources;

List<InputSource> _loadInputSources() {
final document = XmlDocument.parse(File(pathToXml).readAsStringSync());
Expand Down Expand Up @@ -48,16 +48,16 @@ class InputSourceService {
}

class InputSource {

InputSource({this.name, this.description, required this.variants});
final String? name;
final String? description;
final List<InputSourceVariant> variants;

InputSource({this.name, this.description, required this.variants});
}

class InputSourceVariant {
final String? name;
final String? description;

InputSourceVariant({this.name, this.description});
final String? name;
final String? description;
}
4 changes: 2 additions & 2 deletions lib/services/locale_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ extension _LocaleRemoteObject on DBusRemoteObject {
Future<void> setLocale(List<String?>? value) async {
if (value == null) return;
final children = <DBusString>[];
for (var string in value) {
for (final string in value) {
if (string != null) {
children.add(DBusString(string));
}
}
final array = DBusArray(DBusSignature('s'), children);
final args = [array, const DBusBoolean(false)];
callMethod(_kLocaleInterfaceName, _kSetLocaleMethodName, args);
await callMethod(_kLocaleInterfaceName, _kSetLocaleMethodName, args);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/services/settings_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Settings {
return;
}
_values[key] = value;
_settings.set(key, DBusUint32(value));
await _settings.set(key, DBusUint32(value));
}

Future<void> resetValue(String key) {
Expand Down
6 changes: 3 additions & 3 deletions lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Color colorFromHex(String hexString) {
/// Darken a color by [percent] amount (100 = black)
Color darken(Color c, [int percent = 10]) {
assert(1 <= percent && percent <= 100);
var f = 1 - percent / 100;
final f = 1 - percent / 100;
return Color.fromARGB(
c.alpha,
(c.red * f).round(),
Expand All @@ -23,7 +23,7 @@ Color darken(Color c, [int percent = 10]) {
/// Lighten a color by [percent] amount (100 = white)
Color lighten(Color c, [int percent = 10]) {
assert(1 <= percent && percent <= 100);
var p = percent / 100;
final p = percent / 100;
return Color.fromARGB(
c.alpha,
c.red + ((255 - c.red) * p).round(),
Expand All @@ -45,7 +45,7 @@ String camelCaseToSplitByDash(String value) {
final beforeCapitalLetterRegex = RegExp(r'(?=[A-Z])');
final parts = value.split(beforeCapitalLetterRegex);
var newString = '';
for (var part in parts) {
for (final part in parts) {
if (newString.isEmpty) {
newString = part.toLowerCase();
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/view/duration_dropdown_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'package:yaru_widgets/yaru_widgets.dart';

class DurationDropdownButton extends StatelessWidget {
const DurationDropdownButton({
Key? key,
super.key,
required this.value,
required this.values,
required this.onChanged,
this.zeroValueText,
}) : super(key: key);
});

/// The current value of the [DropdownButton]
final int? value;
Expand Down
3 changes: 1 addition & 2 deletions lib/view/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class Link extends StatelessWidget {
const Link({Key? key, required this.url, required this.linkText})
: super(key: key);
const Link({super.key, required this.url, required this.linkText});

final String url;
final String linkText;
Expand Down
Loading

0 comments on commit ee44cc1

Please sign in to comment.