refactor: Migrate to null safety

This commit is contained in:
Krille Fear 2022-01-29 12:35:03 +01:00 committed by Christian Pauly
commit 55f0300f9f
163 changed files with 1759 additions and 1903 deletions

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:collection/collection.dart' show IterableExtension;
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
@ -19,38 +20,38 @@ class NotificationSettingsItem {
NotificationSettingsItem(
PushRuleKind.underride,
'.m.rule.room_one_to_one',
(c) => L10n.of(c).directChats,
(c) => L10n.of(c)!.directChats,
),
NotificationSettingsItem(
PushRuleKind.override,
'.m.rule.contains_display_name',
(c) => L10n.of(c).containsDisplayName,
(c) => L10n.of(c)!.containsDisplayName,
),
NotificationSettingsItem(
PushRuleKind.content,
'.m.rule.contains_user_name',
(c) => L10n.of(c).containsUserName,
(c) => L10n.of(c)!.containsUserName,
),
NotificationSettingsItem(
PushRuleKind.override,
'.m.rule.invite_for_me',
(c) => L10n.of(c).inviteForMe,
(c) => L10n.of(c)!.inviteForMe,
),
NotificationSettingsItem(
PushRuleKind.override,
'.m.rule.member_event',
(c) => L10n.of(c).memberChanges,
(c) => L10n.of(c)!.memberChanges,
),
NotificationSettingsItem(
PushRuleKind.override,
'.m.rule.suppress_notices',
(c) => L10n.of(c).botMessages,
(c) => L10n.of(c)!.botMessages,
),
];
}
class SettingsNotifications extends StatefulWidget {
const SettingsNotifications({Key key}) : super(key: key);
const SettingsNotifications({Key? key}) : super(key: key);
@override
SettingsNotificationsController createState() =>
@ -71,31 +72,30 @@ class SettingsNotificationsController extends State<SettingsNotifications> {
return NotificationSetting.open();
}
bool getNotificationSetting(NotificationSettingsItem item) {
bool? getNotificationSetting(NotificationSettingsItem item) {
final pushRules = Matrix.of(context).client.globalPushRules;
switch (item.type) {
case PushRuleKind.content:
return pushRules.content
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
return pushRules!.content
?.singleWhereOrNull((r) => r.ruleId == item.key)
?.enabled;
case PushRuleKind.override:
return pushRules.override
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
return pushRules!.override
?.singleWhereOrNull((r) => r.ruleId == item.key)
?.enabled;
case PushRuleKind.room:
return pushRules.room
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
return pushRules!.room
?.singleWhereOrNull((r) => r.ruleId == item.key)
?.enabled;
case PushRuleKind.sender:
return pushRules.sender
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
return pushRules!.sender
?.singleWhereOrNull((r) => r.ruleId == item.key)
?.enabled;
case PushRuleKind.underride:
return pushRules.underride
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
return pushRules!.underride
?.singleWhereOrNull((r) => r.ruleId == item.key)
?.enabled;
}
return false;
}
void setNotificationSetting(NotificationSettingsItem item, bool enabled) {

View file

@ -15,14 +15,15 @@ import 'settings_notifications.dart';
class SettingsNotificationsView extends StatelessWidget {
final SettingsNotificationsController controller;
const SettingsNotificationsView(this.controller, {Key key}) : super(key: key);
const SettingsNotificationsView(this.controller, {Key? key})
: super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: const BackButton(),
title: Text(L10n.of(context).notifications),
title: Text(L10n.of(context)!.notifications),
),
body: MaxWidthBody(
withScrolling: true,
@ -38,7 +39,7 @@ class SettingsNotificationsView extends StatelessWidget {
SwitchListTile.adaptive(
value: !Matrix.of(context).client.allPushNotificationsMuted,
title: Text(
L10n.of(context).notificationsEnabledForThisAccount),
L10n.of(context)!.notificationsEnabledForThisAccount),
onChanged: (_) => showFutureLoadingDialog(
context: context,
future: () =>
@ -52,7 +53,7 @@ class SettingsNotificationsView extends StatelessWidget {
if (!Matrix.of(context).client.allPushNotificationsMuted) ...{
if (!kIsWeb && Platform.isAndroid)
ListTile(
title: Text(L10n.of(context).soundVibrationLedColor),
title: Text(L10n.of(context)!.soundVibrationLedColor),
trailing: CircleAvatar(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
@ -64,7 +65,7 @@ class SettingsNotificationsView extends StatelessWidget {
const Divider(thickness: 1),
ListTile(
title: Text(
L10n.of(context).pushRules,
L10n.of(context)!.pushRules,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
@ -82,20 +83,20 @@ class SettingsNotificationsView extends StatelessWidget {
const Divider(thickness: 1),
ListTile(
title: Text(
L10n.of(context).devices,
L10n.of(context)!.devices,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
FutureBuilder<List<Pusher>>(
FutureBuilder<List<Pusher>?>(
future: Matrix.of(context).client.getPushers(),
builder: (context, snapshot) {
if (snapshot.hasError) {
Center(
child: Text(
snapshot.error.toLocalizedString(context),
snapshot.error!.toLocalizedString(context),
),
);
}