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. 13
      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) {
return ImageWrapper(
backgroundColor: Colors.white,
color: Colors.white,
borderRadius: borderRadius,
child: child,
);
@ -96,8 +96,10 @@ class FilePreview extends StatelessWidget {
),
],
if (previewLoading) ...[
const Center(
child: CustomLinearProgressIndicator(),
Center(
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) ...[
CachedURLImage(
url: article.mediaThumbnail!,
account: RxBlocProvider.of<AccountsBloc>(context).activeAccount.value!,
width: 100,
height: 50,
fit: BoxFit.cover,

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

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

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

@ -1,12 +1,10 @@
library notifications;
import 'package:flutter/material.dart';
import 'package:flutter_rx_bloc/flutter_rx_bloc.dart';
import 'package:intersperse/intersperse.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:neon/l10n/localizations.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/neon.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,
child: CachedURLImage(
url: notification.icon!,
account: RxBlocProvider.of<AccountsBloc>(context).activeAccount.value!,
width: 40,
height: 40,
color: Theme.of(context).colorScheme.primary,
svgColor: Theme.of(context).colorScheme.primary,
),
),
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(
child: CachedURLImage(
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
? CachedURLImage(
url: capabilitiesData!.capabilities!.theming!.logo!,
account: widget.account,
)
: null,
)

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

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

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

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

Loading…
Cancel
Save