Skip to content

Commit

Permalink
Added flutter favorites and github trending
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Jun 19, 2021
1 parent 0149e31 commit 426a5e4
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 53 deletions.
81 changes: 58 additions & 23 deletions lib/src/modules/packages/components/flutter_favorite_list_item.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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),
],
),
)
],
),
],
);
Expand Down
35 changes: 15 additions & 20 deletions lib/src/modules/packages/flutter_favorite.dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,25 @@

import 'dart:convert';

import 'package:pub_api_client/pub_api_client.dart';

class FlutterFavorite {
FlutterFavorite({
this.name,
this.version,
this.description,
this.url,
this.changelogUrl,
this.grantedPoints,
this.maxPoints,
this.likeCount,
this.popularityScore,
this.lastUpdated,
this.score,
});

final String name;
final String version;
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));
Expand All @@ -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<String, dynamic> toMap() => {
Expand All @@ -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()
};
}
11 changes: 6 additions & 5 deletions lib/src/modules/packages/packages.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -36,7 +37,9 @@ final flutterFavoritesProvider = FutureProvider<List<FlutterFavorite>>(
final data = jsonDecode(response.data);
final favorites = <FlutterFavorite>[];
for (final item in data) {
favorites.add(FlutterFavorite.fromMap(item));
favorites.add(
FlutterFavorite.fromMap(item),
);
}

return favorites;
Expand All @@ -50,7 +53,7 @@ final packagesProvider = FutureProvider((ref) async {
final packages = <String, int>{};

if (projects.isEmpty) {
return [];
return <PackageDetail>[];
}

// Retrieve cache if exits
Expand All @@ -71,7 +74,5 @@ final packagesProvider = FutureProvider((ref) async {
}
}

final packageList = await fetchPackages(packages);

return packageList;
return fetchPackages(packages);
});
6 changes: 3 additions & 3 deletions lib/src/modules/packages/packages.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 426a5e4

Please sign in to comment.