Browse Source

neon: Fix image handling

pull/76/head
jld3103 2 years ago
parent
commit
255de171d9
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 8
      packages/neon/lib/src/apps/files/widgets/file_preview.dart
  2. 1
      packages/neon/lib/src/apps/news/widgets/articles_view.dart
  3. 4
      packages/neon/lib/src/apps/news/widgets/feed_icon.dart
  4. 2
      packages/neon/lib/src/apps/notifications/app.dart
  5. 3
      packages/neon/lib/src/apps/notifications/pages/main.dart
  6. 2
      packages/neon/lib/src/pages/home/home.dart
  7. 22
      packages/neon/lib/src/widgets/cached_url_image.dart
  8. 17
      packages/neon/lib/src/widgets/image_wrapper.dart

8
packages/neon/lib/src/apps/files/widgets/file_preview.dart

@ -76,7 +76,7 @@ class FilePreview extends StatelessWidget {
); );
if (withBackground) { if (withBackground) {
return ImageWrapper( return ImageWrapper(
backgroundColor: Colors.white, color: Colors.white,
borderRadius: borderRadius, borderRadius: borderRadius,
child: child, child: child,
); );
@ -96,8 +96,10 @@ class FilePreview extends StatelessWidget {
), ),
], ],
if (previewLoading) ...[ if (previewLoading) ...[
const Center( Center(
child: CustomLinearProgressIndicator(), child: CustomLinearProgressIndicator(
color: color,
),
), ),
], ],
], ],

1
packages/neon/lib/src/apps/news/widgets/articles_view.dart

@ -181,7 +181,6 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
if (article.mediaThumbnail != null) ...[ if (article.mediaThumbnail != null) ...[
CachedURLImage( CachedURLImage(
url: article.mediaThumbnail!, url: article.mediaThumbnail!,
account: RxBlocProvider.of<AccountsBloc>(context).activeAccount.value!,
width: 100, width: 100,
height: 50, height: 50,
fit: BoxFit.cover, fit: BoxFit.cover,

4
packages/neon/lib/src/apps/news/widgets/feed_icon.dart

@ -14,16 +14,16 @@ class NewsFeedIcon extends StatelessWidget {
@override @override
Widget build(final BuildContext context) => ImageWrapper( Widget build(final BuildContext context) => ImageWrapper(
backgroundColor: Colors.white, color: Colors.white,
width: size, width: size,
height: size, height: size,
borderRadius: borderRadius, borderRadius: borderRadius,
child: feed.faviconLink != null && feed.faviconLink != '' child: feed.faviconLink != null && feed.faviconLink != ''
? CachedURLImage( ? CachedURLImage(
url: feed.faviconLink!, url: feed.faviconLink!,
account: RxBlocProvider.of<AccountsBloc>(context).activeAccount.value!,
height: size, height: size,
width: size, width: size,
iconColor: Theme.of(context).colorScheme.primary,
) )
: Icon( : Icon(
Icons.rss_feed, Icons.rss_feed,

2
packages/neon/lib/src/apps/notifications/app.dart

@ -1,12 +1,10 @@
library notifications; library notifications;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_rx_bloc/flutter_rx_bloc.dart';
import 'package:intersperse/intersperse.dart'; import 'package:intersperse/intersperse.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:neon/l10n/localizations.dart'; import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/apps/notifications/blocs/notifications.dart'; import 'package:neon/src/apps/notifications/blocs/notifications.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/blocs/apps.dart'; import 'package:neon/src/blocs/apps.dart';
import 'package:neon/src/neon.dart'; import 'package:neon/src/neon.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';

3
packages/neon/lib/src/apps/notifications/pages/main.dart

@ -115,10 +115,9 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
height: 40, height: 40,
child: CachedURLImage( child: CachedURLImage(
url: notification.icon!, url: notification.icon!,
account: RxBlocProvider.of<AccountsBloc>(context).activeAccount.value!,
width: 40, width: 40,
height: 40, height: 40,
color: Theme.of(context).colorScheme.primary, svgColor: Theme.of(context).colorScheme.primary,
), ),
), ),
onTap: () async { onTap: () async {

2
packages/neon/lib/src/pages/home/home.dart

@ -444,7 +444,6 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
Flexible( Flexible(
child: CachedURLImage( child: CachedURLImage(
url: capabilitiesData.capabilities!.theming!.logo!, url: capabilitiesData.capabilities!.theming!.logo!,
account: widget.account,
), ),
), ),
], ],
@ -630,7 +629,6 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
child: capabilitiesData?.capabilities?.theming?.logo != null child: capabilitiesData?.capabilities?.theming?.logo != null
? CachedURLImage( ? CachedURLImage(
url: capabilitiesData!.capabilities!.theming!.logo!, url: capabilitiesData!.capabilities!.theming!.logo!,
account: widget.account,
) )
: null, : null,
) )

22
packages/neon/lib/src/widgets/cached_url_image.dart

@ -5,32 +5,28 @@ final _cacheManager = DefaultCacheManager();
class CachedURLImage extends StatelessWidget { class CachedURLImage extends StatelessWidget {
const CachedURLImage({ const CachedURLImage({
required this.url, required this.url,
required this.account,
this.height, this.height,
this.width, this.width,
this.fit, this.fit,
this.color, this.svgColor,
this.iconColor,
super.key, super.key,
}); });
final String url; final String url;
final Account account;
final double? height; final double? height;
final double? width; final double? width;
final BoxFit? fit; final BoxFit? fit;
/// Only works for SVGs final Color? svgColor;
final Color? color; final Color? iconColor;
@override @override
Widget build(final BuildContext context) => FutureBuilder<File>( Widget build(final BuildContext context) => FutureBuilder<File>(
// Really weird false positive // Really weird false positive
// ignore: discarded_futures // ignore: discarded_futures
future: _cacheManager.getSingleFile( future: _cacheManager.getSingleFile(url),
url,
headers: account.client.baseHeaders,
),
builder: (final context, final fileSnapshot) { builder: (final context, final fileSnapshot) {
if (fileSnapshot.hasData) { if (fileSnapshot.hasData) {
final content = fileSnapshot.data!.readAsBytesSync(); final content = fileSnapshot.data!.readAsBytesSync();
@ -56,7 +52,7 @@ class CachedURLImage extends StatelessWidget {
height: height, height: height,
width: width, width: width,
fit: fit ?? BoxFit.contain, fit: fit ?? BoxFit.contain,
color: color, color: svgColor,
); );
} }
@ -65,17 +61,21 @@ class CachedURLImage extends StatelessWidget {
height: height, height: height,
width: width, width: width,
fit: fit, fit: fit,
gaplessPlayback: true,
); );
} }
if (fileSnapshot.hasError) { if (fileSnapshot.hasError) {
return Icon( return Icon(
Icons.error_outline, Icons.error_outline,
size: height != null && width != null ? min(height!, width!) : height ?? width, size: height != null && width != null ? min(height!, width!) : height ?? width,
color: iconColor,
); );
} }
return SizedBox( return SizedBox(
width: width, width: width,
child: const CustomLinearProgressIndicator(), child: CustomLinearProgressIndicator(
color: iconColor,
),
); );
}, },
); );

17
packages/neon/lib/src/widgets/image_wrapper.dart

@ -3,7 +3,7 @@ part of '../neon.dart';
class ImageWrapper extends StatelessWidget { class ImageWrapper extends StatelessWidget {
const ImageWrapper({ const ImageWrapper({
required this.child, required this.child,
required this.backgroundColor, required this.color,
this.width, this.width,
this.height, this.height,
this.borderRadius, this.borderRadius,
@ -11,7 +11,7 @@ class ImageWrapper extends StatelessWidget {
}); });
final Widget child; final Widget child;
final Color backgroundColor; final Color color;
final double? width; final double? width;
final double? height; final double? height;
final BorderRadius? borderRadius; final BorderRadius? borderRadius;
@ -20,14 +20,11 @@ class ImageWrapper extends StatelessWidget {
Widget build(final BuildContext context) => SizedBox( Widget build(final BuildContext context) => SizedBox(
width: width, width: width,
height: height, height: height,
child: DecoratedBox( child: ClipRRect(
decoration: BoxDecoration( borderRadius: borderRadius ?? BorderRadius.zero,
color: backgroundColor, child: ColoredBox(
borderRadius: borderRadius?.add(const BorderRadius.all(Radius.circular(1))), color: color,
), child: Center(
child: Center(
child: ClipRRect(
borderRadius: borderRadius ?? BorderRadius.zero,
child: child, child: child,
), ),
), ),

Loading…
Cancel
Save