Skip to content

Commit

Permalink
fix(downloader): flutter downloader exception on desktop platform and…
Browse files Browse the repository at this point in the history
… too much width of TrackTile index no.
  • Loading branch information
KRTirtho committed Aug 14, 2022
1 parent 0476bf7 commit d668760
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/components/Shared/TrackTile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class TrackTile extends HookConsumerWidget {
),
SizedBox(
height: 20,
width: 25,
width: 15,
child: Text(
(track.key + 1).toString(),
textAlign: TextAlign.center,
Expand Down
21 changes: 15 additions & 6 deletions lib/components/Shared/TracksTableView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class TracksTableView extends HookConsumerWidget {
final selected = useState<List<String>>([]);
final showCheck = useState<bool>(false);

final selectedTracks = useMemoized(
() => tracks.where(
(track) => selected.value.contains(track.id),
),
[tracks],
);

return SliverList(
delegate: SliverChildListDelegate([
if (heading != null) heading!,
Expand Down Expand Up @@ -101,9 +108,11 @@ class TracksTableView extends HookConsumerWidget {
PopupMenuItem(
enabled: selected.value.isNotEmpty,
child: Row(
children: const [
Icon(Icons.file_download_outlined),
Text("Download"),
children: [
const Icon(Icons.file_download_outlined),
Text(
"Download ${selectedTracks.isNotEmpty ? "(${selectedTracks.length})" : ""}",
),
],
),
value: "download",
Expand All @@ -123,9 +132,6 @@ class TracksTableView extends HookConsumerWidget {
final queue = Queue(
delay: const Duration(seconds: 5),
);
final selectedTracks = tracks.where(
(track) => selected.value.contains(track.id),
);
for (final selectedTrack in selectedTracks) {
queue.add(() async {
downloader.addToQueue(
Expand All @@ -136,6 +142,9 @@ class TracksTableView extends HookConsumerWidget {
);
});
}

selected.value = [];
showCheck.value = false;
await queue.onComplete;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class _SpotubeState extends ConsumerState<Spotube> with WidgetsBindingObserver {
super.initState();
SharedPreferences.getInstance().then(((value) => localStorage = value));
WidgetsBinding.instance.addObserver(this);
FlutterDownloader.registerCallback(downloadCallback);
if (kIsMobile) FlutterDownloader.registerCallback(downloadCallback);
}

@pragma('vm:entry-point')
Expand Down
7 changes: 7 additions & 0 deletions lib/themes/dark-theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,12 @@ ThemeData darkTheme({
cardColor: backgroundMaterialColor[800],
canvasColor: backgroundMaterialColor[900],
listTileTheme: const ListTileThemeData(horizontalTitleGap: 0),
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
return accentMaterialColor[500];
}
}),
),
);
}
7 changes: 7 additions & 0 deletions lib/themes/light-theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,12 @@ ThemeData lightTheme({
),
cardColor: backgroundMaterialColor[50],
canvasColor: backgroundMaterialColor[50],
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
return accentMaterialColor[500];
}
}),
),
);
}

0 comments on commit d668760

Please sign in to comment.