Flutter Tutorial - Share Texts, Images & Files - Flutter Share Plugin

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
one of the most important features an app can have is sharing and we will look at how we can share files and text for example to social media so we can share it to whatsapp and also to other applications on your device if you are new here subscribe to my channel and make sure to watch this video till the end we want to get started by sharing first of all some text to other applications therefore i have created here already a text field and a button and now if we click on this button here on the right side then we want to call here this share.share and here inside you need to put a string and this is then the shared text to the other application and to make this work you also need to go to your pop spec journal file and put here the dependency share under your dependencies inside let's also try it out i have typed a message inside of this text field so i click here on this button share and i select here for example messages and you see that he puts in here this data inside which we have typed before and this works also for other apps so you have here every time the sharing menu then you select whatsapp and then you can also share it to whatsapp easily if you also set your links inside of this text then in some social media apps you see then here this pop-up like whatsapp and then later the people can click on this video for example which you linked within your message and lastly we also want to catch here some errors so let's say there is nothing typed inside then we don't want to share our text and therefore i simply check here the controller.text which is linked up with this text field and if our text field is empty then we want to show here a snack bar which says enter a caption and otherwise we want to call here then the share dialog to share our text we also want to look at how we can share some files to other applications and this is also pretty easy so you can share videos pdfs and so on and therefore we go here to our share button widget which is in this button here and if we click on this one then we want to pick some files from our phone and therefore i create a new method pick files and here inside we basically call this file picker platform pick files and this is also a plugin which we need to integrate inside of our pubspec jumbo file so make sure that you put this file picker here inside under your dependencies if you later have some issues with this file picker then you need to go to android and then you select the build gradle file and here inside make sure that you put this version number inside so you have here the dependencies where you need to put this inside and secondly you also need to go here inside of this gradle wrapper folder and here inside you have this gradle wrap up preferences and here at the end you also need to set this number so make sure that you put this here inside and now we are good to go and we can continue here within our pick files method here inside you can define if you want to share multiple files and in this case i put it here to true so i can share multiple files to other applications on this device otherwise by default if you don't put this inside then you only share one file and lastly we return here this result.pack and this returns then the path of all the files which we have picked so basically if we call here this method then our file dialog on our device will pop up and you can basically select here some files and if you have set here this allow multiple to true you can select your multiple files otherwise you can only select one file and secondly we also want to check here if the result is null and if that's the case then we return an empty list and this can be null if the user doesn't pick any files so he comes to this dialog and if he navigates back then this returns him now now that we have finished the file picking process we can also continue and share our files to other apps therefore after we have picked our files we call this message share files and here inside we put then the files which we have picked from our library and here we can also supply a text if you like and here inside we put then simply the text of our text field let's also try it out so i have here text inside i click on share then i need to allow it and here i can select then a file which i like to share and then this dialog here will pop up and then you basically can select the app to which you want to share your data and at the end we also want to make sure that we have files because if this year is empty then we don't want to share our files and therefore i simply wrap it here inside of the condition and if our paths are empty then we want to show here an error message which says add some files otherwise we will share here our files with this method hello everyone thank you so much for watching this video please make sure to give it a thumbs up and subscribe to my channel here to get the latest news about flutter and see you soon bye
Info
Channel: HeyFlutter․com
Views: 26,369
Rating: undefined out of 5
Keywords: flutter, flutter plugin, flutter share plugin, flutter tutorial, flutter how to, flutte share, google share, share ios, share cross platform, share intent android, flutter ios tutorial, share data with other apps, share data mobile, advanced share in flutter, whatsapp share flutter, share in flutter, share, flutter share, share image, flutter share image, sharing, share plugin, social media, social media share for flutter, share data with app
Id: -PmUFbbA-Fs
Channel Id: undefined
Length: 5min 37sec (337 seconds)
Published: Mon Jan 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.