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:convert';
import 'dart:io';
import 'dart:math';
import 'package:crypto/crypto.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
? 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(

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(
final BuildContext context, {
final double height = 32,
final double width = 32,
final Size size = const Size.square(32),
final Color? color,
}) =>
SizedBox(
height: height,
width: width,
SizedBox.fromSize(
size: size,
child: SvgPicture.asset(
'assets/app.svg',
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 size = (kAvatarSize * MediaQuery.of(context).devicePixelRatio).toInt();
final userStatusBloc = Provider.of<AccountsBloc>(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<UserStatusBloc, NextcloudUserStatusStatus?>(
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<UserStatusBloc, NextcloudUserStatusStatus?>(
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,
),
),
);
},
),
],
);
},
),
],
),
);
}

10
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,
),
),

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 APIImageDownloader download,
final String? etag,
super.height,
super.width,
super.size,
super.fit,
super.svgColor,
super.iconColor,

20
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<File> 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<NeonCachedImage> {
if (widget.isSvgHint || utf8.decode(content).contains('<svg')) {
return SvgPicture.memory(
content,
height: widget.height,
width: widget.width,
height: widget.size?.height,
width: widget.size?.width,
fit: widget.fit ?? BoxFit.contain,
color: widget.svgColor,
);
@ -56,8 +54,8 @@ class _NeonCachedImageState extends State<NeonCachedImage> {
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<NeonCachedImage> {
});
},
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,
),

3
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,

11
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(

1
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';

6
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(

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

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

18
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<bool?>(
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,
);
},
),

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

@ -121,8 +121,7 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
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<NewsArticlesView> {
),
child: NewsFeedIcon(
feed: feed,
size: 16,
icon: 16,
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 {
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,
),
);

5
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(

5
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(

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

@ -74,16 +74,13 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
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,
),
),

Loading…
Cancel
Save