fix(downloader): flutter downloader exception on desktop platform and too much width of TrackTile index no.

This commit is contained in:
Kingkor Roy Tirtho 2022-08-14 22:39:29 +06:00
parent 0476bf7cee
commit d6687603d1
5 changed files with 31 additions and 8 deletions

View File

@ -196,7 +196,7 @@ class TrackTile extends HookConsumerWidget {
),
SizedBox(
height: 20,
width: 25,
width: 15,
child: Text(
(track.key + 1).toString(),
textAlign: TextAlign.center,

View File

@ -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!,
@ -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",
@ -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(
@ -136,6 +142,9 @@ class TracksTableView extends HookConsumerWidget {
);
});
}
selected.value = [];
showCheck.value = false;
await queue.onComplete;
break;
}

View File

@ -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')

View File

@ -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];
}
}),
),
);
}

View File

@ -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];
}
}),
),
);
}