refactor: Null safe dependencies

This commit is contained in:
Christian Pauly 2021-04-21 14:19:54 +02:00
commit 1a477adcb1
34 changed files with 320 additions and 381 deletions

View file

@ -14,7 +14,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_lock/flutter_app_lock.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:universal_html/html.dart' as html;
import 'views/widgets/matrix.dart';
import 'config/themes.dart';

View file

@ -34,7 +34,6 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_gen/gen_l10n/l10n_en.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:path_provider/path_provider.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'platform_infos.dart';
import '../config/app_config.dart';
import '../config/setting_keys.dart';
@ -130,12 +129,7 @@ class BackgroundPush {
bool useDeviceSpecificAppId = false,
}) async {
if (PlatformInfos.isIOS) {
FirebaseMessaging()
.requestNotificationPermissions(IosNotificationSettings(
sound: true,
alert: true,
badge: true,
));
await _fcmSharedIsolate.requestPermission();
}
final clientName = PlatformInfos.clientName;
oldTokens ??= <String>{};
@ -355,7 +349,8 @@ class BackgroundPush {
.toString()
.split('?')
.first;
final res = json.decode(utf8.decode((await http.get(url)).bodyBytes));
final res =
json.decode(utf8.decode((await http.get(Uri.parse(url))).bodyBytes));
if (res['gateway'] == 'matrix') {
endpoint = url;
}
@ -699,7 +694,7 @@ class BackgroundPush {
final url = thumbnail
? content.getThumbnail(client, width: width, height: height)
: content.getDownloadLink(client);
final request = await HttpClient().getUrl(Uri.parse(url));
final request = await HttpClient().getUrl(url);
final response = await request.close();
if (response.statusCode >= 300) {
// we are not in the 2xx range

View file

@ -8,7 +8,7 @@ Future<Database> constructDb(
String password = ''}) async {
Logs().v('[Moor] Using moor web');
return Database(WebDatabase.withStorage(
MoorWebStorage.indexedDbIfSupported(filename),
await MoorWebStorage.indexedDbIfSupported(filename),
logStatements: logStatements));
}

View file

@ -87,7 +87,7 @@ extension LocalizedBody on Event {
}
// check if the url is cached
final url = Uri.parse(mxcUrl).getDownloadLink(room.client);
final file = await DefaultCacheManager().getFileFromCache(url);
final file = await DefaultCacheManager().getFileFromCache(url.toString());
return file != null;
}
@ -96,8 +96,8 @@ extension LocalizedBody on Event {
final mxcUrl = attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail);
_downloadAndDecryptFutures[mxcUrl] ??= downloadAndDecryptAttachment(
getThumbnail: getThumbnail,
downloadCallback: (String url) async {
final file = await DefaultCacheManager().getSingleFile(url);
downloadCallback: (Uri url) async {
final file = await DefaultCacheManager().getSingleFile(url.toString());
return await file.readAsBytes();
},
);

View file

@ -7,7 +7,7 @@ extension FilteredTimelineExtension on Timeline {
final filteredEvents = events
.where((e) =>
// always filter out edit and reaction relationships
!{RelationshipTypes.Edit, RelationshipTypes.Reaction}
!{RelationshipTypes.edit, RelationshipTypes.reaction}
.contains(e.relationshipType) &&
// always filter out m.key.* events
!e.type.startsWith('m.key.verification.') &&

View file

@ -6,7 +6,7 @@ import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/foundation.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:universal_html/html.dart' as html;
import 'package:mime_type/mime_type.dart';
import 'package:permission_handler/permission_handler.dart';

View file

@ -22,13 +22,13 @@ abstract class SentryController {
return await storage.getItemBool(SettingKeys.sentry);
}
static final sentry = SentryClient(dsn: AppConfig.sentryDns);
static final sentry = SentryClient(SentryOptions(dsn: AppConfig.sentryDns));
static void captureException(error, stackTrace) async {
Logs().e('Capture exception', error, stackTrace);
if (!kDebugMode && await getSentryStatus()) {
await sentry.captureException(
exception: error,
error,
stackTrace: stackTrace,
);
}

View file

@ -3,7 +3,7 @@ import 'dart:io';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:emoji_picker/emoji_picker.dart';
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:file_picker_cross/file_picker_cross.dart';
import 'package:fluffychat/config/app_config.dart';
@ -395,7 +395,7 @@ class ChatController extends State<Chat> {
event.sendAgain();
}
final allEditEvents = event
.aggregatedEvents(timeline, RelationshipTypes.Edit)
.aggregatedEvents(timeline, RelationshipTypes.edit)
.where((e) => e.status == -1);
for (final e in allEditEvents) {
e.sendAgain();
@ -473,7 +473,7 @@ class ChatController extends State<Chat> {
children: [
Spacer(),
EmojiPicker(
onEmojiSelected: (emoji, category) {
onEmojiSelected: (category, emoji) {
// recent emojis don't work, so we sadly have to re-implement them
// https://github.com/JeffG05/emoji_picker/issues/31
SharedPreferences.getInstance().then((prefs) {
@ -482,7 +482,7 @@ class ChatController extends State<Chat> {
// make sure we remove duplicates
prefs.setStringList('recents', recents.toSet().toList());
});
Navigator.of(context, rootNavigator: false).pop<Emoji>(emoji);
Navigator.of(context, rootNavigator: false).pop(emoji);
},
),
],

View file

@ -125,7 +125,7 @@ class ChatListController extends State<ChatList> {
context: context,
future: () => room.setPushRuleState(
room.pushRuleState == PushRuleState.notify
? PushRuleState.mentions_only
? PushRuleState.mentionsOnly
: PushRuleState.notify),
);
}

View file

@ -15,7 +15,7 @@ import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:url_launcher/url_launcher.dart';
import '../utils/localized_exception_extension.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:universal_html/html.dart' as html;
class HomeserverPicker extends StatefulWidget {
@override

View file

@ -241,8 +241,8 @@ class ChatDetailsUI extends StatelessWidget {
),
if (room.canChangeHistoryVisibility)
PopupMenuItem<HistoryVisibility>(
value: HistoryVisibility.world_readable,
child: Text(HistoryVisibility.world_readable
value: HistoryVisibility.worldReadable,
child: Text(HistoryVisibility.worldReadable
.getLocalizedString(
MatrixLocals(L10n.of(context)))),
),
@ -269,9 +269,9 @@ class ChatDetailsUI extends StatelessWidget {
<PopupMenuEntry<GuestAccess>>[
if (room.canChangeGuestAccess)
PopupMenuItem<GuestAccess>(
value: GuestAccess.can_join,
value: GuestAccess.canJoin,
child: Text(
GuestAccess.can_join.getLocalizedString(
GuestAccess.canJoin.getLocalizedString(
MatrixLocals(L10n.of(context))),
),
),

View file

@ -431,7 +431,7 @@ class ChatUI extends StatelessWidget {
final emojis = List<String>.from(AppEmojis.emojis);
final allReactionEvents = controller.selectedEvents.first
.aggregatedEvents(
controller.timeline, RelationshipTypes.Reaction)
controller.timeline, RelationshipTypes.reaction)
?.where((event) =>
event.senderId == event.room.client.userID &&
event.type == 'm.reaction');

View file

@ -425,7 +425,7 @@ class _EmoteImage extends StatelessWidget {
method: ThumbnailMethod.scale,
);
return CachedNetworkImage(
imageUrl: url,
imageUrl: url.toString(),
fit: BoxFit.contain,
width: size,
height: size,

View file

@ -16,7 +16,7 @@ import 'package:fluffychat/utils/sentry_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_lock/flutter_app_lock.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_screen_lock/lock_screen.dart';
import 'package:flutter_screen_lock/functions.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:image_picker/image_picker.dart';
import 'package:url_launcher/url_launcher.dart';
@ -296,11 +296,10 @@ class _SettingsState extends State<Settings> {
await FlutterSecureStorage().read(key: SettingKeys.appLockKey);
if (currentLock?.isNotEmpty ?? false) {
var unlocked = false;
await showLockScreen(
await screenLock(
context: context,
correctString: currentLock,
onUnlocked: () => unlocked = true,
canBiometric: true,
didConfirmed: (_) => unlocked = true,
);
if (unlocked != true) return;
}

View file

@ -8,7 +8,7 @@ import 'package:fluffychat/views/widgets/message_download_content.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_sound_lite/flutter_sound.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:universal_html/html.dart' as html;
import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../../utils/ui_fake.dart' if (dart.library.html) 'dart:ui' as ui;
import 'matrix.dart';
@ -144,7 +144,8 @@ class _AudioPlayerState extends State<AudioPlayer> {
if (kIsWeb) {
if (widget.event.content['url'] is String) {
webSrcUrl = Uri.parse(widget.event.content['url'])
.getDownloadLink(Matrix.of(context).client);
.getDownloadLink(Matrix.of(context).client)
.toString();
return Container(
height: 50,
width: 300,

View file

@ -66,7 +66,7 @@ class Avatar extends StatelessWidget {
child: noPic
? textWidget
: CachedNetworkImage(
imageUrl: src,
imageUrl: src.toString(),
fit: BoxFit.cover,
width: size,
height: size,

View file

@ -86,7 +86,7 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
await showFutureLoadingDialog(
context: context,
future: () =>
widget.room.setPushRuleState(PushRuleState.mentions_only));
widget.room.setPushRuleState(PushRuleState.mentionsOnly));
break;
case 'unmute':
await showFutureLoadingDialog(

View file

@ -53,7 +53,7 @@ class ContentBanner extends StatelessWidget {
opacity: opacity,
child: (!loading && mxContent != null)
? CachedNetworkImage(
imageUrl: src,
imageUrl: src.toString(),
height: 300,
fit: BoxFit.cover,
)

View file

@ -56,13 +56,15 @@ class HtmlMessage extends StatelessWidget {
getMxcUrl: (String mxc, double width, double height,
{bool animated = false}) {
final ratio = MediaQuery.of(context).devicePixelRatio;
return Uri.parse(mxc)?.getThumbnail(
matrix.client,
width: (width ?? 800) * ratio,
height: (height ?? 800) * ratio,
method: ThumbnailMethod.scale,
animated: animated,
);
return Uri.parse(mxc)
?.getThumbnail(
matrix.client,
width: (width ?? 800) * ratio,
height: (height ?? 800) * ratio,
method: ThumbnailMethod.scale,
animated: animated,
)
.toString();
},
setCodeLanguage: (String key, String value) async {
await matrix.store.setItem('${SettingKeys.codeLanguage}.$key', value);

View file

@ -80,9 +80,10 @@ class _ImageBubbleState extends State<ImageBubble> {
@override
void initState() {
thumbnailUrl =
widget.event.getAttachmentUrl(getThumbnail: true, animated: true);
attachmentUrl = widget.event.getAttachmentUrl(animated: true);
thumbnailUrl = widget.event
.getAttachmentUrl(getThumbnail: true, animated: true)
.toString();
attachmentUrl = widget.event.getAttachmentUrl(animated: true).toString();
if (thumbnailUrl == null) {
_requestFile(getThumbnail: true);
}
@ -195,12 +196,15 @@ class _ImageBubbleState extends State<ImageBubble> {
_requestedThumbnailOnFailure = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
thumbnailUrl = widget.event.getAttachmentUrl(
getThumbnail: true,
useThumbnailMxcUrl: true,
animated: true);
thumbnailUrl = widget.event
.getAttachmentUrl(
getThumbnail: true,
useThumbnailMxcUrl: true,
animated: true)
.toString();
attachmentUrl = widget.event
.getAttachmentUrl(useThumbnailMxcUrl: true, animated: true);
.getAttachmentUrl(useThumbnailMxcUrl: true, animated: true)
.toString();
});
});
}

View file

@ -160,7 +160,7 @@ class InputBar extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
CachedNetworkImage(
imageUrl: url,
imageUrl: url.toString(),
width: size,
height: size,
),

View file

@ -92,7 +92,7 @@ class Message extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (event.relationshipType == RelationshipTypes.Reply)
if (event.relationshipType == RelationshipTypes.reply)
FutureBuilder<Event>(
future: event.getReplyEvent(timeline),
builder: (BuildContext context, snapshot) {
@ -177,7 +177,7 @@ class Message extends StatelessWidget {
children: rowChildren,
);
Widget container;
if (event.hasAggregatedEvents(timeline, RelationshipTypes.Reaction)) {
if (event.hasAggregatedEvents(timeline, RelationshipTypes.reaction)) {
container = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment:
@ -253,7 +253,7 @@ class _MetaRow extends StatelessWidget {
fontSize: 11 * AppConfig.fontSizeFactor,
),
),
if (event.hasAggregatedEvents(timeline, RelationshipTypes.Edit))
if (event.hasAggregatedEvents(timeline, RelationshipTypes.edit))
Padding(
padding: const EdgeInsets.only(left: 2.0),
child: Icon(

View file

@ -1,7 +1,7 @@
import 'package:fluffychat/config/setting_keys.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_lock/flutter_app_lock.dart';
import 'package:flutter_screen_lock/lock_screen.dart';
import 'package:flutter_screen_lock/functions.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
class LockScreen extends StatelessWidget {
@ -17,11 +17,10 @@ class LockScreen extends StatelessWidget {
if (snapshot.connectionState == ConnectionState.done) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (snapshot.data?.isNotEmpty ?? false) {
showLockScreen(
screenLock(
context: context,
correctString: snapshot.data,
onUnlocked: () => AppLock.of(context).didUnlock(),
canBiometric: true,
didConfirmed: (_) => AppLock.of(context).didUnlock(),
canCancel: false,
);
} else {

View file

@ -16,7 +16,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:provider/provider.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:universal_html/html.dart' as html;
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';
/*import 'package:fluffychat/views/chat_ui.dart';
@ -201,7 +201,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
html.Notification(
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
body: body,
icon: icon,
icon: icon.toString(),
);
} else if (Platform.isLinux) {
/*var sessionBus = DBusClient.session();
@ -239,7 +239,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
Future<void> initConfig() async {
try {
final configJsonString =
utf8.decode((await http.get('config.json')).bodyBytes);
utf8.decode((await http.get(Uri.parse('config.json'))).bodyBytes);
final configJson = json.decode(configJsonString);
AppConfig.loadFromJson(configJson);
} catch (e, s) {

View file

@ -14,7 +14,7 @@ class MessageReactions extends StatelessWidget {
@override
Widget build(BuildContext context) {
final allReactionEvents =
event.aggregatedEvents(timeline, RelationshipTypes.Reaction);
event.aggregatedEvents(timeline, RelationshipTypes.reaction);
final reactionMap = <String, _ReactionEntry>{};
for (final e in allReactionEvents) {
if (e.content['m.relates_to'].containsKey('key')) {
@ -97,7 +97,7 @@ class _Reaction extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: <Widget>[
CachedNetworkImage(
imageUrl: src,
imageUrl: src.toString(),
height: fontSize,
),
Container(width: 4),