From 426a5e4d3e653d40ad311b39dc7701c81d25b139 Mon Sep 17 00:00:00 2001 From: leoafarias <435833+leoafarias@users.noreply.github.com> Date: Sat, 19 Jun 2021 12:13:23 -0400 Subject: [PATCH] Added flutter favorites and github trending --- .../flutter_favorite_list_item.dart | 81 +++++++++++++------ .../packages/flutter_favorite.dto.dart | 35 ++++---- .../modules/packages/packages.provider.dart | 11 +-- lib/src/modules/packages/packages.screen.dart | 6 +- lib/src/version.dart | 2 +- pubspec.yaml | 2 +- 6 files changed, 84 insertions(+), 53 deletions(-) diff --git a/lib/src/modules/packages/components/flutter_favorite_list_item.dart b/lib/src/modules/packages/components/flutter_favorite_list_item.dart index 6c588087..f78f8fcf 100644 --- a/lib/src/modules/packages/components/flutter_favorite_list_item.dart +++ b/lib/src/modules/packages/components/flutter_favorite_list_item.dart @@ -1,10 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; -import 'package:sidekick/src/modules/common/utils/open_link.dart'; +import 'package:sidekick/generated/l10n.dart'; import 'package:sidekick/src/modules/packages/flutter_favorite.dto.dart'; +import '../../../components/atoms/typography.dart'; +import '../../../modules/common/utils/open_link.dart'; import '../../common/molecules/list_tile.dart'; +import 'package_score_display.dart'; /// Flutter favorite list item class FlutterFavoriteListItem extends StatelessWidget { @@ -27,34 +30,66 @@ class FlutterFavoriteListItem extends StatelessWidget { children: [ SkListTile( title: Text(package.name), - trailing: OutlinedButton( - onPressed: () => openLink(package.url), - child: const Text('View'), - ), subtitle: Text( package.description, maxLines: 2, style: Theme.of(context).textTheme.caption, ), + trailing: PackageScoreDisplay(score: package.score), ), - Container( - height: 55, - child: Row( - children: [ - Expanded( - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SizedBox(width: 20), - Icon(MdiIcons.star, size: 15), - SizedBox(width: 5), - SizedBox(width: 20) - ], - ), - ) - ], - ), + Row( + children: [ + Expanded( + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const SizedBox(width: 20), + Caption(package.version), + Spacer(), + Tooltip( + message: S.of(context).details, + child: IconButton( + iconSize: 20, + splashRadius: 20, + icon: const Icon(MdiIcons.informationOutline), + onPressed: () async { + await openLink(package.url); + }, + ), + ), + const SizedBox(width: 10), + const Text('·'), + const SizedBox(width: 10), + Tooltip( + message: S.of(context).changelog, + child: IconButton( + iconSize: 20, + splashRadius: 20, + icon: const Icon(MdiIcons.textBox), + onPressed: () async { + await openLink(package.changelogUrl); + }, + ), + ), + const SizedBox(width: 10), + const Text('·'), + const SizedBox(width: 10), + Tooltip( + message: S.of(context).website, + child: IconButton( + iconSize: 20, + splashRadius: 20, + icon: const Icon(MdiIcons.earth), + onPressed: () async { + await openLink(package.url); + }, + ), + ), + const SizedBox(width: 10), + ], + ), + ) + ], ), ], ); diff --git a/lib/src/modules/packages/flutter_favorite.dto.dart b/lib/src/modules/packages/flutter_favorite.dto.dart index eb5379a7..2f9b203c 100644 --- a/lib/src/modules/packages/flutter_favorite.dto.dart +++ b/lib/src/modules/packages/flutter_favorite.dto.dart @@ -4,6 +4,8 @@ import 'dart:convert'; +import 'package:pub_api_client/pub_api_client.dart'; + class FlutterFavorite { FlutterFavorite({ this.name, @@ -11,11 +13,7 @@ class FlutterFavorite { this.description, this.url, this.changelogUrl, - this.grantedPoints, - this.maxPoints, - this.likeCount, - this.popularityScore, - this.lastUpdated, + this.score, }); final String name; @@ -23,11 +21,8 @@ class FlutterFavorite { final String description; final String url; final String changelogUrl; - final String grantedPoints; - final String maxPoints; - final String likeCount; - final String popularityScore; - final DateTime lastUpdated; + + final PackageScore score; factory FlutterFavorite.fromJson(String str) => FlutterFavorite.fromMap(json.decode(str)); @@ -40,11 +35,15 @@ class FlutterFavorite { description: json['description'], url: json['url'], changelogUrl: json['changelogUrl'], - grantedPoints: json['grantedPoints'], - maxPoints: json['maxPoints'], - likeCount: json['likeCount'], - popularityScore: json['popularityScore'], - lastUpdated: DateTime.parse(json['lastUpdated']), + score: PackageScore( + grantedPoints: int.parse(json['grantedPoints']), + maxPoints: int.parse((json['maxPoints'])), + likeCount: int.parse((json['likeCount'])), + popularityScore: double.parse((json['popularityScore'])), + lastUpdated: DateTime.parse( + json['lastUpdated'], + ), + ), ); Map toMap() => { @@ -53,10 +52,6 @@ class FlutterFavorite { 'description': description, 'url': url, 'changelogUrl': changelogUrl, - 'grantedPoints': grantedPoints, - 'maxPoints': maxPoints, - 'likeCount': likeCount, - 'popularityScore': popularityScore, - 'lastUpdated': lastUpdated.toIso8601String(), + 'score': score.toJson() }; } diff --git a/lib/src/modules/packages/packages.provider.dart b/lib/src/modules/packages/packages.provider.dart index 02ccf1b2..b45918e6 100644 --- a/lib/src/modules/packages/packages.provider.dart +++ b/lib/src/modules/packages/packages.provider.dart @@ -6,6 +6,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:pub_api_client/pub_api_client.dart'; import 'package:pubspec_parse/pubspec_parse.dart'; import 'package:sidekick/src/modules/packages/flutter_favorite.dto.dart'; +import 'package:sidekick/src/modules/packages/package.dto.dart'; import 'package:sidekick/src/modules/packages/trending_package.dto.dart'; import '../../modules/common/utils/dependencies.dart'; @@ -36,7 +37,9 @@ final flutterFavoritesProvider = FutureProvider>( final data = jsonDecode(response.data); final favorites = []; for (final item in data) { - favorites.add(FlutterFavorite.fromMap(item)); + favorites.add( + FlutterFavorite.fromMap(item), + ); } return favorites; @@ -50,7 +53,7 @@ final packagesProvider = FutureProvider((ref) async { final packages = {}; if (projects.isEmpty) { - return []; + return []; } // Retrieve cache if exits @@ -71,7 +74,5 @@ final packagesProvider = FutureProvider((ref) async { } } - final packageList = await fetchPackages(packages); - - return packageList; + return fetchPackages(packages); }); diff --git a/lib/src/modules/packages/packages.screen.dart b/lib/src/modules/packages/packages.screen.dart index 24fd8e6c..3a10ec47 100644 --- a/lib/src/modules/packages/packages.screen.dart +++ b/lib/src/modules/packages/packages.screen.dart @@ -20,9 +20,9 @@ class PackagesScreen extends StatelessWidget { labelPadding: EdgeInsets.zero, indicatorColor: Theme.of(context).accentColor, tabs: [ - Tab(text: '⚡ Trending'), - Tab(text: '📦 Most Used Packages'), - Tab(text: '📦 Flutter Favorites'), + Tab(text: '⚡ Trending'), + Tab(text: '📦 Most Used Packages'), + Tab(text: '💙 Flutter Favorites'), ], ), ), diff --git a/lib/src/version.dart b/lib/src/version.dart index 99e44cce..5b6bfb4d 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '0.0.7'; +const packageVersion = '0.1.0'; diff --git a/pubspec.yaml b/pubspec.yaml index 92953bc0..98bcf3e0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter Version Manager. publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 0.0.7 +version: 0.1.0 environment: sdk: ">=2.7.0 <3.0.0"