A new Flutter package. It is build for fetching media thumbnail associate to url. On adding urls it creates thumbnail wigdet.
Youtube Link:- https://www.youtube.com/watch?v=1MAuErvBtKA
Initial Screen | Add Thumbnail dialog | Image thumbnail |
---|---|---|
MediaListView widget | MediaListView with multiple children | Error on invaild link |
---|---|---|
await Thumbnail.addLink(
context: context,
/// callback that return thumbnail information in `MediaInfo` object
onLinkAdded: (mediaInfo) {
print("Thumbnail title:- ${mediaInfo.title}");
print("Thumbnail url:- ${mediaInfo.thumbnailUrl}");
},
);
Thumbnail.addLink()
to display add link dialog.Next
button.Next
button clicked it it fetch meta accoicated with link.Save
button will visible only if thumbnail image is fetched.Save
button clicked it return MediaInfo
object that contains thumbnail information like title, imageUrl etc.Cancel
button clicked it will close dialog and return nothing.List<MediaInfo> mediaList = [];
List<String> urlList = ["https://www.youtube.com/watch?v=uv54ec8Pg1k"];
MediaListView(
titleTextStyle: TextStyle(color:Colors.white),
titleTextBackGroundColor: Colors.grey,
overlayChild:Icon(Icons.save),
urls: urlList,
mediaList: mediaList,
onPressed: (url) {
print(url);
},
);
dependencies:
add_thumbnail: ^0.0.1
import 'package:add_thumbnail/add_thumbnail.dart';
List<MediaInfo> mediaList = [];
List<String> urlList = ["https://www.youtube.com/watch?v=uv54ec8Pg1k"];
async
function and call Thumbnail.addLink()
void openAddLinkDialog() async {
// Open thumbnail dialog to add link
await Thumbnail.addLink(
context: context,
/// callback that return thumbnail information in `MediaInfo` object
onLinkAdded: (mediaInfo) {
if (mediaInfo != null && mediaInfo.thumbnailUrl.isNotEmpty) {
setState(() {
mediaList.add(mediaInfo);
});
}
},
);
}
Widget getMediaList() {
return MediaListView(
onPressed: (url) {
print(url);
},
urls: urlList,
mediaList: mediaList,
);
}
openAddLinkDialog
function on floatingActionButton
pressed
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFEEEEEE),
appBar: AppBar(
title: Text(widget.title),
),
body:(mediaList == null || mediaList.isEmpty) && (urlList == null || urlList.isEmpty)
? Center(
child: Text(
"Press add button to add thumbnail.",
style: TextStyle(color: Colors.black54, fontSize: 16),
),
)
: getMediaList(),
floatingActionButton: FloatingActionButton(
onPressed: openAddLinkDialog,
tooltip: 'Add link',
child: Icon(Icons.add),
),
);
}
I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request.
Author: TheAlphamerc
GitHub: https://github.com/TheAlphamerc/flutter_plugin_add_thumbnail
#flutter #dart #mobile-apps