youtube_downloader_totalxsoftware
is a Flutter package that simplifies downloading YouTube videos with customizable quality selection, notifications, and thumbnail handling.
Developed by Totalx Software
- Select video quality through a customizable bottom sheet.
- Download video files and their thumbnails.
- Notifications for download progress
Add the following dependency in your pubspec.yaml
:
dependencies:
youtube_downloader_totalxsoftware: ^1.0.0
Then run:
flutter pub get
Call the initialize
method to set up notifications (required for Android):
await YoutubeDownloaderTotalxsoftware.initialize(
androidNotificationIcon: 'resource://drawable/notification_icon',
);
Save your notification icon in the following res/drawable
directories based on screen density:
-
res/drawable-mdpi
: For medium-density screens (1x). -
res/drawable-hdpi
: For high-density screens (1.5x). -
res/drawable-xhdpi
: For extra-high-density screens (2x). -
res/drawable-xxhdpi
: For extra-extra-high-density screens (3x). -
res/drawable-xxxhdpi
: For extra-extra-extra-high-density screens (4x).
Make sure the icon file is named consistently across all folders, for example: notification_icon.png.
YoutubeDownloaderTotalxsoftware().downloadYoutubeVideo(
context: context,
ytUrl: 'https://youtube.com/shorts/G-2INFh7hpk?si=VWfSRsTYMzX69vpK',
error: (e) => log('Error: $e'),
onProgress: (progress) {
this.progress = progress;
setState(() {});
},
onComplete: (file,thumbnail) {
log('Download complete: ${file.path}');
log('Download complete thumbnail: ${thumbnail.path}');
},
onLoading: (isLoading) {
// Loading
},
qualityBuilderSheet: qualityBuilderSheet,
);
Customize your video quality selection UI:
Widget qualityBuilderSheet(videos, onSelected) {
return Container(
margin: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.grey[900],
borderRadius: BorderRadius.circular(10),
),
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Center(
child: Container(
width: 40,
height: 4,
margin: const EdgeInsets.only(bottom: 20),
decoration: BoxDecoration(
color: Colors.grey[700],
borderRadius: BorderRadius.circular(10),
),
),
),
const Align(
alignment: Alignment.centerLeft,
child: Text(
'Download quality',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 16),
for (var video in videos)
ListTile(
onTap: () => onSelected(video),
title: Text(
video.qualityLabel,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
),
trailing: Text(
'${video.size}',
style: TextStyle(
color: Colors.grey[400],
fontSize: 14,
),
),
),
const SizedBox(height: 16),
],
),
);
}
- Add the following permissions to your
AndroidManifest.xml
:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Ensure your Info.plist
includes the required keys for network and storage access.
Explore more about TotalX at www.totalx.in - Your trusted software development company!
Join the vibrant Flutter Firebase Kerala community for updates, discussions, and support:
Flutter Firebase Kerala Totax