Skip to content

Commit

Permalink
Merge pull request #43 from Bennik2000/code-cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
Bennik2000 authored Sep 8, 2020
2 parents ce5d110 + 510ff42 commit 30bfdbf
Show file tree
Hide file tree
Showing 76 changed files with 260 additions and 227 deletions.
2 changes: 1 addition & 1 deletion lib/common/appstart/background_initialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:kiwi/kiwi.dart';

class BackgroundInitialize {
Future<void> setupBackgroundScheduling() async {
var scheduler;
WorkSchedulerService scheduler;
if (Platform.isAndroid) {
scheduler = BackgroundWorkScheduler();
} else {
Expand Down
8 changes: 7 additions & 1 deletion lib/common/background/background_work_scheduler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import 'package:kiwi/kiwi.dart';
import 'package:workmanager/workmanager.dart';

class BackgroundWorkScheduler extends WorkSchedulerService {
Map<String, TaskCallback> _taskCallbacks = {};
final Map<String, TaskCallback> _taskCallbacks = {};

BackgroundWorkScheduler() {
_setupBackgroundScheduling();
}

@override
Future<void> scheduleOneShotTaskIn(
Duration delay, String id, String name) async {
print(
Expand All @@ -25,6 +26,7 @@ class BackgroundWorkScheduler extends WorkSchedulerService {
);
}

@override
Future<void> scheduleOneShotTaskAt(
DateTime date,
String id,
Expand All @@ -33,11 +35,13 @@ class BackgroundWorkScheduler extends WorkSchedulerService {
await scheduleOneShotTaskIn(date.difference(DateTime.now()), id, name);
}

@override
Future<void> cancelTask(String id) async {
await Workmanager.cancelByUniqueName(id);
print("Cancelled task $id");
}

@override
Future<void> schedulePeriodic(
Duration delay,
String id, [
Expand All @@ -60,10 +64,12 @@ class BackgroundWorkScheduler extends WorkSchedulerService {
);
}

@override
void registerTask(TaskCallback task) {
_taskCallbacks[task.getName()] = task;
}

@override
Future<void> executeTask(String id) async {
await _taskCallbacks[id]?.run();
}
Expand Down
6 changes: 6 additions & 0 deletions lib/common/background/void_background_work_scheduler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class VoidBackgroundWorkScheduler extends WorkSchedulerService {
print("Background scheduling is not available!");
}

@override
Future<void> scheduleOneShotTaskIn(Duration delay, String id, String name) {
print(
"Did not schedule one shot task: $id. With a delay of ${delay.inMinutes} minutes.",
Expand All @@ -14,6 +15,7 @@ class VoidBackgroundWorkScheduler extends WorkSchedulerService {
return Future.value();
}

@override
Future<void> scheduleOneShotTaskAt(
DateTime date,
String id,
Expand All @@ -22,12 +24,14 @@ class VoidBackgroundWorkScheduler extends WorkSchedulerService {
await scheduleOneShotTaskIn(date.difference(DateTime.now()), id, name);
}

@override
Future<void> cancelTask(String id) {
print("Cancelled task $id");

return Future.value();
}

@override
Future<void> schedulePeriodic(
Duration delay,
String id, [
Expand All @@ -40,8 +44,10 @@ class VoidBackgroundWorkScheduler extends WorkSchedulerService {
return Future.value();
}

@override
void registerTask(TaskCallback task) {}

@override
Future<void> executeTask(String id) {
return Future.value();
}
Expand Down
15 changes: 8 additions & 7 deletions lib/common/data/database_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';

class DatabaseAccess {
static final _databaseName = "Database.db";
static const String _databaseName = "Database.db";
static Database _databaseInstance;

static final String idColumnName = "id";
static const String idColumnName = "id";

Future<Database> get _database async {
if (_databaseInstance != null) return _databaseInstance;
Expand All @@ -18,23 +18,24 @@ class DatabaseAccess {
return _databaseInstance;
}

_initDatabase() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, _databaseName);
Future<Database> _initDatabase() async {
final Directory documentsDirectory =
await getApplicationDocumentsDirectory();
final String path = join(documentsDirectory.path, _databaseName);

return await openDatabase(path,
version: SqlScripts.databaseMigrationScripts.length,
onCreate: _onCreate,
onUpgrade: _onUpgrade);
}

Future _onCreate(Database db, int version) async {
Future<void> _onCreate(Database db, int version) async {
print("Initializing Database with version: $version");

await _onUpgrade(db, 1, version);
}

Future _onUpgrade(Database db, int oldVersion, int newVersion) async {
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
print("Migrating database version: $oldVersion -> $newVersion");

for (var i = oldVersion; i <= newVersion; i++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/common/data/preferences/secure_storage_access.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

class SecureStorageAccess {
final _secureStorage = new FlutterSecureStorage();
final _secureStorage = const FlutterSecureStorage();

Future<void> set(String key, String value) async {
await _secureStorage.write(key: key, value: value);
Expand Down
4 changes: 2 additions & 2 deletions lib/common/i18n/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ class L {
return Localizations.of<L>(context, L);
}

static Map<String, Map<String, String>> _localizedValues = {
static final Map<String, Map<String, String>> _localizedValues = {
"de": de,
"en": en
};

_getValue(String key) {
String _getValue(String key) {
return _localizedValues[_language][key] ?? "";
}

Expand Down
20 changes: 10 additions & 10 deletions lib/common/ui/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ class ColorPalettes {
}

static const MaterialColor main = MaterialColor(0xffff061c, <int, Color>{
050: const Color(0xFFff838e),
100: const Color(0xFFff6a77),
200: const Color(0xFFff5160),
300: const Color(0xFFff3849),
400: const Color(0xFFff1f33),
500: const Color(0xffff061c),
600: const Color(0xFFe60519),
700: const Color(0xFFcc0516),
800: const Color(0xFFb30414),
900: const Color(0xFF990411),
050: Color(0xFFff838e),
100: Color(0xFFff6a77),
200: Color(0xFFff5160),
300: Color(0xFFff3849),
400: Color(0xFFff1f33),
500: Color(0xffff061c),
600: Color(0xFFe60519),
700: Color(0xFFcc0516),
800: Color(0xFFb30414),
900: Color(0xFF990411),
});

static const MaterialColor secondary = MaterialColor(0xFFCECED0, <int, Color>{
Expand Down
4 changes: 2 additions & 2 deletions lib/common/ui/notification_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NotificationApi {
FlutterLocalNotificationsPlugin();

Future<void> initialize() async {
var initializationSettingsAndroid = AndroidInitializationSettings(
var initializationSettingsAndroid = const AndroidInitializationSettings(
'outline_event_note_24',
);

Expand Down Expand Up @@ -44,7 +44,7 @@ class NotificationApi {
ticker: 'ticker',
);

var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var iOSPlatformChannelSpecifics = const IOSNotificationDetails();

var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics,
Expand Down
13 changes: 7 additions & 6 deletions lib/common/ui/rate_in_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class RateInStore {
RateInStore(this._preferencesProvider);

Future<void> showRateInStoreDialogIfNeeded(BuildContext context) async {
var countdown = await _preferencesProvider.getRateInStoreLaunchCountdown();
final countdown =
await _preferencesProvider.getRateInStoreLaunchCountdown();

if (countdown <= 0) {
if (await _preferencesProvider.getDontShowRateNowDialog()) return;
Expand All @@ -27,15 +28,15 @@ class RateInStore {
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
buttonPadding: EdgeInsets.all(0),
actionsPadding: EdgeInsets.all(0),
contentPadding: EdgeInsets.all(0),
buttonPadding: const EdgeInsets.all(0),
actionsPadding: const EdgeInsets.all(0),
contentPadding: const EdgeInsets.all(0),
title: Text(L.of(context).rateDialogTitle),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.all(24),
padding: const EdgeInsets.all(24),
child: Text(L.of(context).rateDialogMessage),
),
Padding(
Expand All @@ -52,7 +53,7 @@ class RateInStore {
ButtonBar _buildButtonBar(BuildContext context) {
return ButtonBar(
mainAxisSize: MainAxisSize.max,
buttonPadding: EdgeInsets.fromLTRB(5, 0, 5, 0),
buttonPadding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
children: <Widget>[
FlatButton(
child: Text(L.of(context).rateDialogDoNotRateButton.toUpperCase()),
Expand Down
2 changes: 1 addition & 1 deletion lib/common/ui/widgets/error_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ErrorDisplay extends StatelessWidget {
: Container(
width: double.infinity,
),
duration: Duration(milliseconds: 300),
duration: const Duration(milliseconds: 300),
),
],
);
Expand Down
2 changes: 1 addition & 1 deletion lib/common/util/cancelable_mutex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:mutex/mutex.dart';
import 'cancellation_token.dart';

class CancelableMutex {
Mutex _mutex = Mutex();
final Mutex _mutex = Mutex();
CancellationToken _token;
CancellationToken get token => _token;

Expand Down
8 changes: 4 additions & 4 deletions lib/date_management/data/calendar_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CalendarAccess {
List<DateEntry> dateEntries,
Calendar calendar,
) async {
if ((dateEntries ?? []).length == 0) return;
if ((dateEntries ?? []).isEmpty) return;

var existingEvents =
await _getExistingEventsFromCalendar(dateEntries, calendar);
Expand All @@ -70,7 +70,7 @@ class CalendarAccess {
var isAllDay = isAtMidnight(entry.dateAndTime);

var start = entry.dateAndTime;
var end = isAllDay ? start : start.add(Duration(minutes: 30));
var end = isAllDay ? start : start.add(const Duration(minutes: 30));

await _deviceCalendarPlugin.createOrUpdateEvent(Event(
calendar.id,
Expand All @@ -90,9 +90,9 @@ class CalendarAccess {
.where((element) => element.title == entry.description)
.toList();

var id;
String id;

if (existingEvent.length > 0) {
if (existingEvent.isNotEmpty) {
id = existingEvent[0].eventId;
}
return id;
Expand Down
4 changes: 2 additions & 2 deletions lib/date_management/data/date_entry_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class DateEntryEntity extends DatabaseEntity {

@override
void fromMap(Map<String, dynamic> map) {
var date;
DateTime date;
if (map["date"] != null) {
date = DateTime.fromMillisecondsSinceEpoch(map["date"]);
}

_dateEntry = new DateEntry(
_dateEntry = DateEntry(
comment: map["comment"],
dateAndTime: date,
description: map["description"],
Expand Down
2 changes: 1 addition & 1 deletion lib/date_management/data/date_entry_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DateEntryRepository {

for (var row in rows) {
dateEntries.add(
new DateEntryEntity.fromMap(row).asDateEntry(),
DateEntryEntity.fromMap(row).asDateEntry(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/date_management/service/parsing/all_dates_extract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AllDatesExtract {
return _extractAllDates(body, databaseName);
} catch (e) {
if (e.runtimeType is ParseException) rethrow;
throw new ParseException.withInner(e);
throw ParseException.withInner(e);
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/date_management/ui/calendar_export_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _CalendarExportPageState extends State<CalendarExportPage> {
L.of(context).dateManagementExportToCalendarDescription)),
),
_buildCalendarList(),
Divider(
const Divider(
height: 1,
),
_buildExportButton()
Expand Down Expand Up @@ -106,7 +106,7 @@ class _CalendarExportPageState extends State<CalendarExportPage> {
Container(
width: 24,
height: 24,
decoration: new BoxDecoration(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: isSelected ? Color(calendar.color) : Colors.transparent,
border: Border.all(
Expand Down Expand Up @@ -143,8 +143,8 @@ class _CalendarExportPageState extends State<CalendarExportPage> {
builder:
(BuildContext context, CalendarExportViewModel viewModel, _) =>
viewModel.isExporting
? Padding(
padding: const EdgeInsets.all(8.0),
? const Padding(
padding: EdgeInsets.all(8.0),
child: SizedBox(
height: 32,
width: 32,
Expand Down
Loading

0 comments on commit 30bfdbf

Please sign in to comment.