Flutter Cookbook
eBook - ePub

Flutter Cookbook

Over 100 proven techniques and solutions for app development with Flutter 2.2 and Dart

Simone Alessandria, Brian Kayfitz

Condividi libro
  1. 646 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Flutter Cookbook

Over 100 proven techniques and solutions for app development with Flutter 2.2 and Dart

Simone Alessandria, Brian Kayfitz

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Discover how to build, scale, and debug native iOS and Android applications from a single codebase using the Dart programming language – a hands-on approach

Key Features

  • Work through practical recipes for building mobile applications with Flutter
  • Quickly build and iterate on your user interface (UI) with hot reload
  • Fix bugs and prevent them from reappearing using Flutter's developer tools and test suites

Book Description

"Anyone interested in developing Flutter applications for Android or iOS should have a copy of this book on their desk." – Amazon 5* Review

Lauded as the 'Flutter bible' for new and experienced mobile app developers, this recipe-based guide will teach you the best practices for robust app development, as well as how to solve cross-platform development issues.

From setting up and customizing your development environment to error handling and debugging, The Flutter Cookbook covers the how-tos as well as the principles behind them.

As you progress, the recipes in this book will get you up to speed with the main tasks involved in app development, such as user interface and user experience (UI/UX) design, API design, and creating animations. Later chapters will focus on routing, retrieving data from web services, and persisting data locally. A dedicated section also covers Firebase and its machine learning capabilities.

The last chapter is specifically designed to help you create apps for the web and desktop (Windows, Mac, and Linux).

Throughout the book, you'll also find recipes that cover the most important features needed to build a cross-platform application, along with insights into running a single codebase on different platforms.

By the end of this Flutter book, you'll be writing and delivering fully functional apps with confidence.

What you will learn

  • Use Dart programming to customize your Flutter applications
  • Discover how to develop and think like a Dart programmer
  • Leverage Firebase Machine Learning capabilities to create intelligent apps
  • Create reusable architecture that can be applied to any type of app
  • Use web services and persist data locally
  • Debug and solve problems before users can see them
  • Use asynchronous programming with Future and Stream
  • Manage the app state with Streams and the BLoC pattern

Who this book is for

If you're familiar with the basic concepts of programming and have your eyes set on developing mobile apps using Dart, then this book is for you. As a beginner, you'll benefit from the clear and concise step-by-step recipes, while a more experienced programmer will learn best practices and find useful tips. You'll get the most out of this book if you have experience coding in either JavaScript, Swift, Kotlin, Java, Objective-C, or C#.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Flutter Cookbook è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Flutter Cookbook di Simone Alessandria, Brian Kayfitz in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Programming Mobile Devices. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2021
ISBN
9781838827373
Data Persistence and Communicating with the Internet
Most applications, especially business applications, need to perform CRUD tasks: Create, Read, Update, or Delete data. In this chapter, we will cover recipes that explain how to perform CRUD operations in Flutter.
There are two ways that data can be persisted – locally and remotely. Regardless of the destination of your data, in many cases, it will need to be transformed into JSON before it can be persisted, so we will begin by talking about the JSON format in Dart and Flutter. This will be helpful for several technologies you might decide to use in your future apps, including SQLite, Sembast, and Firebase databases. These are all based on sending and retrieving JSON data.
This will integrate with our previous discussion on Futures since interacting with data generally requires an asynchronous connection.
In this chapter, we will cover the following recipe:
  • Converting Dart models into JSON
  • Handling JSON schemas that are incompatible with your models
  • Catching common JSON errors
  • Saving data simply with SharedPreferences
  • Accessing the filesystem, part 1 path_provider
  • Accessing the filesystem, part 2 – working with directories
  • Using secure storage to store data
  • Designing an HTTP client and getting data
  • POST-ing data
  • PUT-ting data
  • DELETE-ing data
By the end of this chapter, you will know how to deal with JSON data in your apps so that you can interact with databases and web services.

Technical requirements

To follow along with the recipes in this chapter, you should have the following software installed on your Windows, Mac, Linux, or Chrome OS device:
  • The Flutter SDK.
  • The Android SDK, when developing for Android.
  • macOS and Xcode, when developing for iOS.
  • An emulator or simulator, or a connected mobile device enabled for debugging.
  • An internet connection to use web services.
  • Your favorite code editor. Android Studio, Visual Studio Code, and IntelliJ IDEA are recommended. All should have the Flutter/Dart extensions installed.
You'll find the code for the recipes in this chapter on GitHub at https://github.com/PacktPublishing/Flutter-Cookbook/tree/master/chapter_08.

Converting Dart models into JSON

JSON has become the standard format for storing, transporting, and sharing data between applications: several web services and databases use JSON to receive and serve data. Later in this chapter, we will learn how to store data in a device, but in this recipe, we will learn how to serialize (or encode) and deserialize (or decode) data structures from/to JSON.
JSON stands for JavaScript Object Notation. Even if it largely follows JavaScript syntax, it can be used independently from Javascript. Most modern languages, including Dart, have methods to read and write JSON data.
The following screenshot shows an example of a JSON data structure:
As you can see, JSON is a text-based format that describes data in key-value pairs: each object (a pizza, in this example) is included curly brackets. In the object, you can specify several properties or fields. The key is generally included in quotes; then, you put a colon, and then the value. All key-value pairs and objects are separated from the next by a comma.
JSON is basically a String. When you write an app in an object-oriented programming language such as Dart, you usually need to convert the JSON string into an object so that it works properly with the data: this process is called de-serialization (or decoding). When you want to generate a JSON string from your object, you need to perform the opposite, which is called serialization (or encoding).
In this recipe, we will perform both encoding and decoding using the built-in dart:convert library.

Getting ready

To follow along with this recipe, you will need some JSON data that can be copied from https://github.com/PacktPublishing/Flutter-Cookbook/tree/master/chapter_08.

How to do it...

For this recipe, we will create a new app that shows how to serialize and deserialize JSON Strings.
In your favorite editor, create a new Flutter project and call it store_data:
  1. In the main.dart file, delete the existing code and add the starting code for the app. The starting code for this recipe is also available at https://github.com/PacktPublishing/Flutter-Cookbook/tree/master/chapter_08, in case you don't want to type it in:
import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter JSON Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity
.adaptivePlatformDensity,
),
home: MyHomePage(),
);}}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState(...

Indice dei contenuti