From 455952aa9598ccfad3c6336a793a35182fef64b9 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 3 Aug 2022 21:11:11 +0200 Subject: [PATCH] neon: Fix feed icon border radius and file preview background --- .../src/apps/files/widgets/browser_view.dart | 1 + .../src/apps/files/widgets/file_preview.dart | 36 +++++++++++------- .../lib/src/apps/news/widgets/feed_icon.dart | 38 ++++++++----------- packages/neon/lib/src/neon.dart | 1 + .../neon/lib/src/widgets/image_wrapper.dart | 36 ++++++++++++++++++ 5 files changed, 77 insertions(+), 35 deletions(-) create mode 100644 packages/neon/lib/src/widgets/image_wrapper.dart diff --git a/packages/neon/lib/src/apps/files/widgets/browser_view.dart b/packages/neon/lib/src/apps/files/widgets/browser_view.dart index fbc53852..2b3b51d6 100644 --- a/packages/neon/lib/src/apps/files/widgets/browser_view.dart +++ b/packages/neon/lib/src/apps/files/widgets/browser_view.dart @@ -303,6 +303,7 @@ class _FilesBrowserViewState extends State { : FilePreview( bloc: widget.filesBloc, details: details, + withBackground: true, borderRadius: const BorderRadius.all(Radius.circular(8)), ), ), diff --git a/packages/neon/lib/src/apps/files/widgets/file_preview.dart b/packages/neon/lib/src/apps/files/widgets/file_preview.dart index f9da8b49..2b94277f 100644 --- a/packages/neon/lib/src/apps/files/widgets/file_preview.dart +++ b/packages/neon/lib/src/apps/files/widgets/file_preview.dart @@ -8,8 +8,12 @@ class FilePreview extends StatelessWidget { this.height = 40, this.color, this.borderRadius, + this.withBackground = false, super.key, - }); + }) : assert( + (borderRadius != null && withBackground) || borderRadius == null, + 'withBackground needs to be true when borderRadius is set', + ); final FilesBloc bloc; final FileDetails details; @@ -17,6 +21,7 @@ class FilePreview extends StatelessWidget { final int height; final Color? color; final BorderRadius? borderRadius; + final bool withBackground; @override Widget build(BuildContext context) { @@ -61,18 +66,23 @@ class FilePreview extends StatelessWidget { children: [ if (previewData != null) ...[ Center( - child: SizedBox( - width: width.toDouble(), - height: height.toDouble(), - child: DecoratedBox( - decoration: BoxDecoration( - borderRadius: borderRadius, - image: DecorationImage( - image: MemoryImage(previewData), - fit: BoxFit.cover, - ), - ), - ), + child: Builder( + builder: (final context) { + final child = Image.memory( + previewData, + fit: BoxFit.cover, + width: width.toDouble(), + height: height.toDouble(), + ); + if (withBackground) { + return ImageWrapper( + backgroundColor: Colors.white, + borderRadius: borderRadius, + child: child, + ); + } + return child; + }, ), ), ], diff --git a/packages/neon/lib/src/apps/news/widgets/feed_icon.dart b/packages/neon/lib/src/apps/news/widgets/feed_icon.dart index 40613ed8..de6925a2 100644 --- a/packages/neon/lib/src/apps/news/widgets/feed_icon.dart +++ b/packages/neon/lib/src/apps/news/widgets/feed_icon.dart @@ -13,29 +13,23 @@ class NewsFeedIcon extends StatelessWidget { final BorderRadius? borderRadius; @override - Widget build(final BuildContext context) => SizedBox( + Widget build(final BuildContext context) => ImageWrapper( + backgroundColor: Colors.white, width: size, height: size, - child: DecoratedBox( - decoration: BoxDecoration( - color: Colors.white, - borderRadius: borderRadius, - ), - child: Center( - child: feed.faviconLink != null && feed.faviconLink != '' - ? CachedURLImage( - url: feed.faviconLink!, - requestManager: Provider.of(context), - client: RxBlocProvider.of(context).activeAccount.value!.client, - height: size, - width: size, - ) - : Icon( - Icons.rss_feed, - size: size, - color: Theme.of(context).colorScheme.primary, - ), - ), - ), + borderRadius: borderRadius, + child: feed.faviconLink != null && feed.faviconLink != '' + ? CachedURLImage( + url: feed.faviconLink!, + requestManager: Provider.of(context), + client: RxBlocProvider.of(context).activeAccount.value!.client, + height: size, + width: size, + ) + : Icon( + Icons.rss_feed, + size: size, + color: Theme.of(context).colorScheme.primary, + ), ); } diff --git a/packages/neon/lib/src/neon.dart b/packages/neon/lib/src/neon.dart index e8b11212..53784eff 100644 --- a/packages/neon/lib/src/neon.dart +++ b/packages/neon/lib/src/neon.dart @@ -91,6 +91,7 @@ part 'widgets/custom_dialog.dart'; part 'widgets/custom_linear_progress_indicator.dart'; part 'widgets/custom_listview.dart'; part 'widgets/exception.dart'; +part 'widgets/image_wrapper.dart'; part 'widgets/neon_logo.dart'; part 'widgets/nextcloud_logo.dart'; part 'widgets/result_stream_builder.dart'; diff --git a/packages/neon/lib/src/widgets/image_wrapper.dart b/packages/neon/lib/src/widgets/image_wrapper.dart new file mode 100644 index 00000000..05d49812 --- /dev/null +++ b/packages/neon/lib/src/widgets/image_wrapper.dart @@ -0,0 +1,36 @@ +part of '../neon.dart'; + +class ImageWrapper extends StatelessWidget { + const ImageWrapper({ + required this.child, + required this.backgroundColor, + this.width, + this.height, + this.borderRadius, + super.key, + }); + + final Widget child; + final Color backgroundColor; + final double? width; + final double? height; + final BorderRadius? borderRadius; + + @override + Widget build(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: child, + ), + ), + ), + ); +}