59 lines
1.8 KiB
Dart
59 lines
1.8 KiB
Dart
import 'package:fipy/globals.dart';
|
|
import 'package:fipy/models/track.dart';
|
|
import 'package:fipy/providers/home.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
|
|
|
|
class DownloadTrack extends StatelessWidget {
|
|
const DownloadTrack({Key? key, this.track}) : super(key: key);
|
|
|
|
final Track? track;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final hp = Provider.of<HomeProvider>(context, listen: false);
|
|
int isDownloading = -1;
|
|
final yt = YoutubeExplode();
|
|
|
|
final track = this.track ??
|
|
hp.currentTrack ??
|
|
Track(number: -1, title: 'title', artiste: 'artiste');
|
|
|
|
return Visibility(
|
|
visible: track.number != -1,
|
|
child: InkWell(onTap: () async {
|
|
isDownloading = track.number;
|
|
hp.reload();
|
|
if (track.id == null) {
|
|
final secondMatch = track.artiste == '' ? track.album : track.artiste;
|
|
final resultUrl =
|
|
await yt.search.search('${track.title} ${secondMatch!}');
|
|
track.id = resultUrl.first.id.value;
|
|
}
|
|
if (track.id != null) {
|
|
// ignore: use_build_context_synchronously
|
|
hp.downloadMusic(context, track);
|
|
}
|
|
isDownloading = -1;
|
|
yt.close();
|
|
// hp.reload();
|
|
}, child: Consumer<HomeProvider>(builder: (context, _, __) {
|
|
return Row(children: [
|
|
const SizedBox(width: 37),
|
|
isDownloading == track.number
|
|
? SizedBox(
|
|
height: 20,
|
|
width: 20,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
color: Colors.grey[500],
|
|
),
|
|
)
|
|
: Icon(Icons.download, color: Colors.grey[500]),
|
|
]);
|
|
})),
|
|
);
|
|
}
|
|
}
|