Book Image

Taking Flutter to the Web

By : Damodar Lohani
Book Image

Taking Flutter to the Web

By: Damodar Lohani

Overview of this book

Using a shared codebase in addition to an extensive range of tools in the Flutter ecosystem optimized for browsers, the Flutter framework has expanded to enable you to bring your mobile apps to the web. You’ll find out how web developers can leverage the Flutter framework for web apps with this hands-on guide. Taking Flutter to the Web will help you learn all about the Flutter ecosystem by covering the tools and project structure that allows you to easily integrate Flutter into your web stack. You’ll understand the concepts of cross-platform UI development and how they can be applied to web platforms. As you explore Flutter on the web, you'll become well-versed with using Flutter as an alternative UI platform for building adaptive and responsive designs for web apps. By the end of this Flutter book, you'll have built and deployed a complete Flutter app for the web and have a roadmap ready to target the web for your existing Flutter mobile apps.
Table of Contents (17 chapters)
1
Part 1: Basics of Flutter Web
5
Part 2: Flutter Web under the Hood
9
Part 3: Advanced Concepts

Persisting data with local storage using the shared_preferences plugin

The shared_preferences plugin provides one of the easiest ways to persist data in Flutter applications. It can be used to store simple key-value pairs and is suitable for storing things such as application settings and offline cache. This plugin uses underlying SharedPreferences in Android, NSUserDefaults in iOS, and localStorage on the web to achieve key-value persistence. You can learn more about the web’s localStorage and its API from the official specification: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Client-side_storage. Using SharedPreferences, we will build a simple theme switcher, where users will be able to choose whether the theme is dark or light, which will persist the next time they come back.

Creating a theme mode service

To create a theme mode using SharedPreferences, follow these steps:

  1. We will start by adding it as a dependency in our application...