FLUTTERFlutter Data Management

Infospica Consultancy Services
3 min readApr 2, 2020

• Flutter applications are built using Dart language, Dart is a single-threaded language and so are Flutter applications. Know how to periodically manage the data of a flutter application.

1. API Calls

• While developing a Flutter application, developers should create a separate class for API calls. Creating multiple API classes may slow down the overall developer productivity. We recommend using a DRY pattern which stands for Don’t Repeat Yourself.

• Use Async/await as much as required because while Await makes it straightforward to fetch & read the data, Async prevents it from blocking the main thread. For example, logging an event in your analytics toolkit, you could log the event without waiting for the results.

• One can also use then() instead of await for doing multiple API calls in a chained fashion.

• For HTTP calls, there are multiple packages available to make them easy. Dio is one such recommended package.

• For longer lists, make sure that you use pagination i.e. fetch the data in chunks from the server itself.

2. Local Data

• Local database in Flutter can be stored using Shared Preferences, SQFlite & text files. But which one of these should be used depends completely on the nature of the data.

• For a small amount of data like the last cursor position, the last visited page, user-specific settings, etc shared preferences are most suitable.

• But for storing a large amount of data (which can be relational), a database is required. Try and keep the database related code in models or repositories which will result in more testable, maintainable & reusable code.

3. Data Sync

• Synchronization has always been a tricky and hard problem in computer science. Many apps have tried to implement their own implementations in the past and few of them have been successful.
• The same problem is visible in Flutter as well. Because of its cross-platform nature, we’re yet to see a synchronization framework similar to native Android and iOS for Flutter. We’d recommend using native sync frameworks for now using Platform Channels.

State Management & Architectural Patterns

• Flutter’s ecosystem is rife with state management techniques with a new technique coming in quickly each day. From setState() to BLoC pattern, developers are very much divided with their own opinions for each pattern.
• A very complex application like a marketplace application where the data is collected from various different platforms should definitely be built with a BLoC pattern.
• There are of course many other state management techniques like Redux, MobX, ScopedModel, InheritedWidget, etc.

Building UI

• While some developers find Flutter UI a tricky task, some enjoy its declarative UI feature. A flutter is a cross-platform tool hence, the selection of UI widgets needs to be done considering both of the platforms i.e. Android & iOS.
• If you’re building an app that’s targeted towards iOS users, make sure that you use more Cupertino widgets rather than Material widgets and vice versa. Also, note that the Cupertino widgets are limited as compared to Material widgets due to the fact that Google itself follows Material Design as a reference throughout their own products.
• All in all, we’d suggest going with your own brand-first design as Flutter is well-suited for them rather than using the stock widgets.
• Flutter also has a Platform View widget which allows embedding native platform controls. Make sure that you use it in order to implement the missing functionalities

--

--