Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/services/state_services/torrent_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ class TorrentService extends ChangeNotifier {
return torrentsList.where((torrent) => torrent.label == label).toList();
}

/// Returns the count of torrents matching a given [Filter]
int getFilterCount(Filter filter) {
List<Torrent>? filtered = _filterList(torrentsList.value, filter);
return filtered?.length ?? 0;
}

/// Reloads list of [Torrent]s from seedbox
refreshTorrentList() async {
log.v("Torrent refresh function called");
Expand Down
20 changes: 20 additions & 0 deletions lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FilterTile extends StatelessWidget {
Widget build(BuildContext context) {
bool isSelected =
(model.selectedFilter == filter && !model.isLabelSelected);
int count = model.getFilterCount(filter);
return Container(
color: isSelected ? Theme.of(context).colorScheme.secondary : null,
child: ListTile(
Expand All @@ -36,6 +37,25 @@ class FilterTile extends StatelessWidget {
? Colors.black
: Colors.white),
),
trailing: Container(
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: isSelected
? Colors.white.withOpacity(0.3)
: Theme.of(context).colorScheme.secondary.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
),
child: Text(
'$count',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: isSelected
? Colors.white
: Theme.of(context).colorScheme.secondary,
),
),
),
onTap: () {
model.changeFilter(filter);
Navigator.pop(context);
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class DrawerViewModel extends BaseViewModel {

get listOfLabels => _torrentService?.listOfLabels;

/// Returns the count of torrents matching a given [Filter]
int getFilterCount(Filter filter) {
return _torrentService?.getFilterCount(filter) ?? 0;
}
Comment on lines +50 to +53
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if DrawerViewModel subscribes to TorrentService changes anywhere
rg -n "addListener|listen" lib/ui/widgets/smart_widgets/drawer/

# Check how drawer is used and if it rebuilds on torrent changes
rg -n -A 5 "DrawerViewModel" lib/ui/widgets/smart_widgets/drawer/

Repository: CCExtractor/rutorrent-flutter

Length of output: 1795


🏁 Script executed:

# Check DrawerViewModel.init() and full implementation
head -80 lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart

Repository: CCExtractor/rutorrent-flutter

Length of output: 3231


🏁 Script executed:

# Check FilterTile implementation and how it uses getFilterCount
fd -t f "filter_tile" lib/ --exec cat -n {} \;

Repository: CCExtractor/rutorrent-flutter

Length of output: 3785


🏁 Script executed:

# Check if BaseViewModel or TorrentService have built-in change propagation
rg -n "class BaseViewModel|class TorrentService" lib/

Repository: CCExtractor/rutorrent-flutter

Length of output: 170


Counts will not update live while the drawer is open, contradicting the PR's claimed reactive behavior.

The getFilterCount method reads synchronously without subscribing to TorrentService changes. DrawerViewModel doesn't listen to TorrentService (neither in init() nor elsewhere), so it won't call notifyListeners() when torrents change. FilterTile is a StatelessWidget that reads the count once at build time without any reactive wrapper, so the displayed count will only refresh when the drawer is reopened, not while it remains open and torrent states change.

To match the PR's description of reactive updates, DrawerViewModel should:

  1. Listen to TorrentService changes in init() and call notifyListeners() when the torrent list or filter counts change, or
  2. Wrap the count display in FilterTile with ValueListenableBuilder on TorrentService.torrentsList
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/ui/widgets/smart_widgets/drawer/drawer_viewmodel.dart` around lines 50 -
53, DrawerViewModel currently reads counts synchronously via getFilterCount and
never subscribes to TorrentService, so counts won’t update while the drawer is
open; fix by subscribing to TorrentService changes in DrawerViewModel.init()
(e.g., listen to TorrentService.torrentsList or its change stream) and call
notifyListeners() when the list or filter counts change, and remove the listener
in dispose(), or alternatively change the UI side by wrapping FilterTile’s count
display in a ValueListenableBuilder (or StreamBuilder) bound to
TorrentService.torrentsList so the count updates reactively; reference
methods/classes: DrawerViewModel.init(), getFilterCount(), notifyListeners(),
TorrentService.torrentsList, and FilterTile.


Filter get selectedFilter => _torrentService?.selectedFilter;

String get selectedLabel => _torrentService?.selectedLabel;
Expand Down