From 5d402f7ca896c5fb575397aa705bfb644158a578 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 12 Dec 2023 16:59:09 +0100 Subject: [PATCH 1/2] chore: Update to ubuntu_lints v0.3.0 --- melos.yaml | 9 +++ packages/app_center/lib/layout.dart | 4 +- packages/app_center/lib/main.dart | 21 +++-- .../app_center/lib/src/about/about_page.dart | 13 ++-- .../lib/src/about/about_providers.dart | 4 +- .../lib/src/appstream/appstream_search.dart | 3 +- .../lib/src/appstream/appstream_service.dart | 78 +++++++++---------- .../lib/src/appstream/appstream_utils.dart | 7 +- .../app_center/lib/src/deb/deb_model.dart | 5 +- packages/app_center/lib/src/deb/deb_page.dart | 15 ++-- .../lib/src/explore/explore_page.dart | 17 ++-- .../lib/src/manage/local_snap_providers.dart | 5 +- .../lib/src/manage/manage_model.dart | 3 +- .../lib/src/manage/manage_page.dart | 16 ++-- .../src/packagekit/packagekit_service.dart | 3 +- .../lib/src/ratings/ratings_l10n.dart | 3 +- .../lib/src/ratings/ratings_model.dart | 7 +- .../lib/src/ratings/ratings_service.dart | 7 +- .../lib/src/search/search_field.dart | 17 ++-- .../lib/src/search/search_page.dart | 19 +++-- .../lib/src/search/search_provider.dart | 5 +- .../lib/src/snapd/snap_category_enum.dart | 7 +- .../app_center/lib/src/snapd/snap_l10n.dart | 5 +- .../lib/src/snapd/snap_launcher.dart | 3 +- .../app_center/lib/src/snapd/snap_model.dart | 5 +- .../app_center/lib/src/snapd/snap_page.dart | 24 +++--- .../app_center/lib/src/snapd/snap_search.dart | 24 +++--- .../app_center/lib/src/snapd/snap_sort.dart | 3 +- .../lib/src/snapd/snapd_service.dart | 5 +- .../lib/src/snapd/snapd_watcher.dart | 4 +- .../lib/src/snapd/updates_model.dart | 5 +- .../app_center/lib/src/store/store_app.dart | 21 +++-- .../lib/src/store/store_navigator.dart | 3 +- .../lib/src/store/store_observer.dart | 5 +- .../app_center/lib/src/store/store_pages.dart | 13 ++-- .../lib/src/store/store_providers.dart | 3 +- .../app_center/lib/src/widgets/app_card.dart | 17 ++-- .../app_center/lib/src/widgets/app_icon.dart | 11 ++- .../lib/src/widgets/app_info_bar.dart | 5 +- .../app_center/lib/src/widgets/app_title.dart | 7 +- .../app_center/lib/src/widgets/dialogs.dart | 5 +- .../lib/src/widgets/screenshot_gallery.dart | 12 ++- .../app_center/lib/src/widgets/snap_grid.dart | 9 +-- .../app_center/lib/xdg_cache_manager.dart | 10 +-- packages/app_center/pubspec.yaml | 10 +-- .../test/appstream_service_test.dart | 4 - packages/app_center/test/snap_model_test.dart | 2 - .../app_center/test/snapd_cache_test.dart | 1 - .../app_center/test/snapd_watcher_test.dart | 6 +- packages/app_center/test/test_utils.dart | 6 +- .../analysis_options.yaml | 5 ++ .../lib/src/chart.dart | 10 +-- .../ratings_features_app.pbgrpc.dart | 23 +++--- .../ratings_features_chart.pbgrpc.dart | 23 +++--- .../ratings_features_user.pbgrpc.dart | 65 +++++++--------- .../lib/src/ratings.dart | 17 ++-- .../lib/src/ratings_client.dart | 45 +++++------ .../lib/src/user.dart | 12 +-- .../app_center_ratings_client/pubspec.yaml | 2 +- .../test/ratings_client_test.dart | 39 +++++----- 60 files changed, 348 insertions(+), 389 deletions(-) diff --git a/melos.yaml b/melos.yaml index e903fac98..920dc4b0f 100644 --- a/melos.yaml +++ b/melos.yaml @@ -3,6 +3,15 @@ name: app_center packages: - packages/** +command: + bootstrap: + environment: + sdk: '>=3.1.0 <4.0.0' + flutter: 3.13.9 + + dev_dependencies: + ubuntu_lints: ^0.3.0 + scripts: # analyze all packages analyze: > diff --git a/packages/app_center/lib/layout.dart b/packages/app_center/lib/layout.dart index 153a1a3c9..24b1807bf 100644 --- a/packages/app_center/lib/layout.dart +++ b/packages/app_center/lib/layout.dart @@ -21,9 +21,9 @@ enum ResponsiveLayoutType { class ResponsiveLayout extends InheritedWidget { ResponsiveLayout({ - super.key, required this.constraints, required super.child, + super.key, }) { final (cardColumnCount, cardSize, snapInfoColumnCount, type) = switch (constraints.maxWidth + kPaneWidth + 1) { @@ -74,7 +74,7 @@ class ResponsiveLayout extends InheritedWidget { } class ResponsiveLayoutBuilder extends LayoutBuilder { - ResponsiveLayoutBuilder({super.key, required WidgetBuilder builder}) + ResponsiveLayoutBuilder({required WidgetBuilder builder, super.key}) : super( builder: (context, constraints) => ResponsiveLayout( constraints: constraints, diff --git a/packages/app_center/lib/main.dart b/packages/app_center/lib/main.dart index 46f0eddab..483d64daa 100644 --- a/packages/app_center/lib/main.dart +++ b/packages/app_center/lib/main.dart @@ -1,6 +1,13 @@ import 'dart:async'; import 'dart:io'; +import 'package:app_center/appstream.dart'; +import 'package:app_center/config.dart'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/packagekit.dart'; +import 'package:app_center/ratings.dart'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/store.dart'; import 'package:app_center_ratings_client/app_center_ratings_client.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -14,14 +21,6 @@ import 'package:ubuntu_service/ubuntu_service.dart'; import 'package:xdg_directories/xdg_directories.dart' as xdg; import 'package:yaru_widgets/yaru_widgets.dart'; -import 'appstream.dart'; -import 'config.dart'; -import 'l10n.dart'; -import 'packagekit.dart'; -import 'ratings.dart'; -import 'snapd.dart'; -import 'store.dart'; - Future main(List args) async { await YaruWindowTitleBar.ensureInitialized(); @@ -54,7 +53,7 @@ Future main(List args) async { registerServiceInstance(config); registerServiceInstance(ratings); - registerService(() => GitHub()); + registerService(GitHub.new); registerService(() => GtkApplicationNotifier(args)); final appstream = AppstreamService(); @@ -63,8 +62,8 @@ Future main(List args) async { unawaited(appstream.init()); registerServiceInstance(appstream); - registerService(() => PackageKitClient()); - registerService(() => PackageKitService(), + registerService(PackageKitClient.new); + registerService(PackageKitService.new, dispose: (service) => service.dispose()); await initDefaultLocale(); diff --git a/packages/app_center/lib/src/about/about_page.dart b/packages/app_center/lib/src/about/about_page.dart index 205a39028..72e9b2b6d 100644 --- a/packages/app_center/lib/src/about/about_page.dart +++ b/packages/app_center/lib/src/about/about_page.dart @@ -1,3 +1,8 @@ +import 'package:app_center/constants.dart'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/src/about/about_providers.dart'; +import 'package:app_center/widgets.dart'; import 'package:flutter/material.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -7,12 +12,6 @@ import 'package:url_launcher/url_launcher_string.dart'; import 'package:yaru_icons/yaru_icons.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/constants.dart'; -import '/l10n.dart'; -import '/layout.dart'; -import '/widgets.dart'; -import 'about_providers.dart'; - class AboutPage extends StatelessWidget { const AboutPage({super.key}); @@ -120,7 +119,7 @@ class _ContributorView extends ConsumerWidget { Text(l10n.aboutPageContributorTitle), const SizedBox(height: 8), state.when( - data: (contributors) => _ContributorWrap(contributors), + data: _ContributorWrap.new, error: (error, stackTrace) => Text(error.toString()), loading: () => Shimmer.fromColors( baseColor: light ? kShimmerBaseLight : kShimmerBaseDark, diff --git a/packages/app_center/lib/src/about/about_providers.dart b/packages/app_center/lib/src/about/about_providers.dart index 03144acf3..f0344f067 100644 --- a/packages/app_center/lib/src/about/about_providers.dart +++ b/packages/app_center/lib/src/about/about_providers.dart @@ -5,8 +5,8 @@ import 'package:package_info_plus/package_info_plus.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -final contributorsProvider = - FutureProvider.autoDispose.family((ref, String repo) async { +final contributorsProvider = FutureProvider.autoDispose + .family, String>((ref, repo) async { const designers = {'anasereijo', 'elioqoshi', 'Zoospora'}; const exclude = {'weblate'}; final contributors = await getService() diff --git a/packages/app_center/lib/src/appstream/appstream_search.dart b/packages/app_center/lib/src/appstream/appstream_search.dart index 21051038f..35a81f771 100644 --- a/packages/app_center/lib/src/appstream/appstream_search.dart +++ b/packages/app_center/lib/src/appstream/appstream_search.dart @@ -1,9 +1,8 @@ +import 'package:app_center/appstream.dart'; import 'package:appstream/appstream.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import '/appstream.dart'; - final appstreamSearchProvider = StreamProvider.family, String>( (ref, query) async* { diff --git a/packages/app_center/lib/src/appstream/appstream_service.dart b/packages/app_center/lib/src/appstream/appstream_service.dart index 54235acf2..5e5bc33c3 100644 --- a/packages/app_center/lib/src/appstream/appstream_service.dart +++ b/packages/app_center/lib/src/appstream/appstream_service.dart @@ -1,36 +1,27 @@ import 'dart:collection'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/src/appstream/appstream_utils.dart'; +import 'package:app_center/src/appstream/logger.dart'; import 'package:appstream/appstream.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'package:snowball_stemmer/snowball_stemmer.dart'; -import '/l10n.dart'; -import 'appstream_utils.dart'; -import 'logger.dart'; - +@immutable class _CachedComponent { - final AppstreamComponent component; - final String id; - final String name; - final List keywords; - final List summary; - final List description; - final String origin; - final String package; - final List mediaTypes; - - _CachedComponent( - this.component, - this.id, - this.name, - this.keywords, - this.summary, - this.description, - this.origin, - this.package, - this.mediaTypes); + const _CachedComponent( + this.component, + this.id, + this.name, + this.keywords, + this.summary, + this.description, + this.origin, + this.package, + this.mediaTypes, + ); factory _CachedComponent.fromAppstream(AppstreamComponent component) { final id = component.getId(); @@ -59,9 +50,18 @@ class _CachedComponent { return _CachedComponent(component, id, name, keywords, summary, description, origin, package, mediaTypes); } + final AppstreamComponent component; + final String id; + final String name; + final List keywords; + final List summary; + final List description; + final String origin; + final String package; + final List mediaTypes; int match(List tokens) { - int score = _MatchScore.none.value; + var score = _MatchScore.none.value; for (final token in tokens) { if (id.contains(token)) { @@ -113,28 +113,18 @@ enum _MatchScore { id(1 << 7), all(1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 7); - final int value; - const _MatchScore(this.value); + + final int value; } class _ScoredComponent { + const _ScoredComponent(this.score, this.component); final int score; final AppstreamComponent component; - - const _ScoredComponent(this.score, this.component); } class AppstreamService { - final AppstreamPool _pool; - late final Future _loader = _pool.load().then((_) { - _populateCache(); - _initialized = true; - }); - - bool get initialized => _initialized; - bool _initialized = false; - // TODO: cache AppstreamPool AppstreamService({@visibleForTesting AppstreamPool? pool}) : _pool = pool ?? AppstreamPool(), @@ -144,6 +134,14 @@ class AppstreamService { _populateCache(); }; } + final AppstreamPool _pool; + late final Future _loader = _pool.load().then((_) { + _populateCache(); + _initialized = true; + }); + + bool get initialized => _initialized; + bool _initialized = false; final HashSet<_CachedComponent> _cache = HashSet<_CachedComponent>(); @@ -219,7 +217,7 @@ class AppstreamService { } // Filter out short tokens, and those containing markup words.removeWhere( - (element) => element.length <= 1 || element.contains(RegExp(r'[<>()]')), + (element) => element.length <= 1 || element.contains(RegExp('[<>()]')), ); // Extract only the common stems from the tokens final algorithm = @@ -227,7 +225,7 @@ class AppstreamService { if (algorithm != null) { final stemmer = SnowballStemmer(algorithm); return words - .map((element) => stemmer.stem(element)) + .map(stemmer.stem) // Keep original tokens as well, since the stemming algorithm might // have unintended effects. See #1305. .followedBy(words) diff --git a/packages/app_center/lib/src/appstream/appstream_utils.dart b/packages/app_center/lib/src/appstream/appstream_utils.dart index 15bf0ebab..68ceb67e8 100644 --- a/packages/app_center/lib/src/appstream/appstream_utils.dart +++ b/packages/app_center/lib/src/appstream/appstream_utils.dart @@ -1,10 +1,9 @@ import 'dart:ui'; +import 'package:app_center/l10n.dart'; import 'package:appstream/appstream.dart'; import 'package:collection/collection.dart'; -import '/l10n.dart'; - extension _GetOrDefault on Map { V getOrDefault(K? key, V fallback) { if (key == null) { @@ -45,7 +44,7 @@ extension LocalizedComponent on AppstreamComponent { } List getLocalizedMediaTypes() { - final List mediaTypes = []; + final mediaTypes = []; for (final provider in provides) { if (provider is AppstreamProvidesMediatype) { @@ -68,7 +67,7 @@ extension LocalizedComponent on AppstreamComponent { final candidates = [fullLocale, languageCode, fallback]; final keys = keyedByLanguage.keys; - for (final String candidate in candidates) { + for (final candidate in candidates) { if (keys.contains(candidate)) return candidate; } diff --git a/packages/app_center/lib/src/deb/deb_model.dart b/packages/app_center/lib/src/deb/deb_model.dart index 25f4566ad..2963404bb 100644 --- a/packages/app_center/lib/src/deb/deb_model.dart +++ b/packages/app_center/lib/src/deb/deb_model.dart @@ -1,14 +1,13 @@ import 'dart:async'; +import 'package:app_center/appstream.dart'; +import 'package:app_center/packagekit.dart'; import 'package:appstream/appstream.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:packagekit/packagekit.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import '/appstream.dart'; -import '/packagekit.dart'; - final debModelProvider = ChangeNotifierProvider.family.autoDispose( (ref, id) => DebModel( diff --git a/packages/app_center/lib/src/deb/deb_page.dart b/packages/app_center/lib/src/deb/deb_page.dart index eeb48006a..bb7392e57 100644 --- a/packages/app_center/lib/src/deb/deb_page.dart +++ b/packages/app_center/lib/src/deb/deb_page.dart @@ -1,5 +1,11 @@ import 'dart:async'; +import 'package:app_center/appstream.dart'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/src/deb/deb_model.dart'; +import 'package:app_center/src/packagekit/packagekit_service.dart'; +import 'package:app_center/widgets.dart'; import 'package:appstream/appstream.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; @@ -12,17 +18,10 @@ import 'package:url_launcher/url_launcher_string.dart'; import 'package:yaru_icons/yaru_icons.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/appstream.dart'; -import '/l10n.dart'; -import '/layout.dart'; -import '/widgets.dart'; -import '../packagekit/packagekit_service.dart'; -import 'deb_model.dart'; - const _kPrimaryButtonMaxWidth = 136.0; class DebPage extends ConsumerStatefulWidget { - const DebPage({super.key, required this.id}); + const DebPage({required this.id, super.key}); final String id; @override diff --git a/packages/app_center/lib/src/explore/explore_page.dart b/packages/app_center/lib/src/explore/explore_page.dart index 60f53bd91..6009f5a4a 100644 --- a/packages/app_center/lib/src/explore/explore_page.dart +++ b/packages/app_center/lib/src/explore/explore_page.dart @@ -1,15 +1,14 @@ +import 'package:app_center/l10n.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/store.dart'; +import 'package:app_center/widgets.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; import 'package:yaru_icons/yaru_icons.dart'; -import '/l10n.dart'; -import '/layout.dart'; -import '/snapd.dart'; -import '/store.dart'; -import '/widgets.dart'; - const kNumberOfBannerSnaps = 3; class ExplorePage extends ConsumerWidget { @@ -164,8 +163,8 @@ class _CategoryBanner extends ConsumerWidget { .whenOrNull(data: (data) => data); final featuredSnaps = category.featuredSnapNames != null ? category.featuredSnapNames! - .map((name) => - snaps?.singleWhereOrNull(((snap) => snap.name == name))) + .map( + (name) => snaps?.singleWhereOrNull((snap) => snap.name == name)) .whereNotNull() : snaps; final l10n = AppLocalizations.of(context); @@ -184,9 +183,9 @@ class _Banner extends StatelessWidget { const _Banner({ required this.snaps, required this.slogan, + required this.colors, this.buttonLabel, this.onPressed, - required this.colors, }); final Iterable snaps; diff --git a/packages/app_center/lib/src/manage/local_snap_providers.dart b/packages/app_center/lib/src/manage/local_snap_providers.dart index c79e4d34d..d6f11be39 100644 --- a/packages/app_center/lib/src/manage/local_snap_providers.dart +++ b/packages/app_center/lib/src/manage/local_snap_providers.dart @@ -1,8 +1,7 @@ +import 'package:app_center/snapd.dart'; +import 'package:app_center/src/manage/manage_model.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '/snapd.dart'; -import 'manage_model.dart'; - final localSnapFilterProvider = StateProvider.autoDispose((_) => ''); final showLocalSystemAppsProvider = StateProvider((_) => false); final localSnapSortOrderProvider = diff --git a/packages/app_center/lib/src/manage/manage_model.dart b/packages/app_center/lib/src/manage/manage_model.dart index b906fdedf..5eaab2603 100644 --- a/packages/app_center/lib/src/manage/manage_model.dart +++ b/packages/app_center/lib/src/manage/manage_model.dart @@ -1,11 +1,10 @@ +import 'package:app_center/snapd.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import '/snapd.dart'; - final manageModelProvider = ChangeNotifierProvider.autoDispose( (ref) => ManageModel( snapd: getService(), diff --git a/packages/app_center/lib/src/manage/manage_page.dart b/packages/app_center/lib/src/manage/manage_page.dart index b1734873c..cf3130b0d 100644 --- a/packages/app_center/lib/src/manage/manage_page.dart +++ b/packages/app_center/lib/src/manage/manage_page.dart @@ -1,5 +1,12 @@ import 'dart:async'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/src/manage/local_snap_providers.dart'; +import 'package:app_center/src/manage/manage_model.dart'; +import 'package:app_center/store.dart'; +import 'package:app_center/widgets.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; @@ -7,14 +14,6 @@ import 'package:ubuntu_widgets/ubuntu_widgets.dart'; import 'package:yaru_icons/yaru_icons.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/l10n.dart'; -import '/layout.dart'; -import '/snapd.dart'; -import '/store.dart'; -import '/widgets.dart'; -import 'local_snap_providers.dart'; -import 'manage_model.dart'; - class ManagePage extends ConsumerStatefulWidget { const ManagePage({super.key}); @@ -341,7 +340,6 @@ class _ManageSnapTile extends ConsumerWidget { side: border, ), ManageTilePosition.middle => RoundedRectangleBorder( - borderRadius: const BorderRadius.all(Radius.zero), side: border, ), ManageTilePosition.last => RoundedRectangleBorder( diff --git a/packages/app_center/lib/src/packagekit/packagekit_service.dart b/packages/app_center/lib/src/packagekit/packagekit_service.dart index d84cb423b..f49019b49 100644 --- a/packages/app_center/lib/src/packagekit/packagekit_service.dart +++ b/packages/app_center/lib/src/packagekit/packagekit_service.dart @@ -1,13 +1,12 @@ import 'dart:async'; import 'dart:io'; +import 'package:app_center/src/packagekit/logger.dart'; import 'package:dbus/dbus.dart'; import 'package:flutter/material.dart'; import 'package:packagekit/packagekit.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import 'logger.dart'; - typedef PackageKitPackageInfo = PackageKitPackageEvent; typedef PackageKitServiceError = PackageKitErrorCodeEvent; diff --git a/packages/app_center/lib/src/ratings/ratings_l10n.dart b/packages/app_center/lib/src/ratings/ratings_l10n.dart index 62be0fb9c..e0bef0626 100644 --- a/packages/app_center/lib/src/ratings/ratings_l10n.dart +++ b/packages/app_center/lib/src/ratings/ratings_l10n.dart @@ -1,8 +1,7 @@ +import 'package:app_center/l10n.dart'; import 'package:app_center_ratings_client/app_center_ratings_client.dart'; import 'package:flutter/material.dart'; -import '../../l10n.dart'; - extension RatingsBandL10n on RatingsBand { String localize(AppLocalizations l10n) { return switch (this) { diff --git a/packages/app_center/lib/src/ratings/ratings_model.dart b/packages/app_center/lib/src/ratings/ratings_model.dart index daf993210..65a1eea88 100644 --- a/packages/app_center/lib/src/ratings/ratings_model.dart +++ b/packages/app_center/lib/src/ratings/ratings_model.dart @@ -1,3 +1,5 @@ +import 'package:app_center/src/ratings/exports.dart'; +import 'package:app_center/src/ratings/ratings_service.dart'; import 'package:app_center_ratings_client/app_center_ratings_client.dart'; import 'package:clock/clock.dart'; import 'package:flutter/material.dart'; @@ -5,9 +7,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import 'exports.dart'; -import 'ratings_service.dart'; - final ratingsModelProvider = ChangeNotifierProvider.family.autoDispose( (ref, snap) => RatingsModel( @@ -66,7 +65,7 @@ class RatingsModel extends ChangeNotifier { } Future castVote(VoteStatus castVote) async { - bool voteUp = castVote == VoteStatus.up ? true : false; + final voteUp = castVote == VoteStatus.up ? true : false; if (castVote != _vote) { final vote = Vote( diff --git a/packages/app_center/lib/src/ratings/ratings_service.dart b/packages/app_center/lib/src/ratings/ratings_service.dart index a770945c0..4c343d65a 100644 --- a/packages/app_center/lib/src/ratings/ratings_service.dart +++ b/packages/app_center/lib/src/ratings/ratings_service.dart @@ -1,14 +1,13 @@ import 'dart:convert'; import 'dart:io'; +import 'package:app_center/src/ratings/exports.dart'; import 'package:app_center_ratings_client/app_center_ratings_client.dart'; import 'package:crypto/crypto.dart'; import 'package:flutter/material.dart'; import 'package:glib/glib.dart'; import 'package:jwt_decode/jwt_decode.dart'; -import 'exports.dart'; - class RatingsService { RatingsService(this.client, {@visibleForTesting String? id}) : _id = id ?? _generateId(); @@ -46,11 +45,11 @@ class RatingsService { Future> listMyVotes(String snapFilter) async { await _ensureValidToken(); - return await client.listMyVotes(snapFilter, _jwt!); + return client.listMyVotes(snapFilter, _jwt!); } Future> getSnapVotes(String snapId) async { await _ensureValidToken(); - return await client.getSnapVotes(snapId, _jwt!); + return client.getSnapVotes(snapId, _jwt!); } } diff --git a/packages/app_center/lib/src/search/search_field.dart b/packages/app_center/lib/src/search/search_field.dart index fbbcf10cb..3fcac70ef 100644 --- a/packages/app_center/lib/src/search/search_field.dart +++ b/packages/app_center/lib/src/search/search_field.dart @@ -1,3 +1,7 @@ +import 'package:app_center/appstream.dart'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/src/search/search_provider.dart'; +import 'package:app_center/widgets.dart'; import 'package:appstream/appstream.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -6,11 +10,6 @@ import 'package:snapd/snapd.dart'; import 'package:yaru_icons/yaru_icons.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/appstream.dart'; -import '/snapd.dart'; -import '/widgets.dart'; -import 'search_provider.dart'; - sealed class AutoCompleteOption { String get title => switch (this) { AutoCompleteSnapOption(snap: final snap) => snap.titleOrName, @@ -20,26 +19,26 @@ sealed class AutoCompleteOption { } class AutoCompleteSnapOption extends AutoCompleteOption { - final Snap snap; AutoCompleteSnapOption(this.snap); + final Snap snap; } class AutoCompleteDebOption extends AutoCompleteOption { - final AppstreamComponent deb; AutoCompleteDebOption(this.deb); + final AppstreamComponent deb; } class AutoCompleteSearchOption extends AutoCompleteOption { - final String query; AutoCompleteSearchOption(this.query); + final String query; } class SearchField extends ConsumerStatefulWidget { const SearchField({ - super.key, required this.onSearch, required this.onSnapSelected, required this.onDebSelected, + super.key, }); final ValueChanged onSearch; diff --git a/packages/app_center/lib/src/search/search_page.dart b/packages/app_center/lib/src/search/search_page.dart index c20d3ef33..b3a8333e4 100644 --- a/packages/app_center/lib/src/search/search_page.dart +++ b/packages/app_center/lib/src/search/search_page.dart @@ -1,17 +1,16 @@ +import 'package:app_center/appstream.dart'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/search.dart'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/store.dart'; +import 'package:app_center/widgets.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:ubuntu_widgets/ubuntu_widgets.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/appstream.dart'; -import '/l10n.dart'; -import '/layout.dart'; -import '/search.dart'; -import '/snapd.dart'; -import '/store.dart'; -import '/widgets.dart'; - // TODO: break down into smaller widgets class SearchPage extends StatelessWidget { const SearchPage({super.key, this.query, String? category}) @@ -180,7 +179,7 @@ class _DebSearchResults extends ConsumerWidget { padding: ResponsiveLayout.of(context).padding, child: Column( children: [ - const Spacer(flex: 1), + const Spacer(), Text( l10n.searchPageNoResults(query!), style: Theme.of(context).textTheme.headlineSmall, @@ -238,7 +237,7 @@ class _SnapSearchResults extends ConsumerWidget { padding: ResponsiveLayout.of(context).padding, child: Column( children: [ - const Spacer(flex: 1), + const Spacer(), Text( category == null ? l10n.searchPageNoResults(query!) diff --git a/packages/app_center/lib/src/search/search_provider.dart b/packages/app_center/lib/src/search/search_provider.dart index 5d4eed1df..b645bc962 100644 --- a/packages/app_center/lib/src/search/search_provider.dart +++ b/packages/app_center/lib/src/search/search_provider.dart @@ -1,12 +1,11 @@ import 'dart:async'; +import 'package:app_center/appstream.dart'; +import 'package:app_center/snapd.dart'; import 'package:appstream/appstream.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; -import '/appstream.dart'; -import '/snapd.dart'; - enum PackageFormat { snap, deb } final queryProvider = StateProvider((_) => null); diff --git a/packages/app_center/lib/src/snapd/snap_category_enum.dart b/packages/app_center/lib/src/snapd/snap_category_enum.dart index dfde78208..2525db8a3 100644 --- a/packages/app_center/lib/src/snapd/snap_category_enum.dart +++ b/packages/app_center/lib/src/snapd/snap_category_enum.dart @@ -1,9 +1,8 @@ +import 'package:app_center/l10n.dart'; import 'package:flutter/widgets.dart'; import 'package:snapd/snapd.dart'; import 'package:yaru_icons/yaru_icons.dart'; -import '/l10n.dart'; - extension SnapCategoryX on SnapCategory { SnapCategoryEnum get categoryEnum => name.toSnapCategoryEnum(); } @@ -11,7 +10,7 @@ extension SnapCategoryX on SnapCategory { extension StringX on String { SnapCategoryEnum toSnapCategoryEnum() => SnapCategoryEnum.values.byName( replaceAllMapped( - RegExp(r'-(.)'), + RegExp('-(.)'), (match) => match[1]!.toUpperCase(), ), ); @@ -44,7 +43,7 @@ enum SnapCategoryEnum { bool get hidden => [unknown, ubuntuDesktop].contains(this); String get categoryName => name.replaceAllMapped( - RegExp(r'[A-Z]'), (match) => '-${match[0]!.toLowerCase()}'); + RegExp('[A-Z]'), (match) => '-${match[0]!.toLowerCase()}'); List? get featuredSnapNames => switch (this) { development => ['code', 'postman', 'phpstorm'], diff --git a/packages/app_center/lib/src/snapd/snap_l10n.dart b/packages/app_center/lib/src/snapd/snap_l10n.dart index 2ad521d78..e123c39b1 100644 --- a/packages/app_center/lib/src/snapd/snap_l10n.dart +++ b/packages/app_center/lib/src/snapd/snap_l10n.dart @@ -1,8 +1,7 @@ +import 'package:app_center/l10n.dart'; +import 'package:app_center/src/snapd/snap_sort.dart'; import 'package:snapd/snapd.dart'; -import '/l10n.dart'; -import 'snap_sort.dart'; - extension SnapdChangeL10n on SnapdChange { String? localize(AppLocalizations l10n) => switch (kind) { 'install-snap' => l10n.snapActionInstallingLabel, diff --git a/packages/app_center/lib/src/snapd/snap_launcher.dart b/packages/app_center/lib/src/snapd/snap_launcher.dart index 4631763ab..ce5c58f6c 100644 --- a/packages/app_center/lib/src/snapd/snap_launcher.dart +++ b/packages/app_center/lib/src/snapd/snap_launcher.dart @@ -5,7 +5,8 @@ import 'package:snapcraft_launcher/snapcraft_launcher.dart'; import 'package:snapd/snapd.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -final launchProvider = Provider.family.autoDispose((ref, Snap snap) { +final launchProvider = + Provider.family.autoDispose((ref, snap) { final launcher = getService(); return SnapLauncher(snap: snap, launcher: launcher); }); diff --git a/packages/app_center/lib/src/snapd/snap_model.dart b/packages/app_center/lib/src/snapd/snap_model.dart index 70ac70f0e..4cbe436c2 100644 --- a/packages/app_center/lib/src/snapd/snap_model.dart +++ b/packages/app_center/lib/src/snapd/snap_model.dart @@ -1,14 +1,13 @@ import 'dart:async'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/src/snapd/logger.dart'; import 'package:collection/collection.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import '/snapd.dart'; -import 'logger.dart'; - final snapModelProvider = ChangeNotifierProvider.family.autoDispose( (ref, snapName) => SnapModel( diff --git a/packages/app_center/lib/src/snapd/snap_page.dart b/packages/app_center/lib/src/snapd/snap_page.dart index c025156de..d20e25996 100644 --- a/packages/app_center/lib/src/snapd/snap_page.dart +++ b/packages/app_center/lib/src/snapd/snap_page.dart @@ -1,6 +1,11 @@ import 'dart:async'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/ratings.dart'; +import 'package:app_center/snapd.dart'; import 'package:app_center/src/store/store_app.dart'; +import 'package:app_center/widgets.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -14,19 +19,13 @@ import 'package:url_launcher/url_launcher_string.dart'; import 'package:yaru_icons/yaru_icons.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/l10n.dart'; -import '/layout.dart'; -import '/ratings.dart'; -import '/snapd.dart'; -import '/widgets.dart'; - const _kPrimaryButtonMaxWidth = 136.0; const _kChannelDropdownWidth = 220.0; typedef SnapInfo = ({String label, Widget value}); class SnapPage extends ConsumerStatefulWidget { - const SnapPage({super.key, required this.snapName}); + const SnapPage({required this.snapName, super.key}); final String snapName; @@ -303,8 +302,9 @@ class _SnapActionButtons extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final l10n = AppLocalizations.of(context); - final snapLauncher = snapModel.isInstalled - ? ref.watch(launchProvider(snapModel.localSnap!)) + final localSnap = snapModel.localSnap; + final snapLauncher = snapModel.isInstalled && localSnap != null + ? ref.watch(launchProvider(localSnap)) : null; final updatesModel = ref.watch(updatesModelProvider); @@ -438,7 +438,7 @@ class _RatingsActionButtons extends ConsumerWidget { onTap: () { ratingsModel.castVote(VoteStatus.up); }, - child: Container( + child: DecoratedBox( decoration: BoxDecoration( border: Border( top: BorderSide(color: Theme.of(context).dividerColor), @@ -470,7 +470,7 @@ class _RatingsActionButtons extends ConsumerWidget { onTap: () { ratingsModel.castVote(VoteStatus.down); }, - child: Container( + child: DecoratedBox( decoration: BoxDecoration( border: Border( top: BorderSide(color: Theme.of(context).dividerColor), @@ -627,7 +627,7 @@ class _ChannelDropdown extends StatelessWidget { MaterialStatePropertyAll(Size(_kChannelDropdownWidth, 0)), maximumSize: MaterialStatePropertyAll(Size(_kChannelDropdownWidth, 200)), - visualDensity: VisualDensity(horizontal: 0, vertical: 0), + visualDensity: VisualDensity.standard, ), itemStyle: MenuItemButton.styleFrom( maximumSize: const Size.fromHeight(100), diff --git a/packages/app_center/lib/src/snapd/snap_search.dart b/packages/app_center/lib/src/snapd/snap_search.dart index 41ce05157..57884cb68 100644 --- a/packages/app_center/lib/src/snapd/snap_search.dart +++ b/packages/app_center/lib/src/snapd/snap_search.dart @@ -1,8 +1,10 @@ +import 'package:app_center/snapd.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:meta/meta.dart'; +import 'package:snapd/snapd.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import '/snapd.dart'; - +@immutable class SnapSearchParameters { const SnapSearchParameters({this.query, this.category}); final String? query; @@ -31,13 +33,16 @@ final snapCategoryProvider = StateProvider.family (ref, initialValue) => initialValue); final snapSearchProvider = - StreamProvider.family((ref, SnapSearchParameters searchParameters) async* { + StreamProvider.family, SnapSearchParameters>( + (ref, searchParameters) async* { final snapd = getService(); if (searchParameters.category == SnapCategoryEnum.ubuntuDesktop) { - yield* snapd.getStoreSnaps(searchParameters.category!.featuredSnapNames - ?.where((name) => name.contains(searchParameters.query ?? '')) - .toList() ?? - []); + yield* snapd.getStoreSnaps( + searchParameters.category!.featuredSnapNames + ?.where((name) => name.contains(searchParameters.query ?? '')) + .toList() ?? + [], + ); } else if (searchParameters.query == null && searchParameters.category != null) { yield* snapd.getCategory(searchParameters.category!.categoryName); @@ -53,7 +58,8 @@ final snapSortOrderProvider = StateProvider.autoDispose((_) => null); final sortedSnapSearchProvider = FutureProvider.family - .autoDispose((ref, SnapSearchParameters searchParameters) { + .autoDispose, SnapSearchParameters>((ref, searchParameters) { return ref.watch(snapSearchProvider(searchParameters).future).then( - (snaps) => snaps.sortedSnaps(ref.watch(snapSortOrderProvider)).toList()); + (snaps) => snaps.sortedSnaps(ref.watch(snapSortOrderProvider)).toList(), + ); }); diff --git a/packages/app_center/lib/src/snapd/snap_sort.dart b/packages/app_center/lib/src/snapd/snap_sort.dart index 36efbf544..016429c2f 100644 --- a/packages/app_center/lib/src/snapd/snap_sort.dart +++ b/packages/app_center/lib/src/snapd/snap_sort.dart @@ -1,8 +1,7 @@ +import 'package:app_center/snapd.dart'; import 'package:collection/collection.dart'; import 'package:snapd/snapd.dart'; -import '/snapd.dart'; - enum SnapSortOrder { alphabeticalAsc, alphabeticalDesc, diff --git a/packages/app_center/lib/src/snapd/snapd_service.dart b/packages/app_center/lib/src/snapd/snapd_service.dart index d446684fd..2b347fb6c 100644 --- a/packages/app_center/lib/src/snapd/snapd_service.dart +++ b/packages/app_center/lib/src/snapd/snapd_service.dart @@ -1,8 +1,7 @@ +import 'package:app_center/src/snapd/snapd_cache.dart'; +import 'package:app_center/src/snapd/snapd_watcher.dart'; import 'package:snapd/snapd.dart'; -import 'snapd_cache.dart'; -import 'snapd_watcher.dart'; - class SnapdService extends SnapdClient with SnapdCache, SnapdWatcher { Future waitChange(String changeId) => watchChange(changeId).firstWhere((change) => change.ready); diff --git a/packages/app_center/lib/src/snapd/snapd_watcher.dart b/packages/app_center/lib/src/snapd/snapd_watcher.dart index 6dd75a0cf..07ec0439f 100644 --- a/packages/app_center/lib/src/snapd/snapd_watcher.dart +++ b/packages/app_center/lib/src/snapd/snapd_watcher.dart @@ -9,7 +9,7 @@ mixin SnapdWatcher on SnapdClient { Duration interval = const Duration(milliseconds: 100), }) { return Stream.periodic(interval, (_) => getChange(id)) - .asyncMap((response) async => await response) + .asyncMap((response) async => response) .distinct(); } @@ -18,7 +18,7 @@ mixin SnapdWatcher on SnapdClient { Duration interval = const Duration(milliseconds: 100), }) { return Stream.periodic(interval, (_) => getChanges(name: name)) - .asyncMap((response) async => await response) + .asyncMap((response) async => response) .map((changes) => changes.map((c) => c.id).sorted()) .distinct(const ListEquality().equals); } diff --git a/packages/app_center/lib/src/snapd/updates_model.dart b/packages/app_center/lib/src/snapd/updates_model.dart index d2f7393b5..25a7d1d3b 100644 --- a/packages/app_center/lib/src/snapd/updates_model.dart +++ b/packages/app_center/lib/src/snapd/updates_model.dart @@ -1,13 +1,12 @@ import 'dart:async'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/src/snapd/logger.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import '/snapd.dart'; -import 'logger.dart'; - final updatesModelProvider = ChangeNotifierProvider( (ref) => UpdatesModel(getService())..refresh(), ); diff --git a/packages/app_center/lib/src/store/store_app.dart b/packages/app_center/lib/src/store/store_app.dart index 34445f677..0d1e727f7 100644 --- a/packages/app_center/lib/src/store/store_app.dart +++ b/packages/app_center/lib/src/store/store_app.dart @@ -1,19 +1,18 @@ +import 'package:app_center/deb.dart'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/search.dart'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/src/store/store_navigator.dart'; +import 'package:app_center/src/store/store_observer.dart'; +import 'package:app_center/src/store/store_pages.dart'; +import 'package:app_center/src/store/store_providers.dart'; +import 'package:app_center/src/store/store_routes.dart'; import 'package:flutter/material.dart' hide AboutDialog, showAboutDialog; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:yaru/yaru.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/deb.dart'; -import '/l10n.dart'; -import '/layout.dart'; -import '/search.dart'; -import '/snapd.dart'; -import 'store_navigator.dart'; -import 'store_observer.dart'; -import 'store_pages.dart'; -import 'store_providers.dart'; -import 'store_routes.dart'; - // Making a provider to provide navigatorKeyTwo final materialAppNavigatorKeyProvider = Provider((ref) => GlobalKey()); diff --git a/packages/app_center/lib/src/store/store_navigator.dart b/packages/app_center/lib/src/store/store_navigator.dart index 949bf8022..9bbfabdd7 100644 --- a/packages/app_center/lib/src/store/store_navigator.dart +++ b/packages/app_center/lib/src/store/store_navigator.dart @@ -1,7 +1,6 @@ +import 'package:app_center/src/store/store_routes.dart'; import 'package:flutter/widgets.dart'; -import 'store_routes.dart'; - class StoreNavigator { static Future pushDeb( BuildContext context, { diff --git a/packages/app_center/lib/src/store/store_observer.dart b/packages/app_center/lib/src/store/store_observer.dart index 577ca41c0..4f9045184 100644 --- a/packages/app_center/lib/src/store/store_observer.dart +++ b/packages/app_center/lib/src/store/store_observer.dart @@ -1,9 +1,8 @@ +import 'package:app_center/search.dart'; +import 'package:app_center/src/store/store_routes.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '/search.dart'; -import 'store_routes.dart'; - class StoreObserver extends NavigatorObserver { StoreObserver(this.ref); diff --git a/packages/app_center/lib/src/store/store_pages.dart b/packages/app_center/lib/src/store/store_pages.dart index 43d1f86f2..d520eb227 100644 --- a/packages/app_center/lib/src/store/store_pages.dart +++ b/packages/app_center/lib/src/store/store_pages.dart @@ -1,14 +1,13 @@ +import 'package:app_center/about.dart'; +import 'package:app_center/explore.dart'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/manage.dart'; +import 'package:app_center/search.dart'; +import 'package:app_center/snapd.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/about.dart'; -import '/explore.dart'; -import '/l10n.dart'; -import '/manage.dart'; -import '/search.dart'; -import '/snapd.dart'; - typedef StorePage = ({ Widget Function(BuildContext context, bool selected) tileBuilder, WidgetBuilder pageBuilder, diff --git a/packages/app_center/lib/src/store/store_providers.dart b/packages/app_center/lib/src/store/store_providers.dart index 845548864..ca98f2f2e 100644 --- a/packages/app_center/lib/src/store/store_providers.dart +++ b/packages/app_center/lib/src/store/store_providers.dart @@ -1,10 +1,9 @@ +import 'package:app_center/src/store/store_routes.dart'; import 'package:args/args.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:gtk/gtk.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; -import 'store_routes.dart'; - const _kUrlPrefix = 'snap://'; final commandLineProvider = Provider.autoDispose((ref) { diff --git a/packages/app_center/lib/src/widgets/app_card.dart b/packages/app_center/lib/src/widgets/app_card.dart index 565a0d818..f6e450f2e 100644 --- a/packages/app_center/lib/src/widgets/app_card.dart +++ b/packages/app_center/lib/src/widgets/app_card.dart @@ -1,21 +1,20 @@ +import 'package:app_center/appstream.dart'; +import 'package:app_center/l10n.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/ratings.dart'; +import 'package:app_center/snapd.dart'; +import 'package:app_center/widgets.dart'; import 'package:appstream/appstream.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/appstream.dart'; -import '/l10n.dart'; -import '/layout.dart'; -import '/ratings.dart'; -import '/snapd.dart'; -import '/widgets.dart'; - class AppCard extends StatelessWidget { const AppCard({ - super.key, required this.title, required this.summary, + super.key, this.onTap, this.compact = false, this.iconUrl, @@ -79,7 +78,7 @@ class AppCard extends StatelessWidget { // TODO: generalize class SnapImageCard extends StatelessWidget { - const SnapImageCard({super.key, required this.snap, this.onTap}); + const SnapImageCard({required this.snap, super.key, this.onTap}); final Snap snap; final VoidCallback? onTap; diff --git a/packages/app_center/lib/src/widgets/app_icon.dart b/packages/app_center/lib/src/widgets/app_icon.dart index 61225b95f..896314be0 100644 --- a/packages/app_center/lib/src/widgets/app_icon.dart +++ b/packages/app_center/lib/src/widgets/app_icon.dart @@ -1,16 +1,15 @@ +import 'package:app_center/constants.dart'; +import 'package:app_center/layout.dart'; +import 'package:app_center/xdg_cache_manager.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:shimmer/shimmer.dart'; import 'package:yaru_icons/yaru_icons.dart'; -import '/constants.dart'; -import '/layout.dart'; -import '/xdg_cache_manager.dart'; - class AppIcon extends StatelessWidget { const AppIcon({ - super.key, required this.iconUrl, + super.key, this.size = kIconSize, this.loadingHighlight, this.loadingBaseColor, @@ -25,7 +24,7 @@ class AppIcon extends StatelessWidget { Widget build(BuildContext context) { final fallBackIcon = YaruPlaceholderIcon(size: Size.square(size)); - var light = Theme.of(context).brightness == Brightness.light; + final light = Theme.of(context).brightness == Brightness.light; final fallBackLoadingIcon = Shimmer.fromColors( baseColor: loadingBaseColor ?? (light ? kShimmerBaseLight : kShimmerBaseDark), diff --git a/packages/app_center/lib/src/widgets/app_info_bar.dart b/packages/app_center/lib/src/widgets/app_info_bar.dart index 55d860f8f..317d216fb 100644 --- a/packages/app_center/lib/src/widgets/app_info_bar.dart +++ b/packages/app_center/lib/src/widgets/app_info_bar.dart @@ -1,14 +1,13 @@ +import 'package:app_center/layout.dart'; import 'package:flutter/material.dart'; -import '/layout.dart'; - typedef AppInfo = ({String label, Widget value}); class AppInfoBar extends StatelessWidget { const AppInfoBar({ - super.key, required this.appInfos, required this.layout, + super.key, }); final List appInfos; diff --git a/packages/app_center/lib/src/widgets/app_title.dart b/packages/app_center/lib/src/widgets/app_title.dart index dd5454273..c13cbc880 100644 --- a/packages/app_center/lib/src/widgets/app_title.dart +++ b/packages/app_center/lib/src/widgets/app_title.dart @@ -1,3 +1,5 @@ +import 'package:app_center/appstream.dart'; +import 'package:app_center/snapd.dart'; import 'package:appstream/appstream.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; @@ -5,13 +7,10 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:snapd/snapd.dart'; import 'package:yaru/yaru.dart'; -import '/appstream.dart'; -import '/snapd.dart'; - class AppTitle extends StatelessWidget { const AppTitle({ - super.key, required this.title, + super.key, this.publisher, this.verifiedPublisher = false, this.starredPublisher = false, diff --git a/packages/app_center/lib/src/widgets/dialogs.dart b/packages/app_center/lib/src/widgets/dialogs.dart index ddb9dd65e..b3388f4e0 100644 --- a/packages/app_center/lib/src/widgets/dialogs.dart +++ b/packages/app_center/lib/src/widgets/dialogs.dart @@ -1,9 +1,8 @@ +import 'package:app_center/l10n.dart'; import 'package:flutter/material.dart'; import 'package:ubuntu_widgets/ubuntu_widgets.dart'; import 'package:yaru_icons/yaru_icons.dart'; -import '/l10n.dart'; - const kMaxWidth = 500.0; Future showErrorDialog({ @@ -24,9 +23,9 @@ Future showErrorDialog({ class ErrorDialog extends StatelessWidget { const ErrorDialog({ - super.key, required this.title, required this.message, + super.key, this.icon, }); diff --git a/packages/app_center/lib/src/widgets/screenshot_gallery.dart b/packages/app_center/lib/src/widgets/screenshot_gallery.dart index 2b9ae556d..4e78c92e2 100644 --- a/packages/app_center/lib/src/widgets/screenshot_gallery.dart +++ b/packages/app_center/lib/src/widgets/screenshot_gallery.dart @@ -1,16 +1,15 @@ +import 'package:app_center/xdg_cache_manager.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:yaru_icons/yaru_icons.dart'; import 'package:yaru_widgets/yaru_widgets.dart'; -import '/xdg_cache_manager.dart'; - class ScreenshotGallery extends StatelessWidget { const ScreenshotGallery({ - super.key, required this.title, required this.urls, + super.key, this.height, }); @@ -46,10 +45,10 @@ class ScreenshotGallery extends StatelessWidget { class MediaTile extends StatelessWidget { const MediaTile({ - super.key, required this.url, - this.fit = BoxFit.contain, required this.onTap, + super.key, + this.fit = BoxFit.contain, }); final String url; @@ -106,7 +105,6 @@ class _CarouselDialogState extends State<_CarouselDialog> { super.initState(); controller = YaruCarouselController( initialPage: widget.initialIndex, - viewportFraction: 0.8, ); } @@ -162,8 +160,8 @@ class _CarouselDialogState extends State<_CarouselDialog> { class SafeNetworkImage extends StatelessWidget { const SafeNetworkImage({ - super.key, required this.url, + super.key, this.filterQuality = FilterQuality.medium, this.fit = BoxFit.fitHeight, this.fallBackIcon, diff --git a/packages/app_center/lib/src/widgets/snap_grid.dart b/packages/app_center/lib/src/widgets/snap_grid.dart index c42a3cb29..2443c65de 100644 --- a/packages/app_center/lib/src/widgets/snap_grid.dart +++ b/packages/app_center/lib/src/widgets/snap_grid.dart @@ -1,14 +1,13 @@ +import 'package:app_center/layout.dart'; +import 'package:app_center/src/widgets/app_card.dart'; import 'package:appstream/appstream.dart'; import 'package:flutter/material.dart'; import 'package:snapd/snapd.dart'; -import '/layout.dart'; -import 'app_card.dart'; - class AppCardGrid extends StatelessWidget { const AppCardGrid({ - super.key, required this.appCards, + super.key, }); factory AppCardGrid.fromSnaps({ @@ -58,9 +57,9 @@ class AppCardGrid extends StatelessWidget { // TODO: generalize class SnapImageCardGrid extends StatelessWidget { const SnapImageCardGrid({ - super.key, required this.snaps, required this.onTap, + super.key, }); final List snaps; diff --git a/packages/app_center/lib/xdg_cache_manager.dart b/packages/app_center/lib/xdg_cache_manager.dart index 8877e1bf7..8dd79d9e6 100644 --- a/packages/app_center/lib/xdg_cache_manager.dart +++ b/packages/app_center/lib/xdg_cache_manager.dart @@ -14,11 +14,10 @@ import 'package:path/path.dart' as p; import 'package:xdg_directories/xdg_directories.dart' as xdg; class _XdgFileSystem implements FileSystem { + _XdgFileSystem(this._cacheKey) : _fileDir = createDirectory(_cacheKey); final Future _fileDir; final String _cacheKey; - _XdgFileSystem(this._cacheKey) : _fileDir = createDirectory(_cacheKey); - static Future createDirectory(String key) async { final baseDir = xdg.cacheHome; final path = p.join(baseDir.path, key, 'images'); @@ -40,13 +39,12 @@ class _XdgFileSystem implements FileSystem { } class XdgCacheManager extends CacheManager with ImageCacheManager { - static final key = p.basename(Platform.resolvedExecutable); - - static final XdgCacheManager _instance = XdgCacheManager._(); - factory XdgCacheManager() { return _instance; } XdgCacheManager._() : super(Config(key, fileSystem: _XdgFileSystem(key))); + static final key = p.basename(Platform.resolvedExecutable); + + static final XdgCacheManager _instance = XdgCacheManager._(); } diff --git a/packages/app_center/pubspec.yaml b/packages/app_center/pubspec.yaml index 391ed86d9..faf8e4146 100644 --- a/packages/app_center/pubspec.yaml +++ b/packages/app_center/pubspec.yaml @@ -8,13 +8,14 @@ environment: flutter: 3.13.9 dependencies: + app_center_ratings_client: ^1.0.0 appstream: ^0.2.8 args: ^2.4.2 cached_network_image: ^3.3.0 + clock: ^1.1.1 collection: ^1.17.2 - dbus: ^0.7.10 - app_center_ratings_client: ^1.0.0 crypto: ^3.0.3 + dbus: ^0.7.10 file: ^6.1.4 flutter: sdk: flutter @@ -47,9 +48,8 @@ dependencies: xdg_directories: ^1.0.3 yaru: ^1.2.0 yaru_icons: ^2.2.2 - yaru_widgets: ^3.3.0 yaru_test: ^0.1.5 - clock: ^1.1.1 + yaru_widgets: ^3.3.0 dev_dependencies: build_runner: ^2.4.6 @@ -59,7 +59,7 @@ dev_dependencies: integration_test: sdk: flutter mockito: 5.4.3 - ubuntu_lints: ^0.1.0 + ubuntu_lints: ^0.3.0 flutter: uses-material-design: true diff --git a/packages/app_center/test/appstream_service_test.dart b/packages/app_center/test/appstream_service_test.dart index caedb1536..26854e6ae 100644 --- a/packages/app_center/test/appstream_service_test.dart +++ b/packages/app_center/test/appstream_service_test.dart @@ -41,8 +41,6 @@ void main() { package: 'qbrew', name: {'C': 'QBrew'}, summary: {}, - description: {}, - keywords: {}, ); const component3 = AppstreamComponent( @@ -51,8 +49,6 @@ void main() { package: 'gperiodic', name: {'C': 'GPeriodic'}, summary: {}, - description: {}, - keywords: {}, ); setUp(() { diff --git a/packages/app_center/test/snap_model_test.dart b/packages/app_center/test/snap_model_test.dart index 0e72414fd..f51c2438f 100644 --- a/packages/app_center/test/snap_model_test.dart +++ b/packages/app_center/test/snap_model_test.dart @@ -114,7 +114,6 @@ void main() { verify(service.install( 'testsnap', channel: 'latest/stable', - classic: false, )).called(1); }); test('non-default channel', () async { @@ -166,7 +165,6 @@ void main() { verify(service.refresh( 'testsnap', channel: 'latest/stable', - classic: false, )).called(1); }); }); diff --git a/packages/app_center/test/snapd_cache_test.dart b/packages/app_center/test/snapd_cache_test.dart index eb87e52d7..8efc5466e 100644 --- a/packages/app_center/test/snapd_cache_test.dart +++ b/packages/app_center/test/snapd_cache_test.dart @@ -73,7 +73,6 @@ void main() { final cache = CacheFile( '/foo/${localSnap.name}.smc', fs: fs, - codec: smc, ); final file = fs.file('foo/${localSnap.name}.smc'); expect(file.existsSync(), isFalse); diff --git a/packages/app_center/test/snapd_watcher_test.dart b/packages/app_center/test/snapd_watcher_test.dart index 8b8b78c00..d1c792f2c 100644 --- a/packages/app_center/test/snapd_watcher_test.dart +++ b/packages/app_center/test/snapd_watcher_test.dart @@ -13,8 +13,8 @@ class TestSnapdWatcher extends MockSnapdClient with SnapdWatcher {} void main() { test('watch change', () async { final changes = [ - SnapdChange(id: 'c', spawnTime: DateTime(1970, 1)), - SnapdChange(id: 'c', spawnTime: DateTime(1970, 1)), + SnapdChange(id: 'c', spawnTime: DateTime(1970)), + SnapdChange(id: 'c', spawnTime: DateTime(1970)), SnapdChange(id: 'c', spawnTime: DateTime(1970, 2)), SnapdChange(id: 'c', spawnTime: DateTime(1970, 3)), SnapdChange(id: 'c', spawnTime: DateTime(1970, 3)), @@ -36,7 +36,7 @@ void main() { final changes = [ SnapdChange(id: 'c2', spawnTime: DateTime(1970, 2)), SnapdChange(id: 'c3', spawnTime: DateTime(1970, 3)), - SnapdChange(id: 'c1', spawnTime: DateTime(1970, 1)), + SnapdChange(id: 'c1', spawnTime: DateTime(1970)), ]; final watcher = TestSnapdWatcher(); diff --git a/packages/app_center/test/test_utils.dart b/packages/app_center/test/test_utils.dart index 18ba948cb..96983cd1a 100644 --- a/packages/app_center/test/test_utils.dart +++ b/packages/app_center/test/test_utils.dart @@ -29,7 +29,7 @@ extension WidgetTesterX on WidgetTester { Future pumpApp(WidgetBuilder builder) async { // The intended minimum size of the window. view.physicalSize = - (Size(800, 600) + Offset(54, 54)) * view.devicePixelRatio; + (const Size(800, 600) + const Offset(54, 54)) * view.devicePixelRatio; final ubuntuRegular = File('test/fonts/Ubuntu-Regular.ttf'); final content = ByteData.view( Uint8List.fromList(ubuntuRegular.readAsBytesSync()).buffer); @@ -48,7 +48,7 @@ extension WidgetTesterX on WidgetTester { Stream> Function(SnapSearchParameters) createMockSnapSearchProvider( Map> searchResults) { - return (SnapSearchParameters searchParameters) => Stream.value( + return (searchParameters) => Stream.value( searchResults.entries .firstWhereOrNull((e) => e.key == searchParameters) ?.value ?? @@ -58,7 +58,7 @@ Stream> Function(SnapSearchParameters) createMockSnapSearchProvider( Stream> Function(String) createMockDebSearchProvider( Map> searchResults) { - return (String query) => Stream.value( + return (query) => Stream.value( searchResults.entries.firstWhereOrNull((e) => e.key == query)?.value ?? [], ); diff --git a/packages/app_center_ratings_client/analysis_options.yaml b/packages/app_center_ratings_client/analysis_options.yaml index cf89ba946..800b2bc35 100644 --- a/packages/app_center_ratings_client/analysis_options.yaml +++ b/packages/app_center_ratings_client/analysis_options.yaml @@ -1 +1,6 @@ include: package:ubuntu_lints/analysis_options.yaml + +analyzer: + exclude: + - "**/*.pb*.dart" + diff --git a/packages/app_center_ratings_client/lib/src/chart.dart b/packages/app_center_ratings_client/lib/src/chart.dart index 41c6ffd1f..f433339cc 100644 --- a/packages/app_center_ratings_client/lib/src/chart.dart +++ b/packages/app_center_ratings_client/lib/src/chart.dart @@ -1,8 +1,8 @@ +import 'package:app_center_ratings_client/src/generated/ratings_features_chart.pb.dart' + as pb; +import 'package:app_center_ratings_client/src/ratings.dart' as common; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'generated/ratings_features_chart.pb.dart' as pb; -import 'ratings.dart' as common; - part 'chart.freezed.dart'; @freezed @@ -22,8 +22,8 @@ enum Timeframe { extension ChartDataFromDTO on pb.ChartData { ChartData fromDTO() { return ChartData( - rating: this.rating.fromDTO(), - rawRating: this.rawRating, + rating: rating.fromDTO(), + rawRating: rawRating, ); } } diff --git a/packages/app_center_ratings_client/lib/src/generated/ratings_features_app.pbgrpc.dart b/packages/app_center_ratings_client/lib/src/generated/ratings_features_app.pbgrpc.dart index 28d0ec8d3..e9c187c60 100644 --- a/packages/app_center_ratings_client/lib/src/generated/ratings_features_app.pbgrpc.dart +++ b/packages/app_center_ratings_client/lib/src/generated/ratings_features_app.pbgrpc.dart @@ -12,26 +12,24 @@ import 'dart:async' as $async; import 'dart:core' as $core; +import 'package:app_center_ratings_client/src/generated/ratings_features_app.pb.dart' + as $0; import 'package:grpc/service_api.dart' as $grpc; import 'package:protobuf/protobuf.dart' as $pb; -import 'ratings_features_app.pb.dart' as $0; - export 'ratings_features_app.pb.dart'; @$pb.GrpcServiceName('ratings.features.app.App') class AppClient extends $grpc.Client { - static final _$getRating = - $grpc.ClientMethod<$0.GetRatingRequest, $0.GetRatingResponse>( - '/ratings.features.app.App/GetRating', - ($0.GetRatingRequest value) => value.writeToBuffer(), - ($core.List<$core.int> value) => - $0.GetRatingResponse.fromBuffer(value)); - AppClient($grpc.ClientChannel channel, {$grpc.CallOptions? options, $core.Iterable<$grpc.ClientInterceptor>? interceptors}) : super(channel, options: options, interceptors: interceptors); + static final _$getRating = + $grpc.ClientMethod<$0.GetRatingRequest, $0.GetRatingResponse>( + '/ratings.features.app.App/GetRating', + (value) => value.writeToBuffer(), + (value) => $0.GetRatingResponse.fromBuffer(value)); $grpc.ResponseFuture<$0.GetRatingResponse> getRating( $0.GetRatingRequest request, @@ -42,17 +40,16 @@ class AppClient extends $grpc.Client { @$pb.GrpcServiceName('ratings.features.app.App') abstract class AppServiceBase extends $grpc.Service { - $core.String get $name => 'ratings.features.app.App'; - AppServiceBase() { $addMethod($grpc.ServiceMethod<$0.GetRatingRequest, $0.GetRatingResponse>( 'GetRating', getRating_Pre, false, false, - ($core.List<$core.int> value) => $0.GetRatingRequest.fromBuffer(value), - ($0.GetRatingResponse value) => value.writeToBuffer())); + (value) => $0.GetRatingRequest.fromBuffer(value), + (value) => value.writeToBuffer())); } + $core.String get $name => 'ratings.features.app.App'; $async.Future<$0.GetRatingResponse> getRating_Pre($grpc.ServiceCall call, $async.Future<$0.GetRatingRequest> request) async { diff --git a/packages/app_center_ratings_client/lib/src/generated/ratings_features_chart.pbgrpc.dart b/packages/app_center_ratings_client/lib/src/generated/ratings_features_chart.pbgrpc.dart index 9a39d0a7b..d6c2ec188 100644 --- a/packages/app_center_ratings_client/lib/src/generated/ratings_features_chart.pbgrpc.dart +++ b/packages/app_center_ratings_client/lib/src/generated/ratings_features_chart.pbgrpc.dart @@ -12,26 +12,24 @@ import 'dart:async' as $async; import 'dart:core' as $core; +import 'package:app_center_ratings_client/src/generated/ratings_features_chart.pb.dart' + as $0; import 'package:grpc/service_api.dart' as $grpc; import 'package:protobuf/protobuf.dart' as $pb; -import 'ratings_features_chart.pb.dart' as $0; - export 'ratings_features_chart.pb.dart'; @$pb.GrpcServiceName('ratings.features.chart.Chart') class ChartClient extends $grpc.Client { - static final _$getChart = - $grpc.ClientMethod<$0.GetChartRequest, $0.GetChartResponse>( - '/ratings.features.chart.Chart/GetChart', - ($0.GetChartRequest value) => value.writeToBuffer(), - ($core.List<$core.int> value) => - $0.GetChartResponse.fromBuffer(value)); - ChartClient($grpc.ClientChannel channel, {$grpc.CallOptions? options, $core.Iterable<$grpc.ClientInterceptor>? interceptors}) : super(channel, options: options, interceptors: interceptors); + static final _$getChart = + $grpc.ClientMethod<$0.GetChartRequest, $0.GetChartResponse>( + '/ratings.features.chart.Chart/GetChart', + (value) => value.writeToBuffer(), + (value) => $0.GetChartResponse.fromBuffer(value)); $grpc.ResponseFuture<$0.GetChartResponse> getChart($0.GetChartRequest request, {$grpc.CallOptions? options}) { @@ -41,17 +39,16 @@ class ChartClient extends $grpc.Client { @$pb.GrpcServiceName('ratings.features.chart.Chart') abstract class ChartServiceBase extends $grpc.Service { - $core.String get $name => 'ratings.features.chart.Chart'; - ChartServiceBase() { $addMethod($grpc.ServiceMethod<$0.GetChartRequest, $0.GetChartResponse>( 'GetChart', getChart_Pre, false, false, - ($core.List<$core.int> value) => $0.GetChartRequest.fromBuffer(value), - ($0.GetChartResponse value) => value.writeToBuffer())); + (value) => $0.GetChartRequest.fromBuffer(value), + (value) => value.writeToBuffer())); } + $core.String get $name => 'ratings.features.chart.Chart'; $async.Future<$0.GetChartResponse> getChart_Pre( $grpc.ServiceCall call, $async.Future<$0.GetChartRequest> request) async { diff --git a/packages/app_center_ratings_client/lib/src/generated/ratings_features_user.pbgrpc.dart b/packages/app_center_ratings_client/lib/src/generated/ratings_features_user.pbgrpc.dart index 9a6ac75a3..3c357f791 100644 --- a/packages/app_center_ratings_client/lib/src/generated/ratings_features_user.pbgrpc.dart +++ b/packages/app_center_ratings_client/lib/src/generated/ratings_features_user.pbgrpc.dart @@ -12,47 +12,44 @@ import 'dart:async' as $async; import 'dart:core' as $core; +import 'package:app_center_ratings_client/src/generated/google/protobuf/empty.pb.dart' + as $1; +import 'package:app_center_ratings_client/src/generated/ratings_features_user.pb.dart' + as $0; import 'package:grpc/service_api.dart' as $grpc; import 'package:protobuf/protobuf.dart' as $pb; -import 'google/protobuf/empty.pb.dart' as $1; -import 'ratings_features_user.pb.dart' as $0; - export 'ratings_features_user.pb.dart'; @$pb.GrpcServiceName('ratings.features.user.User') class UserClient extends $grpc.Client { + UserClient($grpc.ClientChannel channel, + {$grpc.CallOptions? options, + $core.Iterable<$grpc.ClientInterceptor>? interceptors}) + : super(channel, options: options, interceptors: interceptors); static final _$authenticate = $grpc.ClientMethod<$0.AuthenticateRequest, $0.AuthenticateResponse>( '/ratings.features.user.User/Authenticate', - ($0.AuthenticateRequest value) => value.writeToBuffer(), - ($core.List<$core.int> value) => - $0.AuthenticateResponse.fromBuffer(value)); + (value) => value.writeToBuffer(), + (value) => $0.AuthenticateResponse.fromBuffer(value)); static final _$delete = $grpc.ClientMethod<$1.Empty, $1.Empty>( '/ratings.features.user.User/Delete', - ($1.Empty value) => value.writeToBuffer(), - ($core.List<$core.int> value) => $1.Empty.fromBuffer(value)); + (value) => value.writeToBuffer(), + (value) => $1.Empty.fromBuffer(value)); static final _$vote = $grpc.ClientMethod<$0.VoteRequest, $1.Empty>( '/ratings.features.user.User/Vote', - ($0.VoteRequest value) => value.writeToBuffer(), - ($core.List<$core.int> value) => $1.Empty.fromBuffer(value)); + (value) => value.writeToBuffer(), + (value) => $1.Empty.fromBuffer(value)); static final _$listMyVotes = $grpc.ClientMethod<$0.ListMyVotesRequest, $0.ListMyVotesResponse>( '/ratings.features.user.User/ListMyVotes', - ($0.ListMyVotesRequest value) => value.writeToBuffer(), - ($core.List<$core.int> value) => - $0.ListMyVotesResponse.fromBuffer(value)); + (value) => value.writeToBuffer(), + (value) => $0.ListMyVotesResponse.fromBuffer(value)); static final _$getSnapVotes = $grpc.ClientMethod<$0.GetSnapVotesRequest, $0.GetSnapVotesResponse>( '/ratings.features.user.User/GetSnapVotes', - ($0.GetSnapVotesRequest value) => value.writeToBuffer(), - ($core.List<$core.int> value) => - $0.GetSnapVotesResponse.fromBuffer(value)); - - UserClient($grpc.ClientChannel channel, - {$grpc.CallOptions? options, - $core.Iterable<$grpc.ClientInterceptor>? interceptors}) - : super(channel, options: options, interceptors: interceptors); + (value) => value.writeToBuffer(), + (value) => $0.GetSnapVotesResponse.fromBuffer(value)); $grpc.ResponseFuture<$0.AuthenticateResponse> authenticate( $0.AuthenticateRequest request, @@ -85,8 +82,6 @@ class UserClient extends $grpc.Client { @$pb.GrpcServiceName('ratings.features.user.User') abstract class UserServiceBase extends $grpc.Service { - $core.String get $name => 'ratings.features.user.User'; - UserServiceBase() { $addMethod( $grpc.ServiceMethod<$0.AuthenticateRequest, $0.AuthenticateResponse>( @@ -94,42 +89,40 @@ abstract class UserServiceBase extends $grpc.Service { authenticate_Pre, false, false, - ($core.List<$core.int> value) => - $0.AuthenticateRequest.fromBuffer(value), - ($0.AuthenticateResponse value) => value.writeToBuffer())); + (value) => $0.AuthenticateRequest.fromBuffer(value), + (value) => value.writeToBuffer())); $addMethod($grpc.ServiceMethod<$1.Empty, $1.Empty>( 'Delete', delete_Pre, false, false, - ($core.List<$core.int> value) => $1.Empty.fromBuffer(value), - ($1.Empty value) => value.writeToBuffer())); + (value) => $1.Empty.fromBuffer(value), + (value) => value.writeToBuffer())); $addMethod($grpc.ServiceMethod<$0.VoteRequest, $1.Empty>( 'Vote', vote_Pre, false, false, - ($core.List<$core.int> value) => $0.VoteRequest.fromBuffer(value), - ($1.Empty value) => value.writeToBuffer())); + (value) => $0.VoteRequest.fromBuffer(value), + (value) => value.writeToBuffer())); $addMethod( $grpc.ServiceMethod<$0.ListMyVotesRequest, $0.ListMyVotesResponse>( 'ListMyVotes', listMyVotes_Pre, false, false, - ($core.List<$core.int> value) => - $0.ListMyVotesRequest.fromBuffer(value), - ($0.ListMyVotesResponse value) => value.writeToBuffer())); + (value) => $0.ListMyVotesRequest.fromBuffer(value), + (value) => value.writeToBuffer())); $addMethod( $grpc.ServiceMethod<$0.GetSnapVotesRequest, $0.GetSnapVotesResponse>( 'GetSnapVotes', getSnapVotes_Pre, false, false, - ($core.List<$core.int> value) => - $0.GetSnapVotesRequest.fromBuffer(value), - ($0.GetSnapVotesResponse value) => value.writeToBuffer())); + (value) => $0.GetSnapVotesRequest.fromBuffer(value), + (value) => value.writeToBuffer())); } + $core.String get $name => 'ratings.features.user.User'; $async.Future<$0.AuthenticateResponse> authenticate_Pre( $grpc.ServiceCall call, diff --git a/packages/app_center_ratings_client/lib/src/ratings.dart b/packages/app_center_ratings_client/lib/src/ratings.dart index 0efe6969a..c4dd35b13 100644 --- a/packages/app_center_ratings_client/lib/src/ratings.dart +++ b/packages/app_center_ratings_client/lib/src/ratings.dart @@ -1,18 +1,17 @@ +import 'package:app_center_ratings_client/src/generated/ratings_features_common.pb.dart' + as pb; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'generated/ratings_features_common.pb.dart' as pb; - @immutable class Rating { - final String snapId; - final int totalVotes; - final RatingsBand ratingsBand; - const Rating({ required this.snapId, required this.totalVotes, required this.ratingsBand, }); + final String snapId; + final int totalVotes; + final RatingsBand ratingsBand; @override bool operator ==(Object other) { @@ -41,9 +40,9 @@ enum RatingsBand { extension RatingFromDTO on pb.Rating { Rating fromDTO() { return Rating( - snapId: this.snapId, - totalVotes: this.totalVotes.toInt(), - ratingsBand: this.ratingsBand.fromDTO(), + snapId: snapId, + totalVotes: totalVotes.toInt(), + ratingsBand: ratingsBand.fromDTO(), ); } } diff --git a/packages/app_center_ratings_client/lib/src/ratings_client.dart b/packages/app_center_ratings_client/lib/src/ratings_client.dart index c4d235d47..b0814ea6f 100644 --- a/packages/app_center_ratings_client/lib/src/ratings_client.dart +++ b/packages/app_center_ratings_client/lib/src/ratings_client.dart @@ -1,21 +1,19 @@ import 'dart:async'; +import 'package:app_center_ratings_client/src/chart.dart'; +import 'package:app_center_ratings_client/src/generated/google/protobuf/empty.pb.dart'; +import 'package:app_center_ratings_client/src/generated/ratings_features_app.pbgrpc.dart' + as app_pb; +import 'package:app_center_ratings_client/src/generated/ratings_features_chart.pbgrpc.dart' + as chart_pb; +import 'package:app_center_ratings_client/src/generated/ratings_features_user.pbgrpc.dart' + as user_pb; +import 'package:app_center_ratings_client/src/ratings.dart'; +import 'package:app_center_ratings_client/src/user.dart'; import 'package:grpc/grpc.dart'; import 'package:meta/meta.dart'; -import 'chart.dart'; -import 'generated/google/protobuf/empty.pb.dart'; -import 'generated/ratings_features_app.pbgrpc.dart' as appPb; -import 'generated/ratings_features_chart.pbgrpc.dart' as chartPb; -import 'generated/ratings_features_user.pbgrpc.dart' as userPb; -import 'ratings.dart'; -import 'user.dart'; - class RatingsClient { - late appPb.AppClient _appClient; - late userPb.UserClient _userClient; - late chartPb.ChartClient _chartClient; - RatingsClient(String serverUrl, int port) { final channel = ClientChannel( serverUrl, @@ -24,9 +22,9 @@ class RatingsClient { credentials: ChannelCredentials.insecure(), ), ); - _appClient = appPb.AppClient(channel); - _userClient = userPb.UserClient(channel); - _chartClient = chartPb.ChartClient(channel); + _appClient = app_pb.AppClient(channel); + _userClient = user_pb.UserClient(channel); + _chartClient = chart_pb.ChartClient(channel); } // Additional constructor for testing @@ -36,9 +34,12 @@ class RatingsClient { this._userClient, this._chartClient, ); + late app_pb.AppClient _appClient; + late user_pb.UserClient _userClient; + late chart_pb.ChartClient _chartClient; Future authenticate(String id) async { - final request = userPb.AuthenticateRequest(id: id); + final request = user_pb.AuthenticateRequest(id: id); final grpcResponse = await _userClient.authenticate(request); return grpcResponse.token; } @@ -51,7 +52,7 @@ class RatingsClient { } Future> getChart(Timeframe timeframe, String token) async { - final request = chartPb.GetChartRequest(timeframe: timeframe.toDTO()); + final request = chart_pb.GetChartRequest(timeframe: timeframe.toDTO()); final callOptions = CallOptions(metadata: {'authorization': 'Bearer $token'}); final grpcResponse = @@ -63,7 +64,7 @@ class RatingsClient { String snapId, String token, ) async { - final request = appPb.GetRatingRequest(snapId: snapId); + final request = app_pb.GetRatingRequest(snapId: snapId); final callOptions = CallOptions(metadata: {'authorization': 'Bearer $token'}); final grpcResponse = await _appClient.getRating( @@ -73,8 +74,8 @@ class RatingsClient { return grpcResponse.rating.fromDTO(); } - Future> getSnapVotes(String snap_id, String token) async { - final request = userPb.GetSnapVotesRequest(snapId: snap_id); + Future> getSnapVotes(String snapId, String token) async { + final request = user_pb.GetSnapVotesRequest(snapId: snapId); final callOptions = CallOptions(metadata: {'authorization': 'Bearer $token'}); final grpcResponse = await _userClient.getSnapVotes( @@ -85,7 +86,7 @@ class RatingsClient { } Future> listMyVotes(String snapIdFilter, String token) async { - final request = userPb.ListMyVotesRequest(snapIdFilter: snapIdFilter); + final request = user_pb.ListMyVotesRequest(snapIdFilter: snapIdFilter); final callOptions = CallOptions(metadata: {'authorization': 'Bearer $token'}); final grpcResponse = await _userClient.listMyVotes( @@ -97,7 +98,7 @@ class RatingsClient { Future vote( String snapId, int snapRevision, bool voteUp, String token) async { - final request = userPb.VoteRequest( + final request = user_pb.VoteRequest( snapId: snapId, snapRevision: snapRevision, voteUp: voteUp, diff --git a/packages/app_center_ratings_client/lib/src/user.dart b/packages/app_center_ratings_client/lib/src/user.dart index 25edc1439..ea9c460a7 100644 --- a/packages/app_center_ratings_client/lib/src/user.dart +++ b/packages/app_center_ratings_client/lib/src/user.dart @@ -1,7 +1,7 @@ +import 'package:app_center_ratings_client/src/generated/ratings_features_user.pb.dart' + as pb; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'generated/ratings_features_user.pb.dart' as pb; - part 'user.freezed.dart'; @freezed @@ -17,10 +17,10 @@ class Vote with _$Vote { extension VoteFromDTO on pb.Vote { Vote fromDTO() { return Vote( - snapId: this.snapId, - snapRevision: this.snapRevision, - voteUp: this.voteUp, - dateTime: this.timestamp.toDateTime(), + snapId: snapId, + snapRevision: snapRevision, + voteUp: voteUp, + dateTime: timestamp.toDateTime(), ); } } diff --git a/packages/app_center_ratings_client/pubspec.yaml b/packages/app_center_ratings_client/pubspec.yaml index 9583730c4..d06d40abe 100644 --- a/packages/app_center_ratings_client/pubspec.yaml +++ b/packages/app_center_ratings_client/pubspec.yaml @@ -19,4 +19,4 @@ dev_dependencies: build_runner: ^2.4.6 mockito: ^5.4.3 test: ^1.21.0 - ubuntu_lints: ^0.1.0 \ No newline at end of file + ubuntu_lints: ^0.3.0 \ No newline at end of file diff --git a/packages/app_center_ratings_client/test/ratings_client_test.dart b/packages/app_center_ratings_client/test/ratings_client_test.dart index 3232c2da6..7f7bc5ffb 100644 --- a/packages/app_center_ratings_client/test/ratings_client_test.dart +++ b/packages/app_center_ratings_client/test/ratings_client_test.dart @@ -29,9 +29,9 @@ void main() { RatingsClient.withClients(mockAppClient, mockUserClient, mockChartClient); test('get chart', () async { - final snapId = 'foobar'; - final token = 'bar'; - final timeframe = chart.Timeframe.month; + const snapId = 'foobar'; + const token = 'bar'; + const timeframe = chart.Timeframe.month; final pbChartList = [ ChartData( rawRating: 3, @@ -43,7 +43,7 @@ void main() { ]; final expectedResponse = [ - chart.ChartData( + const chart.ChartData( rawRating: 3, rating: ratings.Rating( snapId: snapId, @@ -80,14 +80,14 @@ void main() { }); test('get rating', () async { - final snapId = 'foo'; - final token = 'bar'; + const snapId = 'foo'; + const token = 'bar'; final pbRating = Rating( snapId: snapId, totalVotes: Int64(105), ratingsBand: RatingsBand.NEUTRAL, ); - final expectedResponse = ratings.Rating( + const expectedResponse = ratings.Rating( snapId: snapId, totalVotes: 105, ratingsBand: ratings.RatingsBand.neutral, @@ -122,8 +122,8 @@ void main() { }); test('authenticate user', () async { - final id = 'foo'; - final token = 'bar'; + const id = 'foo'; + const token = 'bar'; final mockResponse = AuthenticateResponse(token: token); final request = AuthenticateRequest(id: id); when(mockUserClient.authenticate(request)).thenAnswer( @@ -137,8 +137,8 @@ void main() { }); test('list user votes', () async { - final snapIdFilter = 'foo'; - final token = 'bar'; + const snapIdFilter = 'foo'; + const token = 'bar'; final time = DateTime.now().toUtc(); final mockVotes = [ Vote( @@ -193,10 +193,10 @@ void main() { }); test('user votes', () async { - final snapId = 'foo'; - final snapRevision = 1; - final voteUp = true; - final token = 'bar'; + const snapId = 'foo'; + const snapRevision = 1; + const voteUp = true; + const token = 'bar'; final request = VoteRequest( snapId: snapId, snapRevision: snapRevision, @@ -227,8 +227,8 @@ void main() { }); test('user votes by snap id', () async { - final snapId = 'foo'; - final token = 'bar'; + const snapId = 'foo'; + const token = 'bar'; final time = DateTime.now().toUtc(); final mockVotes = [ Vote( @@ -284,7 +284,7 @@ void main() { }); test('delete user', () async { - final token = 'bar'; + const token = 'bar'; final request = Empty(); when(mockUserClient.delete( @@ -308,9 +308,8 @@ void main() { } class MockResponseFuture extends Mock implements ResponseFuture { - final T value; - MockResponseFuture(this.value); + final T value; @override Future then(FutureOr Function(T) onValue, {Function? onError}) => From dfe79d65760227aa1944605e3f7e8467f8cd11b5 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Tue, 12 Dec 2023 17:03:16 +0100 Subject: [PATCH 2/2] chore: Re-generate mocks --- packages/app_center/test/test_utils.mocks.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app_center/test/test_utils.mocks.dart b/packages/app_center/test/test_utils.mocks.dart index f6e4024ad..41e3e0160 100644 --- a/packages/app_center/test/test_utils.mocks.dart +++ b/packages/app_center/test/test_utils.mocks.dart @@ -2384,14 +2384,14 @@ class MockRatingsClient extends _i1.Mock implements _i11.RatingsClient { @override _i14.Future> getSnapVotes( - String? snap_id, + String? snapId, String? token, ) => (super.noSuchMethod( Invocation.method( #getSnapVotes, [ - snap_id, + snapId, token, ], ),