Flutter: Show PDF cover image - android

I want to show the cover page of a pdf. But I don't know how to proceed. I have the URL of the pdf file and I want to display the front page like an image. I am using the pdf library but I don't know how to proceed.

I was also looking for the same a few days ago and found solution for it.
You can use this package:https://pub.dev/packages/pdf_render
you can use it like this in your widget:
import 'package:pdf_render/pdf_render_widgets2.dart';
...
PdfDocumentLoader(
assetName: 'assets/hello.pdf',
filePath: 'path of the file in local storage',
pageNumber: 1,
pageBuilder: (context, textureBuilder, pageSize) => textureBuilder()
)

In the pdf_thumbnail package, it uses pdfx package to get every single page.
Relevant line in the library.
final page = await document.getPage(pageNumber);
final pageImage = await page.render(
width: page.width,
height: page.height,
);
images[pageNumber] = pageImage!.bytes;
await page.close();

There is a sample Futter wrapper for a PDF SDK here https://github.com/PDFTron/pdftron-flutter. And a corresponding blog: https://www.pdftron.com/blog/flutter/build-a-document-viewer-in-flutter/

Related

How to pick image or video in flutter from one place?

I am using image_picker plugin to pick images and videos but in the plugin example you must select that you want to pick image or video from gallery . So is there is another way to show both together in one place ?
final ImagePicker _picker = ImagePicker();
// Pick an image
final XFile? image = await _picker.pickImage(source:
ImageSource.gallery);
// Pick a video
final XFile? image = await _picker.pickVideo(source:
ImageSource.gallery);
You are dependent on the plugin and its capabilities that you use. If it does not provide what you need, either you need to develop your plugin or try to use another one. If this plugin is changeable for you, please take a look following solutions:
1- wechat_assets_picker:
final List<AssetEntity>? assets = await AssetPicker.pickAssets(
context,
maxAssets: 2,
requestType: RequestType.all,
pickerTheme: appTheme,
textDelegate: EnglishTextDelegate(),
);
It provides different RequestType like audio, video, common, image, and all.
2- photo_manager:
final assetPathEntityList =
await PhotoManager.getAssetPathList(type: RequestType.all);
This plugin provides different RequestType like audio, video, common, image, and all too. The difference is there is no UI widget. Therefore you need to develop your UI and connect with this plugin.
If you have further questions, please don't hesitate to write in the comments.
You can do one thing, If you need to use image_picker then you can do following,
Give pin icon widget where you want to access media.
Show dialog on it which says, either select video or image.
Handle your methods accordingly.

Why is ImagePicker unable to pick multiple images

I'm trying to pick multiple images at once using the image_picker 0.7.5+3 package
so my code is simple , just one line to open the gallery to select from it
final images = await ImagePicker.platform.pickMultiImage();
but it's showing this error
enter image description here
i tried running flutter clean and deleting the app from emulator and retarting everything but it's the same problem,
note : using final images = await ImagePicker().getImage(source: ImageSource.gallery); it allows me to choose an image without any problems
final result = await ImagePicker().pickMultiImage(
imageQuality: 70,
maxWidth: 1440,
);
This should work as usual. If you are testing on android emulator and the default file manager, you have to long press the first image to multi-select.
Try a long click on one image, then it will let you pick multiple images.
I can't find anything in their API reference for pickMultiImage. I don't think it exists, unfortunately. There's a package called images_picker, maybe that helps you.

Flutter - Get all images from firebase storage

I am manually upload my images to firebase storage console in web. I want to download all images to my flutter android app. But it is getting only one image at a time with getDownloadUrl() method.
In android, listAll() method List all items (files) and prefixes (folders) under this StorageReference.
Like this, anyone suggest me in flutter.
I saw stack over flow answers like there is no api for download all images at once. But any suggestion/ideas would be great.
Finally got the solution.
Flutter package firebase_storage: ^3.0.6 has no method called listAll(). Only able to get single file/image download url using getDownloadURL() method from firebase storage.
Recently (19 hours ago, 16th Oct 2019) flutter team has added this functionality to get all files and folders using listAll() method. Below is the git link.
https://github.com/FirebaseExtended/flutterfire/pull/232
Need to use package in pubspec.yaml like below :
firebase_storage:
git:
url: git://github.com/danysz/flutterfire.git
ref: master
path: packages/firebase_storage
This is temporary solution until they update this package version firebase_storage: ^3.0.6
Example Code :
void getFirebaseImageFolder() {
final StorageReference storageRef =
FirebaseStorage.instance.ref().child('Gallery').child('Images');
storageRef.listAll().then((result) {
print("result is $result");
});
}
Hope it will be useful for many people. Happy coding!
in my cause this code is work me.. for every unique user and get list of images.. you can specify your reference path then get list of images
Tested image
static Future<List<Map<String, dynamic>>> fetchImages(
String uniqueUserId) async {
List<Map<String, dynamic>> files = [];
final ListResult result = await FirebaseStorage.instance
.ref()
.child('Gallery')
.child('images')
.child(uniqueUserId)
.list();
final List<Reference> allFiles = result.items;
print(allFiles.length);
await Future.forEach<Reference>(allFiles, (file) async {
final String fileUrl = await file.getDownloadURL();
final FullMetadata fileMeta = await file.getMetadata();
print('result is $fileUrl');
files.add({
'url': fileUrl,
'path': file.fullPath,
'uploaded_by': fileMeta.customMetadata['uploaded_by'] ?? 'Nobody',
'description':
fileMeta.customMetadata['description'] ?? 'No description'
});
});
return files;
}
if only need specific images you can use the Image.network(url) method for retrieving the image. only thing you have to done is you have to copy the access token related to your specific image and paste it inside the Image.newtork(url). remember to cover the url with '' .
otherwise you can use the method below
Future downloadImage()async{
StorageReference _reference=FirebaseStorage.instance.ref().child("images/$_imageName.png");
String downloadAddress=await _reference.getDownloadURL();
setState(() {
_downloadUrl=downloadAddress;
});
}
now you can use the retrieve the image using Image.network(_downloadUrl).

How to share image on Flutter to other application

I tried using the https://pub.dartlang.org/packages/share plugin to share an image on my flutter app to other app like Whatsapp, Facebook and so on. But rather it sending the file name of the image(images/female/ankara/ank5.jpg) in my android project to the other application rather than the actually image.
How can make it send the actual image.
Hero(
tag: widget.imageList,
child: PhotoView(
imageProvider: AssetImage(widget.imageList),
)
);
final RenderBox box = context.findRenderObject();
Share.share(widget.imageList,
sharePositionOrigin:
box.localToGlobal(Offset.zero) &
box.size);
I excepted to send the actual image to the other app rather it in a string format.
As mentioned in the previous comment, you can follow the answer on this Stack Overflow post for sharing images from a Flutter app. As for selecting a different image, you can use storage path provider plugins like ext_storage or image_picker.

React-native-video not showing the video player

I am using react-native-video package to get video player in which i can play my youtube videos.
I tried this but only a empty space was coming instead of a video player.
import Video from 'react-native-video';
<Video source={{uri: 'https://www.youtube.com/watch?v=Gh2FaDqZp2g'}}
ref={(ref) => {
this.player = ref
}}
onBuffer={this.onBuffer}
onEnd={this.onEnd}
onError={this.videoError}
style={styles.backgroundVideo} />
style:
backgroundVideo: {
height:300,
width:'100%',
}
I think Video tag will accept Uri ending with .mp4 format..
Please replace your uri with this http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4
(Note: Some other uri can also be used with same format) and checkout.
But for streaming Youtube videos you will have to use react-native-youtube and Youtube API Component.
Please refer this link for further
I see there some problems in your code:
1/ uri: please replace by this link: "http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4"
source={{uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'}}
2/ Your style: as I remember width: '100% does not work, you should set it to a specific number. Or you can make video container view wraps the video view
<View style={styles.videoContainer}>
<Video
source={{uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'}}
ref={(ref) => {
this._player = ref
}}
...
style={styles.video}/>
</View>
View style:
videoContainer: {
flex: 1,
backgroundColor: 'black',
},
video: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
},
Hope this can help you.
Video is not showing because of these conditions required by IOS and react-native
URL passed on uri must be "HTTPS" to run on ios because by default these are configured to https
To run HTTP Video file you need to make these changes on info.plist file as mentioned on below image from doc of the package
So add the following snippet in the ios/Project-Name/info.plist file under dict XML, This way you will opt out the App Transport Security by apple.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
It is not recommended to opt out of App Transport Security since Apple plans to require App Transport Security starting 1 January 2017, But if you want you can
For more information refer to this article
https://cocoacasts.com/how-to-add-app-transport-security-exception-domains
If loading from local file system of project use require('path')
directly on source prop. Ex -
source={require('../../assets/videos/test_video.mp4')}
Hope this will help you or somebody else.
Thanks!
it's very clearly mentioned in library that you have to use .mp4 file, in my case .mp4 file url was also not working for android 10 and 11 so i have tried below solution and it worked for me.
still you can try this solution as it works for me try to change your react-native.config.js file with the following code
hope this will work for you
module.exports = {
dependencies: {
'react-native-video': {
platforms: {
android: {
sourceDir: '../node_modules/react-native-video/android-exoplayer',
},
},
},
},
};

Categories

Resources