Skip to content

Commit

Permalink
upgrade to dart 2.17
Browse files Browse the repository at this point in the history
now that we use features of dart 2.17 for the theme upgrading everything to it.

This also adds default constructors to every widget potentially improving the performance. Nuallybility got a boost aswel.

.
  • Loading branch information
Leptopoda committed Oct 16, 2022
1 parent e52dfa6 commit c359a47
Show file tree
Hide file tree
Showing 148 changed files with 609 additions and 491 deletions.
6 changes: 3 additions & 3 deletions lib/common/appstart/app_initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ Future<void> initializeApp(bool isBackground) async {
WidgetUpdateCallback(KiwiContainer().resolve())
.registerCallback(KiwiContainer().resolve());

NotificationsInitialize().setupNotifications();
BackgroundInitialize().setupBackgroundScheduling();
NotificationScheduleChangedInitialize().setupNotification();
const NotificationsInitialize().setupNotifications();
const BackgroundInitialize().setupBackgroundScheduling();
const NotificationScheduleChangedInitialize().setupNotification();

if (isBackground) {
final setup = KiwiContainer().resolve<ScheduleSourceProvider>();
Expand Down
2 changes: 2 additions & 0 deletions lib/common/appstart/background_initialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:kiwi/kiwi.dart';
/// Note: More or less reliable background scheduling only works on android
///
class BackgroundInitialize {
const BackgroundInitialize();

Future<void> setupBackgroundScheduling() async {
WorkSchedulerService scheduler;
if (Platform.isAndroid) {
Expand Down
10 changes: 6 additions & 4 deletions lib/common/appstart/localization_initialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import 'package:kiwi/kiwi.dart';
/// correct language
///
class LocalizationInitialize {
PreferencesProvider? _preferencesProvider;
String? _languageCode;
final PreferencesProvider? _preferencesProvider;
final String? _languageCode;

///
/// Initialize the localization using the provided language code
///
LocalizationInitialize.fromLanguageCode(this._languageCode);
const LocalizationInitialize.fromLanguageCode(this._languageCode)
: _preferencesProvider = null;

///
/// Initialize the localization using the locale from the preferences provider
///
LocalizationInitialize.fromPreferences(this._preferencesProvider);
const LocalizationInitialize.fromPreferences(this._preferencesProvider)
: _languageCode = null;

Future<void> setupLocalizations() async {
final localization = L(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:kiwi/kiwi.dart';
/// Initializes the notification for when the schedule changed
///
class NotificationScheduleChangedInitialize {
const NotificationScheduleChangedInitialize();

void setupNotification() {
final provider = KiwiContainer().resolve<ScheduleProvider>();

Expand Down
5 changes: 4 additions & 1 deletion lib/common/appstart/notifications_initialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:kiwi/kiwi.dart';
/// won't show the notification
///
class NotificationsInitialize {
const NotificationsInitialize();

Future<void> setupNotifications() async {
if (Platform.isAndroid) {
final notificationApi = NotificationApi();
Expand All @@ -17,7 +19,8 @@ class NotificationsInitialize {

await notificationApi.initialize();
} else {
KiwiContainer().registerInstance<NotificationApi>(VoidNotificationApi());
KiwiContainer()
.registerInstance<NotificationApi>(const VoidNotificationApi());
}
}
}
6 changes: 3 additions & 3 deletions lib/common/appstart/service_injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void injectServices(bool isBackground) {

final KiwiContainer c = KiwiContainer();
c.registerInstance(
PreferencesProvider(
const PreferencesProvider(
PreferencesAccess(),
SecureStorageAccess(),
),
);
c.registerInstance(DatabaseAccess());
c.registerInstance(const DatabaseAccess());
c.registerInstance(
ScheduleEntryRepository(
c.resolve(),
Expand Down Expand Up @@ -80,7 +80,7 @@ void injectServices(bool isBackground) {
);
c.registerInstance(
DateEntryProvider(
DateManagementService(),
const DateManagementService(),
DateEntryRepository(c.resolve()),
),
);
Expand Down
2 changes: 2 additions & 0 deletions lib/common/background/task_callback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/// Override this class in order to receive a background callback
///
abstract class TaskCallback {
const TaskCallback();

Future<void> run();

Future<void> schedule();
Expand Down
2 changes: 2 additions & 0 deletions lib/common/background/work_scheduler_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:dhbwstudentapp/common/background/task_callback.dart';

abstract class WorkSchedulerService {
const WorkSchedulerService();

Future<void> scheduleOneShotTaskIn(Duration delay, String id, String name);

Future<void> scheduleOneShotTaskAt(
Expand Down
2 changes: 2 additions & 0 deletions lib/common/data/database_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:dhbwstudentapp/common/data/sql_scripts.dart';
import 'package:sqflite/sqflite.dart';

class DatabaseAccess {
const DatabaseAccess();

static const String _databaseName = "Database.db";
static Database? _databaseInstance;

Expand Down
4 changes: 3 additions & 1 deletion lib/common/data/preferences/preferences_access.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:shared_preferences/shared_preferences.dart';

class PreferencesAccess {
const PreferencesAccess();

Future<void> set<T>(String key, T value) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();

Expand Down Expand Up @@ -43,5 +45,5 @@ class PreferencesAccess {
class InvalidValueTypeException implements Exception {
final Type type;

InvalidValueTypeException(this.type);
const InvalidValueTypeException(this.type);
}
2 changes: 1 addition & 1 deletion lib/common/data/preferences/preferences_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PreferencesProvider {
final PreferencesAccess _preferencesAccess;
final SecureStorageAccess _secureStorageAccess;

PreferencesProvider(this._preferencesAccess, this._secureStorageAccess);
const PreferencesProvider(this._preferencesAccess, this._secureStorageAccess);

Future<ThemeMode> appTheme() async {
final theme = await _preferencesAccess.get<String>(AppThemeKey);
Expand Down
4 changes: 3 additions & 1 deletion lib/common/data/preferences/secure_storage_access.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

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

const SecureStorageAccess();

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/iap/in_app_purchase_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class InAppPurchaseHelper {
final productIdPurchases =
allPurchases?.where((element) => element.productId == id);

if (productIdPurchases?.isNotEmpty ?? false) {
return productIdPurchases!.any((element) => _isPurchased(element))
if (productIdPurchases != null && productIdPurchases.isNotEmpty) {
return productIdPurchases.any((element) => _isPurchased(element))
? PurchaseStateEnum.Purchased
: PurchaseStateEnum.NotPurchased;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/common/ui/app_launch_dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:flutter/material.dart';
class AppLaunchDialog {
final PreferencesProvider _preferencesProvider;

AppLaunchDialog(this._preferencesProvider);
const AppLaunchDialog(this._preferencesProvider);

Future<void> showAppLaunchDialogs(BuildContext context) async {
final appLaunchCounter = await _preferencesProvider.getAppLaunchCounter();
Expand Down
2 changes: 1 addition & 1 deletion lib/common/ui/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:dhbwstudentapp/common/ui/text_theme.dart';
import 'package:flutter/material.dart';

class AppTheme {
AppTheme._();
const AppTheme._();

/// Light theme
static final lightThemeData = ThemeData(
Expand Down
5 changes: 4 additions & 1 deletion lib/common/ui/donate_to_developer_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class DonateToDeveloperDialog {
final PreferencesProvider _preferencesProvider;
final int _appLaunchCounter;

DonateToDeveloperDialog(this._preferencesProvider, this._appLaunchCounter);
const DonateToDeveloperDialog(
this._preferencesProvider,
this._appLaunchCounter,
);

Future<void> showIfNeeded(BuildContext context) async {
if (await _preferencesProvider.getDidShowDonateDialog()) return;
Expand Down
4 changes: 4 additions & 0 deletions lib/common/ui/notification_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class NotificationApi {
final FlutterLocalNotificationsPlugin _localNotificationsPlugin =
FlutterLocalNotificationsPlugin();

NotificationApi();

///
/// Initialize the notifications. You can't show any notifications before you
/// call this method
Expand Down Expand Up @@ -84,6 +86,8 @@ class NotificationApi {
/// This class implements the methods of the NotificationApi with empty stubs
///
class VoidNotificationApi implements NotificationApi {
const VoidNotificationApi();

@override
FlutterLocalNotificationsPlugin get _localNotificationsPlugin =>
throw UnimplementedError();
Expand Down
2 changes: 1 addition & 1 deletion lib/common/ui/rate_in_store_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RateInStoreDialog {
final PreferencesProvider _preferencesProvider;
final int _appLaunchCounter;

RateInStoreDialog(this._preferencesProvider, this._appLaunchCounter);
const RateInStoreDialog(this._preferencesProvider, this._appLaunchCounter);

Future<void> showIfNeeded(BuildContext context) async {
if (!PlatformUtil.isAndroid()) return;
Expand Down
2 changes: 1 addition & 1 deletion lib/common/ui/widget_help_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class WidgetHelpDialog {
final PreferencesProvider _preferencesProvider;
final int _appLaunchCounter;

WidgetHelpDialog(this._preferencesProvider, this._appLaunchCounter);
const WidgetHelpDialog(this._preferencesProvider, this._appLaunchCounter);

Future<void> showIfNeeded(BuildContext context) async {
if (!PlatformUtil.isAndroid()) return;
Expand Down
4 changes: 2 additions & 2 deletions lib/common/ui/widgets/dots_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ class DotsIndicator extends StatelessWidget {
final int currentStep;

const DotsIndicator({
Key? key,
super.key,
required this.numberSteps,
required this.currentStep,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand Down
8 changes: 4 additions & 4 deletions lib/common/ui/widgets/error_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
class ErrorDisplay extends StatelessWidget {
final bool show;

const ErrorDisplay({Key? key, required this.show}) : super(key: key);
const ErrorDisplay({super.key, required this.show});

@override
Widget build(BuildContext context) {
Expand All @@ -25,9 +25,9 @@ class ErrorDisplay extends StatelessWidget {
child: Text(
L.of(context).noConnectionMessage,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.subtitle2!.copyWith(
color: AppTheme.noConnectionForeground,
),
style: const TextStyle(
color: AppTheme.noConnectionForeground,
),
),
),
),
Expand Down
2 changes: 2 additions & 0 deletions lib/common/ui/widgets/help_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
/// Deriving classes only need to implement the title() and content() methods
///
abstract class HelpDialog {
const HelpDialog();

Future show(BuildContext context) async {
await showDialog(
context: context,
Expand Down
2 changes: 1 addition & 1 deletion lib/common/ui/widgets/title_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
class TitleListTile extends StatelessWidget {
final String title;

const TitleListTile({Key? key, required this.title}) : super(key: key);
const TitleListTile({super.key, required this.title});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 2 additions & 0 deletions lib/common/util/cancelable_mutex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class CancelableMutex {
CancellationToken? _token;
CancellationToken? get token => _token;

CancelableMutex();

void cancel() {
_token?.cancel();
}
Expand Down
12 changes: 6 additions & 6 deletions lib/date_management/business/date_entry_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ class DateEntryProvider {
final DateManagementService _dateEntryService;
final DateEntryRepository _dateEntryRepository;

DateEntryProvider(this._dateEntryService, this._dateEntryRepository);
const DateEntryProvider(this._dateEntryService, this._dateEntryRepository);

Future<List<DateEntry>> getCachedDateEntries(
DateSearchParameters parameters,
) async {
List<DateEntry> cachedEntries = <DateEntry>[];

if (parameters.includeFuture! && parameters.includePast!) {
if (parameters.includeFuture && parameters.includePast) {
cachedEntries = await _dateEntryRepository.queryAllDateEntries(
parameters.databaseName,
parameters.year,
);
} else {
final now = DateTime.now();
if (parameters.includeFuture!) {
if (parameters.includeFuture) {
final datesAfter = await _dateEntryRepository.queryDateEntriesAfter(
parameters.databaseName,
parameters.year,
Expand All @@ -31,7 +31,7 @@ class DateEntryProvider {
cachedEntries.addAll(datesAfter);
}

if (parameters.includePast!) {
if (parameters.includePast) {
final datesBefore = await _dateEntryRepository.queryDateEntriesBefore(
parameters.databaseName,
parameters.year,
Expand Down Expand Up @@ -85,11 +85,11 @@ class DateEntryProvider {
continue;
}

if (dateEntry.start.isBefore(now) && !parameters.includePast!) {
if (dateEntry.start.isBefore(now) && !parameters.includePast) {
continue;
}

if (dateEntry.end.isAfter(now) && !parameters.includeFuture!) {
if (dateEntry.end.isAfter(now) && !parameters.includeFuture) {
continue;
}

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 @@ -17,6 +17,8 @@ enum CalendarPermission {
class CalendarAccess {
final DeviceCalendarPlugin _deviceCalendarPlugin = DeviceCalendarPlugin();

CalendarAccess();

Future<CalendarPermission> requestCalendarPermission() async {
try {
var permissionsGranted = await _deviceCalendarPlugin.hasPermissions();
Expand Down Expand Up @@ -134,12 +136,10 @@ class CalendarAccess {
),
);

var existingEvents = <Event>[];

if (existingEventsResult.isSuccess) {
existingEvents = existingEventsResult.data!.toList();
return existingEventsResult.data!.toList();
}
return existingEvents;
return <Event>[];
}

DateEntry _findFirstEntry(List<DateEntry> entries) {
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 @@ -4,7 +4,7 @@ import 'package:dhbwstudentapp/date_management/model/date_entry.dart';
class DateEntryRepository {
final DatabaseAccess _database;

DateEntryRepository(this._database);
const DateEntryRepository(this._database);

Future<List<DateEntry>> queryAllDateEntries(
String? databaseName,
Expand Down
2 changes: 1 addition & 1 deletion lib/date_management/model/date_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class DateDatabase {
final String id;
final String displayName;

DateDatabase(this.displayName, this.id);
const DateDatabase(this.displayName, this.id);
}
Loading

0 comments on commit c359a47

Please sign in to comment.