Skip to content

Commit

Permalink
Compact dependents history item
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexios80 committed Dec 8, 2023
1 parent 156e29b commit 73ff252
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
60 changes: 60 additions & 0 deletions pub_stats/lib/extension/diff_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
import 'package:pub_stats/constant/app_theme.dart';
import 'package:pub_stats/constant/constants.dart';
import 'package:pub_stats_core/pub_stats_core.dart';
import 'package:url_launcher/url_launcher_string.dart';

extension DiffExtension on Diff {
Widget get widget => switch (this) {
(final StringDiff diff) => Text(diff.text),
(final SetDiff diff) => Row(
children: [
PackageListButton(
packages: diff.added.cast<String>(),
qualifier: 'Added',
),
const SizedBox(width: 8),
PackageListButton(
packages: diff.removed.cast<String>(),
qualifier: 'Removed',
),
],
),
};
}

class PackageListButton extends StatelessWidget {
final Set<String> packages;
final String qualifier;

const PackageListButton({
super.key,
required this.packages,
required this.qualifier,
});

@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
shape: RoundedRectangleBorder(borderRadius: AppTheme.pillRadius),
clipBehavior: Clip.antiAlias,
child: PopupMenuButton(
tooltip: 'Show packages',
itemBuilder: (context) => packages
.map(
(package) => PopupMenuItem(
child: Text(package),
onTap: () =>
launchUrlString(Constants.pubPackageBaseUrl + package),
),
)
.toList(),
child: Padding(
padding: const EdgeInsets.all(8),
child: Text('${packages.length} $qualifier'),
),
),
);
}
}
3 changes: 2 additions & 1 deletion pub_stats/lib/view/widget/stats/diff_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:firebase_ui_database/firebase_ui_database.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:pub_stats/controller/data_controller.dart';
import 'package:pub_stats/extension/diff_extension.dart';
import 'package:pub_stats/format/formatting.dart';
import 'package:pub_stats_core/pub_stats_core.dart';
import 'package:recase/recase.dart';
Expand Down Expand Up @@ -51,7 +52,7 @@ class DiffList extends StatelessWidget {
width: 100,
child: Text(e.key.name.titleCase),
),
title: Text(e.value.text),
title: e.value.widget,
trailing: Text(Formatting.shortDate(date)),
),
)
Expand Down
8 changes: 4 additions & 4 deletions pub_stats_core/lib/src/model/diff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';

part 'diff.g.dart';

abstract class Diff {
sealed class Diff {
bool get different;
String get text;

Expand Down Expand Up @@ -31,15 +31,15 @@ class StringDiff extends Diff {

@JsonSerializable(constructor: '_')
class SetDiff extends Diff {
final Set added;
final Set removed;
final Set<Object> added;
final Set<Object> removed;

SetDiff._({
this.added = const {},
this.removed = const {},
});

SetDiff(Set before, Set after)
SetDiff(Set<Object> before, Set<Object> after)
: added = after.difference(before),
removed = before.difference(after);

Expand Down
9 changes: 7 additions & 2 deletions pub_stats_core/lib/src/model/diff.g.dart

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

0 comments on commit 73ff252

Please sign in to comment.