Questions And Answers

More Tutorials

Flutter Local Files

If you don’t need to query but you need to store possibly complex objects and lots of data with full-control then this is probably the best way to do it.
Flutter provides a core package ‘’ to help you with input and output at the device level. Remember that this may be different for different devices (platforms). For example, some of the file details may be different for an Android than iOS. That is why the Platform class is covered below.

The Flutter ‘’ core package includes Directory and File objects for the purpose of working with Directories and Files. These objects are excellent because they can work both synchronously and asynchronously, allowing you to maintain a responsive app even when dealing with large amounts of data.

However, this package does not tell you how to store the data in the files, what file format to use and how to serialize and deserialize objects into files. That is both good and bad but it requires some work on your part.


When you are coding with local files and directories, sometimes you need information about the device platform:
Number of processors.
Path separator.
Operating System.
Operating System version.
Local hostname.

The Platform class exists to provide this information to you.

Path Separator

Very useful when you want to separate elements from the path, such as the directory and the filename.
In the example below, I create a ‘Directory’ object and use it to query local files in the ‘Application Documents’ directory. When I do this, I get a list of files and each file has a path, which includes the filename at the end. I parse out the filename by finding the last path file

separator (using Platform.pathSeparator) and calculating the filename
as the rest of the path from there onward.
Directory(_path).listSync().forEach((FileSystemEntity fse) {
String path = fse.path;
if (path.endsWith(".themeColor")) {
int startIndex = path.lastIndexOf(Platform.pathSeparator) + 1;
int endIndex = path.lastIndexOf(".themeColor");
filenameList.add(path.substring(startIndex, endIndex));


In this page (written and validated by ) you learned about Flutter Local Files . What's Next? If you are interested in completing Flutter tutorial, your next topic will be learning about: Flutter Mixins.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.