fix: Desktop images

This commit is contained in:
Christian Pauly 2020-10-04 16:11:18 +02:00
parent 4f419f65c7
commit 5409fe864b
9 changed files with 79 additions and 32 deletions

View File

@ -1,4 +1,5 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/string_color.dart'; import 'package:fluffychat/utils/string_color.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -41,7 +42,11 @@ class Avatar extends StatelessWidget {
onTap: onTap, onTap: onTap,
child: CircleAvatar( child: CircleAvatar(
radius: size / 2, radius: size / 2,
backgroundImage: !noPic ? CachedNetworkImageProvider(src) : null, backgroundImage: !noPic
? PlatformInfos.isBetaDesktop
? NetworkImage(src)
: CachedNetworkImageProvider(src)
: null,
backgroundColor: noPic backgroundColor: noPic
? name?.lightColor ?? Theme.of(context).secondaryHeaderColor ? name?.lightColor ?? Theme.of(context).secondaryHeaderColor
: Theme.of(context).secondaryHeaderColor, : Theme.of(context).secondaryHeaderColor,

View File

@ -1,4 +1,5 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
@ -48,7 +49,13 @@ class ContentBanner extends StatelessWidget {
opacity: 0.75, opacity: 0.75,
child: !loading child: !loading
? mxContent != null ? mxContent != null
? CachedNetworkImage( ? PlatformInfos.isBetaDesktop
? Image.network(
src,
height: 300,
fit: BoxFit.cover,
)
: CachedNetworkImage(
imageUrl: src, imageUrl: src,
height: 300, height: 300,
fit: BoxFit.cover, fit: BoxFit.cover,

View File

@ -1,5 +1,6 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/app_route.dart'; import 'package:fluffychat/utils/app_route.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/views/image_view.dart'; import 'package:fluffychat/views/image_view.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -121,13 +122,20 @@ class _ImageBubbleState extends State<ImageBubble> {
fit: widget.fit, fit: widget.fit,
); );
} else if (isUnencrypted) { } else if (isUnencrypted) {
renderWidget = CachedNetworkImage( final src = Uri.parse(widget.event.content['url']).getThumbnail(
imageUrl: Uri.parse(widget.event.content['url']).getThumbnail(
widget.event.room.client, widget.event.room.client,
width: 800, width: 800,
height: 800, height: 800,
method: ThumbnailMethod.scale), method: ThumbnailMethod.scale);
placeholder: (context, url) => generatePlaceholderWidget(), renderWidget = PlatformInfos.isBetaDesktop
? Image.network(
src,
fit: widget.fit,
)
: CachedNetworkImage(
imageUrl: src,
placeholder: (context, url) =>
generatePlaceholderWidget(),
fit: widget.fit, fit: widget.fit,
); );
} else { } else {

View File

@ -1,3 +1,4 @@
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
@ -146,7 +147,13 @@ class InputBar extends StatelessWidget {
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
CachedNetworkImage( PlatformInfos.isBetaDesktop
? Image.network(
url,
width: size,
height: size,
)
: CachedNetworkImage(
imageUrl: url, imageUrl: url,
width: size, width: size,
height: size, height: size,

View File

@ -1,4 +1,5 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
@ -92,7 +93,12 @@ class _Reaction extends StatelessWidget {
content = Row( content = Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
CachedNetworkImage( PlatformInfos.isBetaDesktop
? Image.network(
src,
height: fontSize,
)
: CachedNetworkImage(
imageUrl: src, imageUrl: src,
height: fontSize, height: fontSize,
), ),

View File

@ -4,6 +4,12 @@ import 'package:flutter/foundation.dart';
abstract class PlatformInfos { abstract class PlatformInfos {
static bool get isWeb => kIsWeb; static bool get isWeb => kIsWeb;
static bool get isMobile => !kIsWeb && (Platform.isAndroid || Platform.isIOS); 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; static bool get usesTouchscreen => !isMobile;
} }

View File

@ -1,6 +1,7 @@
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
@ -415,7 +416,14 @@ class _EmoteImage extends StatelessWidget {
height: size * devicePixelRatio, height: size * devicePixelRatio,
method: ThumbnailMethod.scale, method: ThumbnailMethod.scale,
); );
return CachedNetworkImage( return PlatformInfos.isBetaDesktop
? Image.network(
url,
fit: BoxFit.contain,
width: size,
height: size,
)
: CachedNetworkImage(
imageUrl: url, imageUrl: url,
fit: BoxFit.contain, fit: BoxFit.contain,
width: size, width: size,

View File

@ -1053,5 +1053,5 @@ packages:
source: hosted source: hosted
version: "0.1.2" version: "0.1.2"
sdks: 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" flutter: ">=1.20.0 <2.0.0"

View File

@ -33,7 +33,7 @@ dependencies:
memoryfilepicker: ^0.1.3 memoryfilepicker: ^0.1.3
url_launcher: ^5.4.1 url_launcher: ^5.4.1
url_launcher_web: ^0.1.0 url_launcher_web: ^0.1.0
cached_network_image: ^2.3.1 cached_network_image: ^2.3.2+1
firebase_messaging: ^7.0.2 firebase_messaging: ^7.0.2
flutter_local_notifications: ^1.4.3 flutter_local_notifications: ^1.4.3
matrix_link_text: ^0.1.5 matrix_link_text: ^0.1.5