#Flutter Tutorials - File Operations- Writing and Reading files (coderzheaven.com)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello doll occurs in this video we are going to find out how we can write and read files in clutter let's start with this small template my template has nothing actually in the UI as you can see so let's start let's start by giving a title and say it file operations let's give a text field and a button which is a rice button each button with a text so that will be child with a text let's give it save to file then give it a nice heat and frost event on trust it will be saved to file we can define it later so a file and we'll give another button to read the data from the file that will be another nice button with child text the read from file and I want trust it's late for now or will define it an empty function form now it's no more the say file as well ok and even other text in which we will show the contents from the file okay now we will define a string file contents that will store the files contents and show it in the text so we will initialize initialize with an empty string and we'll give the file contents to the next video and condense there okay so probably loading you can see the changes in the simulator this reload let's reset the hap sometimes it won't take effect so let's restart the app so you can see the no data and no so nothing looks okay now let's create another file which will be an utility file so go ahead and create a new file shall be called file util is not that and we will have all the functions for file operations and saved class file noodles now for using file operations in Plata we need to input a library so go to come spec 30 ml and import the path provider library you can google it and see what is of not order latest ocean let's go ahead and import that import the fire-pot provider there it is okay now let's define the okay will input the data us will so that we will get the file descriptor once let's start with some functions that static functions so all are asking function so it will be returning a future so future string that get the file path and so that will be a nursing function since these are all blocking functions will be giving it as a nursing let's get the directory where we want to so we want to store the files so return the path of the directory dot dot path now we will get the file so that will be another static function with future and written because file so that comes from God I you so get it file so that will be another sinc function so that will be final but equal to weight it file path so return the path the whole path so that will be a new file with dollar path slash our file so let's name it my file dot txt so next we will write another function to save the contents of file so that will be future file all are the all these are passing functions so the return type will be always the future so save the file with the data parameter so final file equal to get the file oh wait get file so we got the file now we are going to write that contains the file the return file dot right so we've all got the simple okay so that will be a right string data data so we'll write the function to read from the file that will be under nothing function which will return the string yes the future read from file I think it's have it like a nice block so if there is an error we will catch that error and return some error or some let's return an empty string for now now inside the try let's write file the file get the file to read oh wait get file these are our block infections you saw it so string the file contents equal to L dot oh wait sorry so that's also a blocking function so we use a weight I'll read a string so that will return the contents let's return the contents so all done let's go to the main file and hook the functions before that we need to get the contents from the text field to write the write to the file so that is done by using in text editing control so let's create the variable my control or equal to text editing control let's use a controller in the text field let's give it to the controller property my controller okay let's go to say to file one plus method so that will be file utils oh we forgot input let's import file file utils okay so that will be file utils dot saved file with the text my controller so that will be a text from the text field my controller dot text that's the use of the controller let's read from the file so that will be since that is an asynchronous function let's see how we can write so that will be value it will start create from file dot then so it will not immediately return so you need to use that then I'll let's name it contents so don't confuse it with the current state variable so let's once we receive the contents of the file we will update the state so that will be set state file contents equal to intense okay let's set the file contents oh okay we already said well contents to the text so it's all good let's run the app let's try something hello SATA file read profile there it is we successfully returned the file let's try to update the file hello um water safety file again read from the file there it is so all good so everything is working fine so thank you for watching and please leave your comments and please subscribe to my channel thank you
Info
Channel: Mobile Programmer
Views: 21,866
Rating: undefined out of 5
Keywords: Flutter file operations, Flutter Writing files, Flutter Reading files, Flutter tutorial, Android tutorial, iOS tutorial, getApplicationDocumentsDirectory, Future, async, await, path_provider, readAsString, writeAsString, coderzheaven, coderzheaven.com
Id: nWki7Wb0NNU
Channel Id: undefined
Length: 10min 47sec (647 seconds)
Published: Tue Dec 25 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.