fix: Desktop images

This commit is contained in:
Christian Pauly 2020-10-04 16:11:18 +02:00 committed by Inex Code
parent 46c606ef29
commit 95e130281e
8 changed files with 78 additions and 31 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,11 +49,17 @@ class ContentBanner extends StatelessWidget {
opacity: 0.75, opacity: 0.75,
child: !loading child: !loading
? mxContent != null ? mxContent != null
? CachedNetworkImage( ? PlatformInfos.isBetaDesktop
imageUrl: src, ? Image.network(
height: 300, src,
fit: BoxFit.cover, height: 300,
) fit: BoxFit.cover,
)
: CachedNetworkImage(
imageUrl: src,
height: 300,
fit: BoxFit.cover,
)
: Icon(defaultIcon, size: 300) : Icon(defaultIcon, size: 300)
: Icon(defaultIcon, size: 300), : Icon(defaultIcon, size: 300),
), ),

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,15 +122,22 @@ 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), renderWidget = PlatformInfos.isBetaDesktop
placeholder: (context, url) => generatePlaceholderWidget(), ? Image.network(
fit: widget.fit, src,
); fit: widget.fit,
)
: CachedNetworkImage(
imageUrl: src,
placeholder: (context, url) =>
generatePlaceholderWidget(),
fit: widget.fit,
);
} else { } else {
renderWidget = generatePlaceholderWidget(); renderWidget = generatePlaceholderWidget();
} }

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,11 +147,17 @@ class InputBar extends StatelessWidget {
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
CachedNetworkImage( PlatformInfos.isBetaDesktop
imageUrl: url, ? Image.network(
width: size, url,
height: size, width: size,
), height: size,
)
: CachedNetworkImage(
imageUrl: url,
width: size,
height: size,
),
SizedBox(width: 6), SizedBox(width: 6),
Text(suggestion['name']), Text(suggestion['name']),
Expanded( Expanded(

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,10 +93,15 @@ class _Reaction extends StatelessWidget {
content = Row( content = Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
CachedNetworkImage( PlatformInfos.isBetaDesktop
imageUrl: src, ? Image.network(
height: fontSize, src,
), height: fontSize,
)
: CachedNetworkImage(
imageUrl: src,
height: fontSize,
),
Container(width: 4), Container(width: 4),
Text(count.toString(), Text(count.toString(),
style: TextStyle( style: TextStyle(

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,12 +416,19 @@ class _EmoteImage extends StatelessWidget {
height: size * devicePixelRatio, height: size * devicePixelRatio,
method: ThumbnailMethod.scale, method: ThumbnailMethod.scale,
); );
return CachedNetworkImage( return PlatformInfos.isBetaDesktop
imageUrl: url, ? Image.network(
fit: BoxFit.contain, url,
width: size, fit: BoxFit.contain,
height: size, width: size,
); height: size,
)
: CachedNetworkImage(
imageUrl: url,
fit: BoxFit.contain,
width: size,
height: size,
);
} }
} }

View file

@ -31,7 +31,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