Flutter 2
Flutter 2
- SARANIYA S
• In general, developing a mobile application is a complex and challenging task. There are
many frameworks available to develop a mobile application. Android provides a native
framework based on Java language and iOS provides a native framework based on
Objective-C / Swift language.
• To create an app for both Android and iOS, we usually need to code in two different
languages. To make this easier, there are frameworks that support both operating
systems. These range from simple HTML-based frameworks, which use HTML and
JavaScript, to more advanced frameworks that handle complex language translation for
native performance.
• In this scenario, Flutter – a simple and high performance framework based on Dart
language, provides high performance by rendering the UI directly in the operating
system’s canvas rather than through native framework.
• Flutter also offers many ready to use widgets (UI) to create a modern application. These
widgets are optimized for mobile environment and designing the application using
widgets is as simple as designing HTML.
➢ Flutter – Basics
• In this section, you’ll learn the fundamentals of Flutter. Flutter is a toolkit created by
Google that lets developers build apps for mobile, web, and desktop using the same
code. It uses the Dart programming language and comes with ready-to-use widgets for
designing user interfaces. Flutter’s special feature, hot reload, allows developers to see
changes instantly as they code, making development faster.
➢ Web specific features in flutter
❖ Web-Specific Widgets:
Widgets like Link (for web navigation) and Selectable Text (for copy-pasting text) make web
interactions smoother.
❖ Offline Support:
Using service workers, Flutter Web apps can work offline and cache assets to improve loading times.
Rendering Options:
1. Provider
• Limitations: Not suited for very complex state management or when managing very large
applications.
2. Riverpod
• Description: Riverpod builds on Provider but offers a more robust and safer API. It allows for
state sharing without depending on the widget tree, making it flexible and powerful.
• Description: Bloc is a reactive state management solution that separates business logic from
UI using the Stream API. It’s a good choice for complex applications requiring well-organized
business logic.
• Limitations: Can be verbose and complex to implement, especially for simpler apps.
This documentation should include details about endpoints, data formats (such as JSON or
XML), authentication mechanisms, request/response structures, and any specific guidelines or
limitations. Having a thorough understanding of the backend services will facilitate smoother
integration.
• API Versioning and Future Compatibility:
As your app evolves and backend services undergo changes, maintaining API compatibility
becomes important. Follow API versioning practices and design your integration in a way that allows
for future updates without disrupting existing functionality.
Ensure secure data transmission between your Flutter app and the backend server by
implementing appropriate encryption protocols like HTTPS/TLS. This protects sensitive user data
from eavesdropping and unauthorized access.
You don’t need an app for every business idea. Do your research first, identify the problem
you want to solve and try to find solutions. Interview people who experience the problem and ask if
they have possible solutions. If you feel a web application will streamline work, proceed to the next
stage.
2. Market research
You must have an accurate understanding of the user, their problem, and the scope of the
problem. Research if there are other ways to solve the problem out there. Getting insight into the
user and the competition helps inform the technical direction of the web app.
Come up with a list of features that will address the problem. But keep your distance and add
only a few functionalities. Apps with more features take longer to build. Only focus on the features
that solve your target market's problems.
If your app has competitors, sign up for their free trials and use the solutions. Pay attention to
the workflow and note what’s good and bad. Sit down and sketch different workflows for your app
that is better than the competition.
A database allows you to store data securely to access it later. The data you store, and user
functions will determine the type of database required to run your web app.
The frontend is what users see and interact with. It’s the visual element of the application and
is developed with coding language. The framework is set up on a no-code/low-code platform, and
almost no coding is needed to build a frontend. Not all web applications need frontend frameworks.
The backend manages your data, servers, databases, and everything users can’t see in a web
application. Building a backend is a job for skilled developers, but a no-code/low-code tool can take
away many of the complexities.
8. Test and troubleshoot
Test the app before you publish it. Use it in run mode and see if it functions as expected. If
something is wrong, diagnose the problem using the no-code/low-code platform. Some platforms
have a debug mode and issue checker to make your job easy.
First, choose a host for your web app to make it available on the cloud. Users will be able to
access it from anywhere in the world. Next, deploy the web app. This step involves getting your web
application from your computer to your cloud hosting.
Flutter widgets are constructed utilizing a modern set of libraries that resembles React Native.
The fundamental concept is that you make your UI out of widgets. Widgets showcase what their
formation should represent to end users, given their present structure and state.
Now the situation is rebuilding the widget boosts the load time. Here is how. When a user comes
across the elements in the widget, the complete view in that widget is refreshed.
Prefer Async/Await:
An async keyword would try to assist you in pivoting your operations to the asynchronous mode
by implementing the return kind of operation to the Future. Async illustrates the operations as
asynchronous, and it could take a bit to get the results. If the return type is not Future, there are
possibilities of various issues in the code. Functions label ‘async’ must have a return type assignable
to ‘Future.’
Adding all the attributes, widgets, and scripts appears quite doable. But that also takes lots of
space within it, resulting in an increase in the app size. But that’s not right. And here is what we can
do to diminish the size of the Flutter app.
There are manual and automatic procedures for deleting undesirable resources. In the manual
procedure, you have to select the individual files manually and then delete those which are not
essential.
The automatic procedure utilizing the tools is with the Android Studio pursuing the given steps
below:
The appearance is separated into 2 domains: structure and picture. Flutter apps are optimized
when you can equally separate the structure and picture for about 8ms.
Coders have 8ms for structure and another 8ms for the image to induce a 60hz display. It won’t affect
the grade of the app. Instead, it will boost the battery duration and preserve the temperature of the
system.
bash
Copy code
Here are some easy-to-use platforms for hosting your Flutter web app:
bash
Copy code
2. Login to Firebase:
bash
Copy code
firebase login
bash
Copy code
firebase init
Select "Hosting" and choose the build/web folder as the public directory.
bash
Copy code
firebase deploy
bash
Copy code
3. Enable GitHub Pages: Go to your repository settings, scroll to "GitHub Pages," and select gh-
pages as the source branch.
Option 3: Netlify
o Drag and drop the contents of the build/web folder into the Netlify UI.
After deploying, visit the provided URL to see your app live on the web!
PWAs are the latest buzz in app development. These web applications masquerade as native apps
and offer many advantages, such as working offline and providing engaging user experiences. With
the right blend of mobile apps' versatility and websites' connectivity, PWAs command the best of
both worlds.
Combine the prowess of PWAs with the flexibility of Flutter. This Google-developed, open-source
technology is an ace in cross-platform app development. It allows you to craft beautiful, high-
performing applications from a single codebase for mobile, web, and even desktop. Google
announced last year that Flutter's web support is now stable, making it a gamut of possibilities for
developers targeting multiple platforms.
Google's substantial support for PWAs in Flutter breathes fresh life into cross-platform app
development. It combines the characteristics and benefits of native and web apps, fitting together
like pieces of a puzzle to form a sophisticated whole.
Before developing our PWA, we must ensure our toolkit is ready. Here, our toolkit refers to the
Flutter environment.
Firstly, you need to install the Flutter SDK. Visit the official Flutter installation guide and follow the
detailed steps mentioned there. It would be best if you had an editor that supports Flutter. Visual
Studio Code, Android Studio, and IntelliJ are excellent picks that offer robust Flutter and Dart plugins.
Ensure everything runs correctly once Flutter is set up and your editor is installed. Flutter Doctor is a
handy command that checks your environment and displays a report of the status of your Flutter
installation:
1flutter doctor
The command checks your system and lets you know if there are any dependencies you need to
install to use Flutter. The objective is to create a fully functional Flutter environment ready for action.
A new Flutter project can be created by running the simple command flutter create [project_name].
Fire up your terminal, navigate to the directory where you want to store your project, and run:
This command creates a new Flutter project named flutter PWA. The project directory will have the
following structure:
1flutter_pwa/
2 android
3 iOS
Now that we have reached this far, let's begin our coding voyage into the Flutter universe. Our
primary objective is to convert our existing Flutter project into a progressive web app (PWA).
First, we will rewrite our lib/main.dart file with a simple MaterialApp with an AppBar. It would look
something like this:
1import 'package:flutter/material.dart';
2
3void main() {
4 runApp(MyApp());
5}
10 @override
12 return MaterialApp(
14 theme: ThemeData(
15 primarySwatch: Colors.blue,
16 ),
17 home: MyHomePage(),
18 );
19 }
20}
21
24
25 @override
27 return Scaffold(
28 appBar: AppBar(
30 ),
31 body: Center(
32 child: Column(
33 mainAxisAlignment: MainAxisAlignment.center,
34 children: <Widget>[
35 Text(
37 ),
38 ],
39 ),
40 ),
41 );
42 }
43}
After finishing up with the code, you will need to navigate into the project's root directory and run
the app in Chrome by executing the following command:
Flutter creates a local server hosting your web app by running the above command. Open your
browser and navigate to localhost:8080 to see your application.
Testing and debugging are integral aspects of app development. Let's explore how we can check if
the PWA works perfectly.
To confirm our Flutter web app is indeed a PWA, we need to verify two things:
First, we navigate to the "Application" tab, then to the "Service Workers" from the left-hand menu.
Here, we can see that the service worker is installed and running. We can also test whether our PWA
is functioning offline by checking the "offline" box.
To install your PWA on your device, you can find an "+" icon on the right-hand side of the URL bar on
top. Clicking this icon installs your PWA on your device. If clicking the "+" does not do anything or
does not appear, it suggests there's some error in your PWA.
Debugging in Chrome Developer Tools significantly helps to locate and fix unexpected behavior in
your code.
2. A build/web directory gets created, containing your app's built version, including HTML, JS,
CSS, fonts, and other assets.
3. Copy the output directory files, and follow the deployment instructions for your selected
hosting option. ( Here are some examples of hosting solutions: Firebase, GitHub Pages, or a
self-hosted server with Nginx, Apache, etc.)
That’s it! Congrats on deploying your first PWA with Flutter. Your users can now enjoy a web
experience that feels like a native app.
bash
Copy code
This opens your app in Chrome (or your default browser) in debug mode.
3. Console Logs
dart
Copy code