Flutter in 7 Days Ipsi Patro
Flutter in 7 Days Ipsi Patro
7 Days
Build user-friendly apps with
widgets and navigation
Ipsi Patro
www.bpbonline.com
ii
First Edition 2024
ISBN: 978-93-55516-091
All Rights Reserved. No part of this publication may be reproduced, distributed or transmitted in
any form or by any means or stored in a database or retrieval system, without the prior written
permission of the publisher with the exception to the program listings which may be entered,
stored and executed in a computer system, but they can not be reproduced by the means of
publication, photocopy, recording, or by any electronic and mechanical means.
All trademarks referred to in the book are acknowledged as properties of their respective
owners but BPB Publications cannot guarantee the accuracy of this information.
www.bpbonline.com
iii
Dedicated to
To my beloved husband, Sanat Patro,
and my two sons, Arnav Patro and Vivaan Patro
iv
Ipsi Patro is a software engineer with extensive experience in mobile platforms, excelling
in both native and hybrid environments. She graduated with a B.Tech degree and has
since worked at renowned companies such as Tata Consultancy Services in India, Vitality,
and OvalMoney in the UK, among several others. Currently serving as the Head of
Engineering at Twyn in the UK, Ipsi has consistently showcased outstanding leadership
and managerial skills, effectively guiding mobile development teams with proficiency.
Motivated by an insatiable curiosity and a dedication to remaining at the forefront
of technology, Ipsi immersed herself in mastering Flutter and Dart, swiftly achieving
proficiency in both. Her technical expertise spans various programming languages,
frameworks, and tools, complemented by a deep understanding of software architecture,
agile methodologies, and DevOps practices. These capabilities have empowered her to
successfully oversee complex projects from conception through deployment.
Beyond her technical accomplishments, Ipsi is passionate about knowledge-sharing.
Her extensive hands-on experience with Flutter projects, coupled with a natural talent
for teaching, enables her to articulate complex concepts clearly and accessibly. She firmly
believes in the transformative impact of education and is committed to empowering
aspiring developers to fulfill their potential.
When not deeply engaged in coding or teaching, Ipsi enjoys pursuits such as listening to
music, gardening, cooking, and exploring the outdoors. Actively involved in developer
communities, she collaborates with peers to exchange insights and deepen her knowledge.
Ipsi’s book, Flutter in 7 Days, reflects her deep expertise and passion for Flutter
development. She hopes this guide will empower readers to embark on their own Flutter
journey and create exceptional mobile applications.
v
Acknowledgement
I would like to express my deepest gratitude to my family and friends for their unwavering
support and encouragement throughout the writing of this book. A special thanks to my
beloved husband, Sanat Patro, and my two sons, Arnav Patro and Vivaan Patro, whose
love and patience have been my greatest source of strength.
I am also profoundly grateful to BPB Publications for their guidance and expertise in
bringing this book to fruition. This journey involved numerous revisions and benefited
immensely from the participation and collaboration of reviewers, technical experts, and
editors.
Finally, I extend my heartfelt thanks to all the readers who have shown interest in my
book. Your support and enthusiasm have been invaluable in making this book a reality.
Thank you for embarking on this journey with me.
vii
Preface
Welcome to Flutter in 7 Days! If you are holding this book, you have taken the first step
towards mastering one of the most versatile and powerful frameworks for building cross-
platform applications. Whether you are a seasoned developer looking to expand your skill
set or a newcomer eager to dive into the world of mobile app development, this book is
designed to be your comprehensive guide to learning Flutter in just seven days.
In today’s fast-paced world, the demand for high-quality mobile applications is ever-
increasing. Flutter, with its robust set of features and unparalleled flexibility, has emerged
as a frontrunner in the realm of cross-platform development. With Flutter, you can create
stunning user interfaces, leverage a single codebase to deploy apps on multiple platforms,
and enjoy blazing-fast performance – all without compromising on quality or user
experience.
Flutter in 7 Days is structured to provide you with a step-by-step journey through the
fundamentals of Flutter development. Each day is carefully crafted to build upon the
concepts learned in the previous days, ensuring a smooth and progressive learning
experience. From setting up your development environment to building complex UI
layouts, handling user input, and integrating with backend services, this book covers
everything you need to know to become proficient in Flutter development.
Throughout this book, you will find a balance of theoretical explanations, practical
examples, and hands-on exercises to reinforce your learning. Whether you prefer to read
through concepts, follow along with code examples, or roll up your sleeves and dive into
coding challenges, you’ll find something here to suit your learning style.
As you embark on this seven-day journey, remember that learning Flutter – like any new
skill – takes time, patience, and practice. Do not be discouraged by challenges or setbacks
along the way. Embrace them as opportunities to deepen your understanding and grow
as a developer.
By the end of Flutter in 7 Days, you will have the knowledge and confidence to tackle real-
world Flutter projects with ease. Whether you are building your own apps, contributing to
open-source projects, or launching your career as a Flutter developer, this book will serve
as your trusted companion on your Flutter journey.
viii
So, without further ado, let us embark on this exciting adventure into the world of Flutter
development. Get ready to unleash your creativity, build amazing apps, and take your
skills to new heights. The next seven days are going to be both challenging and rewarding
– let us make the most of them!
This chapter introduces Flutter and Dart, guiding you through setting up your development
environment and creating your first Flutter project. You will gain an understanding of the
Flutter project structure and write your first Dart code.
In this chapter, you will learn about variables and data types in Dart, control flow
mechanisms such as loops and conditionals, and the fundamentals of functions and
methods. Additionally, you will explore object-oriented programming basics in Dart and
engage in hands-on exercises to reinforce these concepts.
This chapter delves into the Flutter widget tree, teaching you how to create layouts
with widgets and handle user input through gestures and interactions. You will learn to
navigate between screens and build a simple app from scratch.
Here, you will get an overview of commonly used Flutter widgets, including container
widgets for layout and styling, and text and image widgets for displaying content. The
chapter also covers ListView and GridView for creating scrolling lists and grids, as well as
exploring advanced widgets and customizing their behavior.
This chapter focuses on state management in Flutter, understanding the widget lifecycle,
and using packages and plugins to extend Flutter’s functionality. Additionally, you will
explore Flutter’s animation capabilities and learn techniques for optimizing performance
and debugging.
In this chapter, you will learn how to make HTTP requests in Flutter and handle
asynchronous operations using Futures and Streams. You will also learn to parse JSON
data, display remote data in your Flutter app, and implement error handling and loading
indicators.
ix
This chapter introduces Firebase and its services, guiding you through setting up Firebase
for your Flutter project. You will learn to integrate Firebase Authentication, store and
retrieve data with Cloud Firestore, and implement real-time updates with Firebase Cloud
Messaging.
Chapter 8: Miscellaneous
The final chapter offers tips and best practices for Flutter development, guidance on
deploying your Flutter app to different platforms, and resources for further learning and
exploration. It also addresses troubleshooting common issues and exploring advanced
topics and next steps in your Flutter journey.
x
https://rebrand.ly/077b4d
We have code bundles from our rich catalogue of books and videos available at
https://github.com/bpbpublications. Check them out!
Errata
We take immense pride in our work at BPB Publications and follow best practices to
ensure the accuracy of our content to provide with an indulging reading experience to our
subscribers. Our readers are our mirrors, and we use their inputs to reflect and improve
upon human errors, if any, that may have occurred during the publishing processes
involved. To let us maintain the quality and help us reach out to any readers who might be
having difficulties due to any unforeseen errors, please write to us at :
[email protected]
Your support, suggestions and feedbacks are highly appreciated by the BPB Publications’
Family.
Did you know that BPB offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.bpbonline.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at :
[email protected] for more details.
Piracy
If you come across any illegal copies of our works in any form on the internet,
we would be grateful if you would provide us with the location address or
website name. Please contact us at [email protected] with a link to
the material.
Reviews
Please leave a review. Once you have read and used this book, why not leave
a review on the site that you purchased it from? Potential readers can then see
and use your unbiased opinion to make purchase decisions. We at BPB can
understand what you think about our products, and our authors can see your
feedback on their book. Thank you!
Table of Contents
Further reading.................................................................................................................... 26
Conclusion............................................................................................................................ 26
Questions.............................................................................................................................. 27
Answers............................................................................................................................ 27
Multiple choice questions................................................................................................... 28
Answers............................................................................................................................ 28
Async/Await.............................................................................................................. 218
Parsing JSON...................................................................................................................... 219
Spinner widget................................................................................................................... 226
Passing data backwards through navigator.................................................................. 227
Sending data from the destination screen....................................................................... 227
Receiving data in the previous screen:............................................................................ 227
Location service................................................................................................................. 228
Sample app with networking call................................................................................... 230
Conclusion.......................................................................................................................... 240
Multiple choice questions................................................................................................. 240
Answers.......................................................................................................................... 241
Index...............................................................................................................................313-317
Chapter 1
Getting Started with
Flutter and Dart
Introduction
Hello readers welcome onboard to the journey of becoming a Flutter developer. In this
chapter, first we will go through the installation steps to bring your machine ready for
Flutter development and then we will go through some basic concepts of Flutter and Dart.
Structure
The chapter covers the following topics:
• Introduction to Flutter and Dart
• Understanding Flutter
• Defining Dart
• Installation in Windows
• Installation in Mac
• IDEs for Flutter
• Compilation logic of flutter
• Dartpad
• Function
• Dart data types
2 Flutter in 7 Days
• Dart Variables
• Dart Classes and Objects
• Dart List
• Dart Map
• Null Safety in Dart
• String Interpolation
Objectives
By the end of this chapter, your machine must be ready for Flutter development, and you
will get a good understanding of which IDE to pick and some important features provided
by the IDE to make your development easier and faster. Along with that, some important
and fundamental Flutter and Dart concepts will also be discussed.
Understanding Flutter
Google has introduced Flutter for native mobile app development on Android, iOS, and
Windows. Flutter is a mobile app SDK, complete with framework, widgets, and tools,
that gives developers a way to build and deploy mobile apps written in Dart. So, before
moving ahead with learning Flutter, we will cover Dart basics later in this chapter. If you
have prior experience of software development with any language, you must be familiar
with these basics, but if you do not have any, it will be helpful for you in this journey.
Defining Dart
Dart is a programming language designed for client development, such as for the web and
mobile apps. It is developed by Google and can also be used to build server and desktop
applications. It is an object-oriented, class-based, garbage-collected language with C-style
syntax.
Flutter Architecture
With UI as code, there is no visual editor in Flutter like native iOS and Android development.
Therefore, no drag and drop of widgets; instead, write the code for adding and updating