From 5409fe864b39ec2006d20c8d774672afa204942c Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 4 Oct 2020 16:11:18 +0200 Subject: [PATCH] fix: Desktop images --- lib/components/avatar.dart | 7 ++++++- lib/components/content_banner.dart | 17 ++++++++++++----- lib/components/image_bubble.dart | 26 +++++++++++++++++--------- lib/components/input_bar.dart | 17 ++++++++++++----- lib/components/message_reactions.dart | 14 ++++++++++---- lib/utils/platform_infos.dart | 6 ++++++ lib/views/settings_emotes.dart | 20 ++++++++++++++------ pubspec.lock | 2 +- pubspec.yaml | 2 +- 9 files changed, 79 insertions(+), 32 deletions(-) diff --git a/lib/components/avatar.dart b/lib/components/avatar.dart index 1d450b64..47ca14bf 100644 --- a/lib/components/avatar.dart +++ b/lib/components/avatar.dart @@ -1,4 +1,5 @@ import 'package:famedlysdk/famedlysdk.dart'; +import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/string_color.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -41,7 +42,11 @@ class Avatar extends StatelessWidget { onTap: onTap, child: CircleAvatar( radius: size / 2, - backgroundImage: !noPic ? CachedNetworkImageProvider(src) : null, + backgroundImage: !noPic + ? PlatformInfos.isBetaDesktop + ? NetworkImage(src) + : CachedNetworkImageProvider(src) + : null, backgroundColor: noPic ? name?.lightColor ?? Theme.of(context).secondaryHeaderColor : Theme.of(context).secondaryHeaderColor, diff --git a/lib/components/content_banner.dart b/lib/components/content_banner.dart index 40eefde7..16292e09 100644 --- a/lib/components/content_banner.dart +++ b/lib/components/content_banner.dart @@ -1,4 +1,5 @@ import 'package:famedlysdk/famedlysdk.dart'; +import 'package:fluffychat/utils/platform_infos.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; @@ -48,11 +49,17 @@ class ContentBanner extends StatelessWidget { opacity: 0.75, child: !loading ? mxContent != null - ? CachedNetworkImage( - imageUrl: src, - height: 300, - fit: BoxFit.cover, - ) + ? PlatformInfos.isBetaDesktop + ? Image.network( + src, + height: 300, + fit: BoxFit.cover, + ) + : CachedNetworkImage( + imageUrl: src, + height: 300, + fit: BoxFit.cover, + ) : Icon(defaultIcon, size: 300) : Icon(defaultIcon, size: 300), ), diff --git a/lib/components/image_bubble.dart b/lib/components/image_bubble.dart index 92ce4184..5d12bddf 100644 --- a/lib/components/image_bubble.dart +++ b/lib/components/image_bubble.dart @@ -1,5 +1,6 @@ import 'package:famedlysdk/famedlysdk.dart'; import 'package:fluffychat/utils/app_route.dart'; +import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/views/image_view.dart'; import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; @@ -121,15 +122,22 @@ class _ImageBubbleState extends State { fit: widget.fit, ); } else if (isUnencrypted) { - renderWidget = CachedNetworkImage( - imageUrl: Uri.parse(widget.event.content['url']).getThumbnail( - widget.event.room.client, - width: 800, - height: 800, - method: ThumbnailMethod.scale), - placeholder: (context, url) => generatePlaceholderWidget(), - fit: widget.fit, - ); + final src = Uri.parse(widget.event.content['url']).getThumbnail( + widget.event.room.client, + width: 800, + height: 800, + method: ThumbnailMethod.scale); + renderWidget = PlatformInfos.isBetaDesktop + ? Image.network( + src, + fit: widget.fit, + ) + : CachedNetworkImage( + imageUrl: src, + placeholder: (context, url) => + generatePlaceholderWidget(), + fit: widget.fit, + ); } else { renderWidget = generatePlaceholderWidget(); } diff --git a/lib/components/input_bar.dart b/lib/components/input_bar.dart index 3daebaa1..ad1f40db 100644 --- a/lib/components/input_bar.dart +++ b/lib/components/input_bar.dart @@ -1,3 +1,4 @@ +import 'package:fluffychat/utils/platform_infos.dart'; import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:famedlysdk/famedlysdk.dart'; @@ -146,11 +147,17 @@ class InputBar extends StatelessWidget { child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ - CachedNetworkImage( - imageUrl: url, - width: size, - height: size, - ), + PlatformInfos.isBetaDesktop + ? Image.network( + url, + width: size, + height: size, + ) + : CachedNetworkImage( + imageUrl: url, + width: size, + height: size, + ), SizedBox(width: 6), Text(suggestion['name']), Expanded( diff --git a/lib/components/message_reactions.dart b/lib/components/message_reactions.dart index 26198914..cf09add0 100644 --- a/lib/components/message_reactions.dart +++ b/lib/components/message_reactions.dart @@ -1,4 +1,5 @@ import 'package:famedlysdk/famedlysdk.dart'; +import 'package:fluffychat/utils/platform_infos.dart'; import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; @@ -92,10 +93,15 @@ class _Reaction extends StatelessWidget { content = Row( mainAxisSize: MainAxisSize.min, children: [ - CachedNetworkImage( - imageUrl: src, - height: fontSize, - ), + PlatformInfos.isBetaDesktop + ? Image.network( + src, + height: fontSize, + ) + : CachedNetworkImage( + imageUrl: src, + height: fontSize, + ), Container(width: 4), Text(count.toString(), style: TextStyle( diff --git a/lib/utils/platform_infos.dart b/lib/utils/platform_infos.dart index 4c072b1d..5473a8cf 100644 --- a/lib/utils/platform_infos.dart +++ b/lib/utils/platform_infos.dart @@ -4,6 +4,12 @@ import 'package:flutter/foundation.dart'; abstract class PlatformInfos { static bool get isWeb => kIsWeb; + static bool get isMobile => !kIsWeb && (Platform.isAndroid || Platform.isIOS); + + /// For desktops which don't support ChachedNetworkImage yet + static bool get isBetaDesktop => + !kIsWeb && (Platform.isWindows || Platform.isLinux); + static bool get usesTouchscreen => !isMobile; } diff --git a/lib/views/settings_emotes.dart b/lib/views/settings_emotes.dart index 1f088e1a..9b5af891 100644 --- a/lib/views/settings_emotes.dart +++ b/lib/views/settings_emotes.dart @@ -1,6 +1,7 @@ import 'package:bot_toast/bot_toast.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:famedlysdk/famedlysdk.dart'; +import 'package:fluffychat/utils/platform_infos.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -415,12 +416,19 @@ class _EmoteImage extends StatelessWidget { height: size * devicePixelRatio, method: ThumbnailMethod.scale, ); - return CachedNetworkImage( - imageUrl: url, - fit: BoxFit.contain, - width: size, - height: size, - ); + return PlatformInfos.isBetaDesktop + ? Image.network( + url, + fit: BoxFit.contain, + width: size, + height: size, + ) + : CachedNetworkImage( + imageUrl: url, + fit: BoxFit.contain, + width: size, + height: size, + ); } } diff --git a/pubspec.lock b/pubspec.lock index 2d4e5781..b74b0f39 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1053,5 +1053,5 @@ packages: source: hosted version: "0.1.2" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.10.0-110 <=2.11.0-161.0.dev" flutter: ">=1.20.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 3ce587ec..d00bf06c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,7 +33,7 @@ dependencies: memoryfilepicker: ^0.1.3 url_launcher: ^5.4.1 url_launcher_web: ^0.1.0 - cached_network_image: ^2.3.1 + cached_network_image: ^2.3.2+1 firebase_messaging: ^7.0.2 flutter_local_notifications: ^1.4.3 matrix_link_text: ^0.1.5