diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index b51a2c14..f26ac609 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -3,7 +3,6 @@ library neon; import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'dart:math'; import 'package:crypto/crypto.dart'; import 'package:file_picker/file_picker.dart'; diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index f5fe073b..f3591072 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -526,8 +526,7 @@ class _HomePageState extends State { color: unreadCount > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onBackground, - width: kAvatarSize * 2 / 3, - height: kAvatarSize * 2 / 3, + size: const Size.square(kAvatarSize * 2 / 3), ), onPressed: () async { await _openNotifications( diff --git a/packages/neon/neon/lib/src/utils/app_implementation.dart b/packages/neon/neon/lib/src/utils/app_implementation.dart index a3159d40..4816408f 100644 --- a/packages/neon/neon/lib/src/utils/app_implementation.dart +++ b/packages/neon/neon/lib/src/utils/app_implementation.dart @@ -28,13 +28,11 @@ abstract class AppImplementation - SizedBox( - height: height, - width: width, + SizedBox.fromSize( + size: size, child: SvgPicture.asset( 'assets/app.svg', package: 'neon_$id', diff --git a/packages/neon/neon/lib/src/widgets/account_avatar.dart b/packages/neon/neon/lib/src/widgets/account_avatar.dart index 572e7fb8..c1364a4c 100644 --- a/packages/neon/neon/lib/src/widgets/account_avatar.dart +++ b/packages/neon/neon/lib/src/widgets/account_avatar.dart @@ -15,40 +15,38 @@ class NeonAccountAvatar extends StatelessWidget { final isDark = Theme.of(context).brightness == Brightness.dark; final size = (kAvatarSize * MediaQuery.of(context).devicePixelRatio).toInt(); final userStatusBloc = Provider.of(context, listen: false).getUserStatusBloc(account); - return Stack( - alignment: Alignment.center, - children: [ - CircleAvatar( - radius: kAvatarSize / 2, - child: ClipOval( - child: NeonCachedApiImage( - account: account, - cacheKey: 'avatar-${account.id}-${isDark ? 'dark' : 'light'}$size', - download: () async { - if (isDark) { - return account.client.core.getDarkAvatar( - userId: account.username, - size: size, - ); - } else { - return account.client.core.getAvatar( - userId: account.username, - size: size, - ); - } - }, + return SizedBox.square( + dimension: kAvatarSize, + child: Stack( + alignment: Alignment.center, + children: [ + CircleAvatar( + child: ClipOval( + child: NeonCachedApiImage( + account: account, + cacheKey: 'avatar-${account.id}-${isDark ? 'dark' : 'light'}$size', + download: () async { + if (isDark) { + return account.client.core.getDarkAvatar( + userId: account.username, + size: size, + ); + } else { + return account.client.core.getAvatar( + userId: account.username, + size: size, + ); + } + }, + ), ), ), - ), - ResultBuilder( - stream: userStatusBloc.userStatus, - builder: (final context, final userStatus) { - final hasEmoji = userStatus.data?.icon != null; - final factor = hasEmoji ? 2 : 3; - return SizedBox( - height: kAvatarSize, - width: kAvatarSize, - child: Align( + ResultBuilder( + stream: userStatusBloc.userStatus, + builder: (final context, final userStatus) { + final hasEmoji = userStatus.data?.icon != null; + final factor = hasEmoji ? 2 : 3; + return Align( alignment: Alignment.bottomRight, child: Container( height: kAvatarSize / factor, @@ -82,11 +80,11 @@ class NeonAccountAvatar extends StatelessWidget { ) : null, ), - ), - ); - }, - ), - ], + ); + }, + ), + ], + ), ); } diff --git a/packages/neon/neon/lib/src/widgets/app_implementation_icon.dart b/packages/neon/neon/lib/src/widgets/app_implementation_icon.dart index 3b9e56c2..8434e778 100644 --- a/packages/neon/neon/lib/src/widgets/app_implementation_icon.dart +++ b/packages/neon/neon/lib/src/widgets/app_implementation_icon.dart @@ -5,8 +5,7 @@ class NeonAppImplementationIcon extends StatelessWidget { required this.appImplementation, this.unreadCount = 0, this.color, - this.width = kAvatarSize, - this.height = kAvatarSize, + this.size = const Size.square(kAvatarSize), super.key, }); @@ -16,9 +15,7 @@ class NeonAppImplementationIcon extends StatelessWidget { final Color? color; - final double width; - - final double height; + final Size size; @override Widget build(final BuildContext context) => Stack( @@ -28,8 +25,7 @@ class NeonAppImplementationIcon extends StatelessWidget { margin: const EdgeInsets.all(5), child: appImplementation.buildIcon( context, - height: height, - width: width, + size: size, color: color, ), ), diff --git a/packages/neon/neon/lib/src/widgets/cached_api_image.dart b/packages/neon/neon/lib/src/widgets/cached_api_image.dart index 5e27e3ae..307d48dc 100644 --- a/packages/neon/neon/lib/src/widgets/cached_api_image.dart +++ b/packages/neon/neon/lib/src/widgets/cached_api_image.dart @@ -8,8 +8,7 @@ class NeonCachedApiImage extends NeonCachedImage { required final String cacheKey, required final APIImageDownloader download, final String? etag, - super.height, - super.width, + super.size, super.fit, super.svgColor, super.iconColor, diff --git a/packages/neon/neon/lib/src/widgets/cached_image.dart b/packages/neon/neon/lib/src/widgets/cached_image.dart index 598c83ba..3b6dcc87 100644 --- a/packages/neon/neon/lib/src/widgets/cached_image.dart +++ b/packages/neon/neon/lib/src/widgets/cached_image.dart @@ -6,8 +6,7 @@ abstract class NeonCachedImage extends StatefulWidget { const NeonCachedImage({ required this.getImageFile, this.isSvgHint = false, - this.height, - this.width, + this.size, this.fit, this.svgColor, this.iconColor, @@ -17,8 +16,7 @@ abstract class NeonCachedImage extends StatefulWidget { final Future Function() getImageFile; final bool isSvgHint; - final double? height; - final double? width; + final Size? size; final BoxFit? fit; final Color? svgColor; @@ -44,8 +42,8 @@ class _NeonCachedImageState extends State { if (widget.isSvgHint || utf8.decode(content).contains(' { return Image.memory( content, - height: widget.height, - width: widget.width, + height: widget.size?.height, + width: widget.size?.width, fit: widget.fit, gaplessPlayback: true, ); @@ -72,14 +70,12 @@ class _NeonCachedImageState extends State { }); }, onlyIcon: true, - iconSize: widget.height != null && widget.width != null - ? min(widget.height!, widget.width!) - : widget.height ?? widget.width, + iconSize: widget.size?.shortestSide, color: widget.iconColor ?? Colors.red, ); } return SizedBox( - width: widget.width, + width: widget.size?.width, child: NeonLinearProgressIndicator( color: widget.iconColor, ), diff --git a/packages/neon/neon/lib/src/widgets/cached_url_image.dart b/packages/neon/neon/lib/src/widgets/cached_url_image.dart index 19fe4d7c..6e66e6ee 100644 --- a/packages/neon/neon/lib/src/widgets/cached_url_image.dart +++ b/packages/neon/neon/lib/src/widgets/cached_url_image.dart @@ -3,8 +3,7 @@ part of '../../neon.dart'; class NeonCachedUrlImage extends NeonCachedImage { NeonCachedUrlImage({ required final String url, - super.height, - super.width, + super.size, super.fit, super.svgColor, super.iconColor, diff --git a/packages/neon/neon/lib/src/widgets/image_wrapper.dart b/packages/neon/neon/lib/src/widgets/image_wrapper.dart index 8edbee85..69fe4005 100644 --- a/packages/neon/neon/lib/src/widgets/image_wrapper.dart +++ b/packages/neon/neon/lib/src/widgets/image_wrapper.dart @@ -4,22 +4,19 @@ class NeonImageWrapper extends StatelessWidget { const NeonImageWrapper({ required this.child, required this.color, - this.width, - this.height, + this.size, this.borderRadius, super.key, }); final Widget child; final Color color; - final double? width; - final double? height; + final Size? size; final BorderRadius? borderRadius; @override - Widget build(final BuildContext context) => SizedBox( - width: width, - height: height, + Widget build(final BuildContext context) => SizedBox.fromSize( + size: size, child: ClipRRect( borderRadius: borderRadius ?? BorderRadius.zero, child: ColoredBox( diff --git a/packages/neon/neon_files/lib/neon_files.dart b/packages/neon/neon_files/lib/neon_files.dart index e823d59c..9a6d7de5 100644 --- a/packages/neon/neon_files/lib/neon_files.dart +++ b/packages/neon/neon_files/lib/neon_files.dart @@ -2,7 +2,6 @@ library neon_files; import 'dart:async'; import 'dart:io'; -import 'dart:math'; import 'dart:typed_data'; import 'package:collection/collection.dart'; diff --git a/packages/neon/neon_files/lib/pages/details.dart b/packages/neon/neon_files/lib/pages/details.dart index 7fb0baa3..e63004df 100644 --- a/packages/neon/neon_files/lib/pages/details.dart +++ b/packages/neon/neon_files/lib/pages/details.dart @@ -27,8 +27,10 @@ class FilesDetailsPage extends StatelessWidget { bloc: bloc, details: details, color: Theme.of(context).colorScheme.onPrimary, - width: MediaQuery.of(context).size.width.toInt(), - height: MediaQuery.of(context).size.height ~/ 4, + size: Size( + MediaQuery.of(context).size.width, + MediaQuery.of(context).size.height / 4, + ), ), ), DataTable( diff --git a/packages/neon/neon_files/lib/widgets/browser_view.dart b/packages/neon/neon_files/lib/widgets/browser_view.dart index 5c8a3f8d..cca47e36 100644 --- a/packages/neon/neon_files/lib/widgets/browser_view.dart +++ b/packages/neon/neon_files/lib/widgets/browser_view.dart @@ -252,9 +252,8 @@ class _FilesBrowserViewState extends State { ], ], ), - leading: SizedBox( - height: 40, - width: 40, + leading: SizedBox.square( + dimension: 40, child: Stack( children: [ Center( @@ -429,9 +428,8 @@ class _FilesBrowserViewState extends State { } }, ) - : const SizedBox( - width: 48, - height: 48, + : const SizedBox.square( + dimension: 48, ), ); } diff --git a/packages/neon/neon_files/lib/widgets/file_preview.dart b/packages/neon/neon_files/lib/widgets/file_preview.dart index 2a8d019c..9de089af 100644 --- a/packages/neon/neon_files/lib/widgets/file_preview.dart +++ b/packages/neon/neon_files/lib/widgets/file_preview.dart @@ -4,8 +4,7 @@ class FilePreview extends StatelessWidget { const FilePreview({ required this.bloc, required this.details, - this.width = 40, - this.height = 40, + this.size = const Size.square(40), this.color, this.borderRadius, this.withBackground = false, @@ -17,18 +16,19 @@ class FilePreview extends StatelessWidget { final FilesBloc bloc; final FileDetails details; - final int width; - final int height; + final Size size; final Color? color; final BorderRadius? borderRadius; final bool withBackground; + int get width => size.width.toInt(); + int get height => size.height.toInt(); + @override Widget build(final BuildContext context) { final color = this.color ?? Theme.of(context).colorScheme.primary; - return SizedBox( - width: width.toDouble(), - height: height.toDouble(), + return SizedBox.fromSize( + size: size, child: StreamBuilder( stream: bloc.options.showPreviewsOption.stream, builder: (final context, final showPreviewsSnapshot) { @@ -58,14 +58,14 @@ class FilePreview extends StatelessWidget { return Icon( MdiIcons.folder, color: color, - size: min(width.toDouble(), height.toDouble()), + size: size.shortestSide, ); } return FileIcon( details.name, color: color, - size: min(width.toDouble(), height.toDouble()), + size: size.shortestSide, ); }, ), diff --git a/packages/neon/neon_news/lib/widgets/articles_view.dart b/packages/neon/neon_news/lib/widgets/articles_view.dart index f4159573..d7785a76 100644 --- a/packages/neon/neon_news/lib/widgets/articles_view.dart +++ b/packages/neon/neon_news/lib/widgets/articles_view.dart @@ -121,8 +121,7 @@ class _NewsArticlesViewState extends State { if (article.mediaThumbnail != null) ...[ NeonCachedUrlImage( url: article.mediaThumbnail!, - width: 100, - height: 50, + size: const Size(100, 50), fit: BoxFit.cover, ), ], @@ -138,7 +137,7 @@ class _NewsArticlesViewState extends State { ), child: NewsFeedIcon( feed: feed, - size: 16, + icon: 16, borderRadius: const BorderRadius.all(Radius.circular(2)), ), ), diff --git a/packages/neon/neon_news/lib/widgets/feed_icon.dart b/packages/neon/neon_news/lib/widgets/feed_icon.dart index b576b3d1..cbe50f9e 100644 --- a/packages/neon/neon_news/lib/widgets/feed_icon.dart +++ b/packages/neon/neon_news/lib/widgets/feed_icon.dart @@ -3,31 +3,29 @@ part of '../neon_news.dart'; class NewsFeedIcon extends StatelessWidget { const NewsFeedIcon({ required this.feed, - this.size = 48, + this.icon = 48, this.borderRadius, super.key, }); final NextcloudNewsFeed feed; - final double size; + final double icon; final BorderRadius? borderRadius; @override Widget build(final BuildContext context) => NeonImageWrapper( color: Colors.white, - width: size, - height: size, + size: Size.square(icon), borderRadius: borderRadius, child: feed.faviconLink != null && feed.faviconLink != '' ? NeonCachedUrlImage( url: feed.faviconLink!, - height: size, - width: size, + size: Size.square(icon), iconColor: Theme.of(context).colorScheme.primary, ) : Icon( Icons.rss_feed, - size: size, + size: icon, color: Theme.of(context).colorScheme.primary, ), ); diff --git a/packages/neon/neon_news/lib/widgets/folders_view.dart b/packages/neon/neon_news/lib/widgets/folders_view.dart index eca3c8e9..8e40ee26 100644 --- a/packages/neon/neon_news/lib/widgets/folders_view.dart +++ b/packages/neon/neon_news/lib/widgets/folders_view.dart @@ -72,9 +72,8 @@ class NewsFoldersView extends StatelessWidget { AppLocalizations.of(context).newsUnreadArticles(unreadCount), ) : Container(), - leading: SizedBox( - width: 48, - height: 48, + leading: SizedBox.square( + dimension: 48, child: Stack( children: [ Icon( diff --git a/packages/neon/neon_notes/lib/widgets/categories_view.dart b/packages/neon/neon_notes/lib/widgets/categories_view.dart index 38a267d8..be1435ff 100644 --- a/packages/neon/neon_notes/lib/widgets/categories_view.dart +++ b/packages/neon/neon_notes/lib/widgets/categories_view.dart @@ -49,10 +49,7 @@ class NotesCategoriesView extends StatelessWidget { size: 40, color: NotesCategoryColor.compute(category.name), ) - : const SizedBox( - height: 40, - width: 40, - ), + : const SizedBox.square(dimension: 40), onTap: () async { await Navigator.of(context).push( MaterialPageRoute( diff --git a/packages/neon/neon_notifications/lib/pages/main.dart b/packages/neon/neon_notifications/lib/pages/main.dart index c04e98e1..61a8ab73 100644 --- a/packages/neon/neon_notifications/lib/pages/main.dart +++ b/packages/neon/neon_notifications/lib/pages/main.dart @@ -74,16 +74,13 @@ class _NotificationsMainPageState extends State { leading: app != null ? app.buildIcon( context, - width: 40, - height: 40, + size: const Size.square(40), ) - : SizedBox( - width: 40, - height: 40, + : SizedBox.fromSize( + size: const Size.square(40), child: NeonCachedUrlImage( url: notification.icon!, - width: 40, - height: 40, + size: const Size.square(40), svgColor: Theme.of(context).colorScheme.primary, ), ),