Browse Source

Merge pull request #295 from Leptopoda/cleanup/use_size

neon: use Size class for sizes
pull/308/head
Nikolas Rimikis 2 years ago committed by GitHub
parent
commit
ae383f95b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/neon/neon/lib/neon.dart
  2. 3
      packages/neon/neon/lib/src/pages/home.dart
  3. 8
      packages/neon/neon/lib/src/utils/app_implementation.dart
  4. 72
      packages/neon/neon/lib/src/widgets/account_avatar.dart
  5. 10
      packages/neon/neon/lib/src/widgets/app_implementation_icon.dart
  6. 3
      packages/neon/neon/lib/src/widgets/cached_api_image.dart
  7. 20
      packages/neon/neon/lib/src/widgets/cached_image.dart
  8. 3
      packages/neon/neon/lib/src/widgets/cached_url_image.dart
  9. 11
      packages/neon/neon/lib/src/widgets/image_wrapper.dart
  10. 1
      packages/neon/neon_files/lib/neon_files.dart
  11. 6
      packages/neon/neon_files/lib/pages/details.dart
  12. 10
      packages/neon/neon_files/lib/widgets/browser_view.dart
  13. 18
      packages/neon/neon_files/lib/widgets/file_preview.dart
  14. 5
      packages/neon/neon_news/lib/widgets/articles_view.dart
  15. 12
      packages/neon/neon_news/lib/widgets/feed_icon.dart
  16. 5
      packages/neon/neon_news/lib/widgets/folders_view.dart
  17. 5
      packages/neon/neon_notes/lib/widgets/categories_view.dart
  18. 11
      packages/neon/neon_notifications/lib/pages/main.dart

1
packages/neon/neon/lib/neon.dart

@ -3,7 +3,6 @@ library neon;
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:math';
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';

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

@ -526,8 +526,7 @@ class _HomePageState extends State<HomePage> {
color: unreadCount > 0 color: unreadCount > 0
? Theme.of(context).colorScheme.primary ? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onBackground, : Theme.of(context).colorScheme.onBackground,
width: kAvatarSize * 2 / 3, size: const Size.square(kAvatarSize * 2 / 3),
height: kAvatarSize * 2 / 3,
), ),
onPressed: () async { onPressed: () async {
await _openNotifications( await _openNotifications(

8
packages/neon/neon/lib/src/utils/app_implementation.dart

@ -28,13 +28,11 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppSpecificO
Widget buildIcon( Widget buildIcon(
final BuildContext context, { final BuildContext context, {
final double height = 32, final Size size = const Size.square(32),
final double width = 32,
final Color? color, final Color? color,
}) => }) =>
SizedBox( SizedBox.fromSize(
height: height, size: size,
width: width,
child: SvgPicture.asset( child: SvgPicture.asset(
'assets/app.svg', 'assets/app.svg',
package: 'neon_$id', package: 'neon_$id',

72
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 isDark = Theme.of(context).brightness == Brightness.dark;
final size = (kAvatarSize * MediaQuery.of(context).devicePixelRatio).toInt(); final size = (kAvatarSize * MediaQuery.of(context).devicePixelRatio).toInt();
final userStatusBloc = Provider.of<AccountsBloc>(context, listen: false).getUserStatusBloc(account); final userStatusBloc = Provider.of<AccountsBloc>(context, listen: false).getUserStatusBloc(account);
return Stack( return SizedBox.square(
alignment: Alignment.center, dimension: kAvatarSize,
children: [ child: Stack(
CircleAvatar( alignment: Alignment.center,
radius: kAvatarSize / 2, children: [
child: ClipOval( CircleAvatar(
child: NeonCachedApiImage( child: ClipOval(
account: account, child: NeonCachedApiImage(
cacheKey: 'avatar-${account.id}-${isDark ? 'dark' : 'light'}$size', account: account,
download: () async { cacheKey: 'avatar-${account.id}-${isDark ? 'dark' : 'light'}$size',
if (isDark) { download: () async {
return account.client.core.getDarkAvatar( if (isDark) {
userId: account.username, return account.client.core.getDarkAvatar(
size: size, userId: account.username,
); size: size,
} else { );
return account.client.core.getAvatar( } else {
userId: account.username, return account.client.core.getAvatar(
size: size, userId: account.username,
); size: size,
} );
}, }
},
),
), ),
), ),
), ResultBuilder<UserStatusBloc, NextcloudUserStatusStatus?>(
ResultBuilder<UserStatusBloc, NextcloudUserStatusStatus?>( stream: userStatusBloc.userStatus,
stream: userStatusBloc.userStatus, builder: (final context, final userStatus) {
builder: (final context, final userStatus) { final hasEmoji = userStatus.data?.icon != null;
final hasEmoji = userStatus.data?.icon != null; final factor = hasEmoji ? 2 : 3;
final factor = hasEmoji ? 2 : 3; return Align(
return SizedBox(
height: kAvatarSize,
width: kAvatarSize,
child: Align(
alignment: Alignment.bottomRight, alignment: Alignment.bottomRight,
child: Container( child: Container(
height: kAvatarSize / factor, height: kAvatarSize / factor,
@ -82,11 +80,11 @@ class NeonAccountAvatar extends StatelessWidget {
) )
: null, : null,
), ),
), );
); },
}, ),
), ],
], ),
); );
} }

10
packages/neon/neon/lib/src/widgets/app_implementation_icon.dart

@ -5,8 +5,7 @@ class NeonAppImplementationIcon extends StatelessWidget {
required this.appImplementation, required this.appImplementation,
this.unreadCount = 0, this.unreadCount = 0,
this.color, this.color,
this.width = kAvatarSize, this.size = const Size.square(kAvatarSize),
this.height = kAvatarSize,
super.key, super.key,
}); });
@ -16,9 +15,7 @@ class NeonAppImplementationIcon extends StatelessWidget {
final Color? color; final Color? color;
final double width; final Size size;
final double height;
@override @override
Widget build(final BuildContext context) => Stack( Widget build(final BuildContext context) => Stack(
@ -28,8 +25,7 @@ class NeonAppImplementationIcon extends StatelessWidget {
margin: const EdgeInsets.all(5), margin: const EdgeInsets.all(5),
child: appImplementation.buildIcon( child: appImplementation.buildIcon(
context, context,
height: height, size: size,
width: width,
color: color, color: color,
), ),
), ),

3
packages/neon/neon/lib/src/widgets/cached_api_image.dart

@ -8,8 +8,7 @@ class NeonCachedApiImage extends NeonCachedImage {
required final String cacheKey, required final String cacheKey,
required final APIImageDownloader download, required final APIImageDownloader download,
final String? etag, final String? etag,
super.height, super.size,
super.width,
super.fit, super.fit,
super.svgColor, super.svgColor,
super.iconColor, super.iconColor,

20
packages/neon/neon/lib/src/widgets/cached_image.dart

@ -6,8 +6,7 @@ abstract class NeonCachedImage extends StatefulWidget {
const NeonCachedImage({ const NeonCachedImage({
required this.getImageFile, required this.getImageFile,
this.isSvgHint = false, this.isSvgHint = false,
this.height, this.size,
this.width,
this.fit, this.fit,
this.svgColor, this.svgColor,
this.iconColor, this.iconColor,
@ -17,8 +16,7 @@ abstract class NeonCachedImage extends StatefulWidget {
final Future<File> Function() getImageFile; final Future<File> Function() getImageFile;
final bool isSvgHint; final bool isSvgHint;
final double? height; final Size? size;
final double? width;
final BoxFit? fit; final BoxFit? fit;
final Color? svgColor; final Color? svgColor;
@ -44,8 +42,8 @@ class _NeonCachedImageState extends State<NeonCachedImage> {
if (widget.isSvgHint || utf8.decode(content).contains('<svg')) { if (widget.isSvgHint || utf8.decode(content).contains('<svg')) {
return SvgPicture.memory( return SvgPicture.memory(
content, content,
height: widget.height, height: widget.size?.height,
width: widget.width, width: widget.size?.width,
fit: widget.fit ?? BoxFit.contain, fit: widget.fit ?? BoxFit.contain,
color: widget.svgColor, color: widget.svgColor,
); );
@ -56,8 +54,8 @@ class _NeonCachedImageState extends State<NeonCachedImage> {
return Image.memory( return Image.memory(
content, content,
height: widget.height, height: widget.size?.height,
width: widget.width, width: widget.size?.width,
fit: widget.fit, fit: widget.fit,
gaplessPlayback: true, gaplessPlayback: true,
); );
@ -72,14 +70,12 @@ class _NeonCachedImageState extends State<NeonCachedImage> {
}); });
}, },
onlyIcon: true, onlyIcon: true,
iconSize: widget.height != null && widget.width != null iconSize: widget.size?.shortestSide,
? min(widget.height!, widget.width!)
: widget.height ?? widget.width,
color: widget.iconColor ?? Colors.red, color: widget.iconColor ?? Colors.red,
); );
} }
return SizedBox( return SizedBox(
width: widget.width, width: widget.size?.width,
child: NeonLinearProgressIndicator( child: NeonLinearProgressIndicator(
color: widget.iconColor, color: widget.iconColor,
), ),

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

@ -3,8 +3,7 @@ part of '../../neon.dart';
class NeonCachedUrlImage extends NeonCachedImage { class NeonCachedUrlImage extends NeonCachedImage {
NeonCachedUrlImage({ NeonCachedUrlImage({
required final String url, required final String url,
super.height, super.size,
super.width,
super.fit, super.fit,
super.svgColor, super.svgColor,
super.iconColor, super.iconColor,

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

@ -4,22 +4,19 @@ class NeonImageWrapper extends StatelessWidget {
const NeonImageWrapper({ const NeonImageWrapper({
required this.child, required this.child,
required this.color, required this.color,
this.width, this.size,
this.height,
this.borderRadius, this.borderRadius,
super.key, super.key,
}); });
final Widget child; final Widget child;
final Color color; final Color color;
final double? width; final Size? size;
final double? height;
final BorderRadius? borderRadius; final BorderRadius? borderRadius;
@override @override
Widget build(final BuildContext context) => SizedBox( Widget build(final BuildContext context) => SizedBox.fromSize(
width: width, size: size,
height: height,
child: ClipRRect( child: ClipRRect(
borderRadius: borderRadius ?? BorderRadius.zero, borderRadius: borderRadius ?? BorderRadius.zero,
child: ColoredBox( child: ColoredBox(

1
packages/neon/neon_files/lib/neon_files.dart

@ -2,7 +2,6 @@ library neon_files;
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'dart:math';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';

6
packages/neon/neon_files/lib/pages/details.dart

@ -27,8 +27,10 @@ class FilesDetailsPage extends StatelessWidget {
bloc: bloc, bloc: bloc,
details: details, details: details,
color: Theme.of(context).colorScheme.onPrimary, color: Theme.of(context).colorScheme.onPrimary,
width: MediaQuery.of(context).size.width.toInt(), size: Size(
height: MediaQuery.of(context).size.height ~/ 4, MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height / 4,
),
), ),
), ),
DataTable( DataTable(

10
packages/neon/neon_files/lib/widgets/browser_view.dart

@ -252,9 +252,8 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
], ],
], ],
), ),
leading: SizedBox( leading: SizedBox.square(
height: 40, dimension: 40,
width: 40,
child: Stack( child: Stack(
children: [ children: [
Center( Center(
@ -429,9 +428,8 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
} }
}, },
) )
: const SizedBox( : const SizedBox.square(
width: 48, dimension: 48,
height: 48,
), ),
); );
} }

18
packages/neon/neon_files/lib/widgets/file_preview.dart

@ -4,8 +4,7 @@ class FilePreview extends StatelessWidget {
const FilePreview({ const FilePreview({
required this.bloc, required this.bloc,
required this.details, required this.details,
this.width = 40, this.size = const Size.square(40),
this.height = 40,
this.color, this.color,
this.borderRadius, this.borderRadius,
this.withBackground = false, this.withBackground = false,
@ -17,18 +16,19 @@ class FilePreview extends StatelessWidget {
final FilesBloc bloc; final FilesBloc bloc;
final FileDetails details; final FileDetails details;
final int width; final Size size;
final int height;
final Color? color; final Color? color;
final BorderRadius? borderRadius; final BorderRadius? borderRadius;
final bool withBackground; final bool withBackground;
int get width => size.width.toInt();
int get height => size.height.toInt();
@override @override
Widget build(final BuildContext context) { Widget build(final BuildContext context) {
final color = this.color ?? Theme.of(context).colorScheme.primary; final color = this.color ?? Theme.of(context).colorScheme.primary;
return SizedBox( return SizedBox.fromSize(
width: width.toDouble(), size: size,
height: height.toDouble(),
child: StreamBuilder<bool?>( child: StreamBuilder<bool?>(
stream: bloc.options.showPreviewsOption.stream, stream: bloc.options.showPreviewsOption.stream,
builder: (final context, final showPreviewsSnapshot) { builder: (final context, final showPreviewsSnapshot) {
@ -58,14 +58,14 @@ class FilePreview extends StatelessWidget {
return Icon( return Icon(
MdiIcons.folder, MdiIcons.folder,
color: color, color: color,
size: min(width.toDouble(), height.toDouble()), size: size.shortestSide,
); );
} }
return FileIcon( return FileIcon(
details.name, details.name,
color: color, color: color,
size: min(width.toDouble(), height.toDouble()), size: size.shortestSide,
); );
}, },
), ),

5
packages/neon/neon_news/lib/widgets/articles_view.dart

@ -121,8 +121,7 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
if (article.mediaThumbnail != null) ...[ if (article.mediaThumbnail != null) ...[
NeonCachedUrlImage( NeonCachedUrlImage(
url: article.mediaThumbnail!, url: article.mediaThumbnail!,
width: 100, size: const Size(100, 50),
height: 50,
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
], ],
@ -138,7 +137,7 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
), ),
child: NewsFeedIcon( child: NewsFeedIcon(
feed: feed, feed: feed,
size: 16, icon: 16,
borderRadius: const BorderRadius.all(Radius.circular(2)), borderRadius: const BorderRadius.all(Radius.circular(2)),
), ),
), ),

12
packages/neon/neon_news/lib/widgets/feed_icon.dart

@ -3,31 +3,29 @@ part of '../neon_news.dart';
class NewsFeedIcon extends StatelessWidget { class NewsFeedIcon extends StatelessWidget {
const NewsFeedIcon({ const NewsFeedIcon({
required this.feed, required this.feed,
this.size = 48, this.icon = 48,
this.borderRadius, this.borderRadius,
super.key, super.key,
}); });
final NextcloudNewsFeed feed; final NextcloudNewsFeed feed;
final double size; final double icon;
final BorderRadius? borderRadius; final BorderRadius? borderRadius;
@override @override
Widget build(final BuildContext context) => NeonImageWrapper( Widget build(final BuildContext context) => NeonImageWrapper(
color: Colors.white, color: Colors.white,
width: size, size: Size.square(icon),
height: size,
borderRadius: borderRadius, borderRadius: borderRadius,
child: feed.faviconLink != null && feed.faviconLink != '' child: feed.faviconLink != null && feed.faviconLink != ''
? NeonCachedUrlImage( ? NeonCachedUrlImage(
url: feed.faviconLink!, url: feed.faviconLink!,
height: size, size: Size.square(icon),
width: size,
iconColor: Theme.of(context).colorScheme.primary, iconColor: Theme.of(context).colorScheme.primary,
) )
: Icon( : Icon(
Icons.rss_feed, Icons.rss_feed,
size: size, size: icon,
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
), ),
); );

5
packages/neon/neon_news/lib/widgets/folders_view.dart

@ -72,9 +72,8 @@ class NewsFoldersView extends StatelessWidget {
AppLocalizations.of(context).newsUnreadArticles(unreadCount), AppLocalizations.of(context).newsUnreadArticles(unreadCount),
) )
: Container(), : Container(),
leading: SizedBox( leading: SizedBox.square(
width: 48, dimension: 48,
height: 48,
child: Stack( child: Stack(
children: [ children: [
Icon( Icon(

5
packages/neon/neon_notes/lib/widgets/categories_view.dart

@ -49,10 +49,7 @@ class NotesCategoriesView extends StatelessWidget {
size: 40, size: 40,
color: NotesCategoryColor.compute(category.name), color: NotesCategoryColor.compute(category.name),
) )
: const SizedBox( : const SizedBox.square(dimension: 40),
height: 40,
width: 40,
),
onTap: () async { onTap: () async {
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(

11
packages/neon/neon_notifications/lib/pages/main.dart

@ -74,16 +74,13 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
leading: app != null leading: app != null
? app.buildIcon( ? app.buildIcon(
context, context,
width: 40, size: const Size.square(40),
height: 40,
) )
: SizedBox( : SizedBox.fromSize(
width: 40, size: const Size.square(40),
height: 40,
child: NeonCachedUrlImage( child: NeonCachedUrlImage(
url: notification.icon!, url: notification.icon!,
width: 40, size: const Size.square(40),
height: 40,
svgColor: Theme.of(context).colorScheme.primary, svgColor: Theme.of(context).colorScheme.primary,
), ),
), ),

Loading…
Cancel
Save