How to

How to be a Flutter Developer? Learn Flutter Development Easily

With the dawn of Google’s open-source UI framework, Flutter, its users have increased significantly. Today, we have a whole generation of developers remarked as Flutter developers who are busy building numerous cross-platform applications equipped with native performance, working efficiently by saving time and effort. To become an efficient Flutter developer, you have to go through a few basic steps. This highly flexible and open-source UI is easy to learn and you can get the hang of it by following the guideline below. Before you jump directly into how to be a Flutter developer, it is advisable to read some prerequisites to improve your familiarity. Some Prerequisites for a Flutter Developer Sources of Learning Flutter: With Flutter’s increasing popularity, it is time for you to install and learn Flutter as well. You must be questioning yourself by now what could be the best source for Flutter learning. The Internet is overloaded with plenty of online courses and books about Flutter development that can overwhelm you with information. To take off this stress ball from your mind, let’s help you out with 4 simple steps to learn Flutter: Flutter Installation and IDE Setup: Now that you are deep into the study of Flutter and have learned everything you need to know, it is time to get Flutter and set up an integrated development environment (IDE) to start building the app. There are two IDEs quite popular for flutter development. Visual Studio Code: VS code has everything you would want in an IDE. Supporting multiple programming languages, it is fast, lightweight, and coding-friendly. Its code-error recognition is a great step towards improved and efficient app development. Android Studio: Being an ideal IDE for app development, Android Studio provides a unified environment to its users. Its structured code modules divide your project into functional units that can be built, tested, and debugged independently. Get the plugins of Dart and Flutter, set up the SDK, and begin your journey as a Flutter developer. Related Post – Flutter development in android studio Get Familiar with OOPS Concept: Before you begin your journey with Flutter, get familiar with OOP concepts – object-based programming, not just functions or procedures. Through OOP’s structured programming features, you will get familiar with new ways of developing programs with programs divided into objects. By learning any of the OOP languages (preferably Java), you will pick up Dart and Flutter in days. First Step towards Flutter Developer Skills – Learn Dart Flutter’s SDK makes use of Dart. As hinted above, if you are familiar with any of the OOP languages, learning Dart would be relatively quick and easy. For example, if you know Java or C+, the transition toward Dart would be a piece of cake. If not, get yourself registered in a course to completely understand the mechanism of this language and get the best practice out of it.  Make sure to learn the following concepts from Dart: A Flutter Developer’s Roles and Responsibilities When working as a Flutter developer, there are some responsibilities that you have to fulfill. These are: Related Post – Flutter projects that can add to portfolio or resume Explore the extensive library of Widgets The central and crucial part of Flutter is its Widget library. The modern framework of Flutter manages the underlying render tree which is responsible for constructing a view with its state and configuration. To write a Flutter application, it is essential to know the difference between Stateful and Stateless widgets. A stateless widget once built, cannot be modified. Stateful widgets are dynamic and create a State object. So, they are helpful if you want some interactivity in your application. Flutter’s library is vast so take your time and explore it alphabetically. Related Post – Conditional Show Widgets in flutter Make API Calls and Get Database Integration Now that you are familiar with widgets and view trees, it’s time to make API calls. After getting the API URL and endpoints, add relevant packages to make calls. The most commonly used package is HTTP, but dio and chopper can also be used. After API integration and call, you can access the data directly, by creating a model class to parse the JSON. With so much data flowing around, it is only wise to use the database to store any data from your app. Two popular databases used with Flutter are: Hive: Written purely in Dart, Hive is a lightweight, fast key-value and offline database with no native dependencies and runs on Flutter web. Hence, it will be an ideal choice for you. Firebase: You can also consider data integration with firebase. The platform offers hosted backend services like cloud storage, real-time database, crash reporting, and much more. Flutter when used with firebase, makes development faster. Most Important Concept in Flutter – State Management As you continue with app development, it grows both in size and complexity, and you will soon be unable to manage your screens. Here, state management comes into play. You will find various state management packages, but you can take start with Provider, Redux, or Bloc. You can read a complete guide on State Management in Flutter from here. Which additional tools the Flutter developer may need? Panache: An open-source theme editor for Flutter that will help you in creating customized material themes for your mobile applications. Set the shapes, colors, and other theme properties of your own choice. Later export it to your Google Drive folder as a .dart file. Supernova: This powerful design-to-code tool – a bridge between design and development, helps in creating UI code for Flutter. With supernova, you can see the changes happening in real-time allowing you to edit the code and edit your design side-by-side. Moreover, Supernova manages your asset creation and saves your time by importing your Adobe XD or Sketch designs into native front-end code. Codemagic: With this app development tool, you can build a workflow for running tests only. Build apps with codemagic and assure quality with automated testing. Get fast feedback

Read More »

How to Use Webview in Flutter?

While building Flutter apps, you get to use several plugins. Each plugin has its respective features to offer inside the app. Plugins allow you to communicate with platform-specific code to access the features of that platform. Interestingly, developers from the Flutter community also contribute to each other and share plugins with each other. In this blog, you will get to know how to use webview in Flutter. There are several features that we need to add to any app to make it more useful. You have to keep in mind that adding more and more features to an app doesn’t make it useful. Your app can face a massive bounce rate if you stuff it with different features that weren’t necessary. Adding webview to a flutter app is useful because it gives control over the user experience and the navigation with the help of delegated objects. A webview is only useful when you want increased and advanced control over your app’s UI. These advanced controls help you to leverage different web pages in a personalized environment.   Keep staying with us because we will provide you with a Flutter webview source code at the end of this blog. The code will lead you toward creating a webview in Flutter apps development company for Android and iOS both.  Let’s move towards knowing what a webview is in Flutter, how to use it, and some examples of it. What is WebView in Flutter? Webview in a Flutter app is a platform-native view that allows you to integrate website content into your app’s UI. It simply adds the website pages to your app which (when opened) displays the web page over the app’s interface. As long as you surf that website, you can close it with just a click and get back to the app’s UI right away.  Web views present HTML, CSS, and JavaScript content alongside the native view of your app. There are several things that you need to learn to add a webview in Flutter apps. This includes handling the flow while receiving the callbacks from webview to the native app layer and vice versa. Interestingly, webview automatically converts any telephone numbers to phone links that are available on the web content. So when a user taps on the phone number, the app launches the phone dialer and dials the number.  Let’s move towards creating a web view in Flutter apps. How to add a webview in Flutter app for both Android and iOS? Creating a webview in Flutter apps will not seem difficult to you after getting an idea from this blog post. Interestingly, the code is cross-platform so you can reuse it for iOS and Android both. The code given       Here is the Flutter webview source code for you so you can easily create a web view in apps. Change the URL in the final _url to embed the web view of your own website. Results Webview in Flutter example You might have seen some apps which require login with third-party apps. In those apps, an embedded webview layer appears when you click on the login button. That embedded layer allows you to access a specific URL and you surf through it. This is what you call webview in an app.  Another example of webview in an app is when you use third-party payment gateways to make online purchases. The screen that pops up on the app’s UI is an example of webview in Flutter. Conclusion This was pretty much it for a quick guide to adding a webview in Flutter apps. Surprisingly, you can also do some manipulation in the webview_flutter package. These manipulations could be the addition of zooming features, progress bars, etc. No doubt, webview gives benefits by providing enhanced control over the app, there are fewer drawbacks as well. It doesn’t offer the full functionality of the web content that you embed on the app. A native interface has a definite control over all the components so it does its best when it comes to performance.  That’s all folks! We hope you will get a better idea of how to add webview in Flutter apps. If you still have any questions to ask, feel free to comment below. Our team of skilled flutter developers would love to assist you in every way possible.

Read More »

Game Development With Flutter | Learn to Build Awesome Games

In this era of application development, Flutter is becoming more popular and advanced at the same time. No matter what kind of app or game you are building you are developing, the Flutter framework remains an ultimate choice for every developer. Businesses have an eye on game development with Flutter. Fast development, a single codebase system, and a native environment are the few perks that make Flutter one of the best frameworks for game development.  It is obvious that when it comes to game development, developers have to choose a framework that perfectly aligns with the client’s needs and wants. A game developer can either choose a native platform and risk time and money or go with a multi-platform framework like Flutter and risk large app sizes or slow performance. Flutter is the only framework available if you want to do game development without such bloating.   By the end of this blog, you’ll be able to create games using Flutter in no time. Flutter is undoubtedly the best cross-platform mobile app development platform available for game development. It makes the process easier and smoother due to its multiple benefits over other platforms. Moreover, Flutter uses Dart language which is easy to understand for new developers who have even a little knowledge of programming. Game Engines in Flutter  A game engine is a development platform that is solely used to create video games. In addition, you can also create a virtual environment using the game engines. These game engines provide artificial intelligence and animation features to developers to create virtual interfaces, mostly, for mobile devices.  The following are the most common game engines that are used by developers to develop mobile games. 1. Flame The Flame engine is a platform that provides ultimate solutions for game development. As Flame is introduced by Google, it combines with Flutter and gives developers a reliable option to code easily. Flame provides all the necessary functionalities and game loop implementations that you must require to develop games. It provides some simple yet effective functionalities and implementations like sprite sheets, input, images, animations, and a flame component system. Moreover, Flame also offers some stand-alone packages that enhance its functionality of Flame. Interestingly, the Flame engine is growing and improving day by day. Owing to this, they have formed a cooperative community where people freely make suggestions, pull requests, and open issues.   2. Flutter Unity Widget Incorporating 3D visuals within an app is not a difficult task when the development framework is Flutter. You can easily do 3D customization and interpretations with Flutter unity widgets. Flutter unity widget compiles a 3D view of how your app would look on all major platforms before launching it. In this process, both full screen mode and embedded mode are used, so you can be confident that they will work on any mobile device.  3. Flutter Quill  FlutterQuill is a lightweight text editor, component, or game engine that uses quills and feathers. This library is specially built for modern mobile devices. Surprisingly, FlutterQuill for the web is also under development and it will be live anytime soon. Moreover, Quill supports several format options, both in API calls and UI controls. The Quill editor supports all formats by default and allows them to exist within it. Furthermore, you can also configure it with the formats option. You can customize the Quill editor and paste an underlined text into an editor that has no underline button in the toolbar. Keep in mind that this is not the same as adding control in the toolbar. Quill gives you full control over the game you’re developing. 4. Sprite Widget SpriteWidget is one of the most extensively and broadly functional libraries in Flutter. It is used for building 2D games and high-performance animations in Flutter. From an animated icon to a full fledge game, you can create everything with SpriteWidget. Serverpod is the sponsor of SpriteWidget and it is perfect for the backend for any of your apps or game. 5. Forge2D Forge2D is a useful and effective package to use while building games in Flutter. Flame has this open-source engine that provides physics abilities using a Box2D port. Interestingly, you can use this package separately in Dart or your Flame project using flame_forge2d. If you want a complete overview of how to install Forge2D and use it, you can read this page for that. Is Flutter good for game development? You might be wondering whether Flutter is good for game development or not. Or can we use Flutter for game development? The answer to questions like these is both yes and no. Because Flutter is a framework that is designed to create intuitive applications particularity, not for games specifically. So, if you want to build a game similar to Call of Duty, PUBG Mobile, or some other FPS games then Flutter might not be the right choice for you. However, if you want to develop simpler but interactive games like 8 Ball Pool, Flappy Dunk, or ludo then Flutter would undoubtedly be the right choice for you. There are several reasons behind choosing or not choosing Flutter for game development. Here are the benefits and challenges you may undergo after choosing Flutter to develop games. Benefits of Game Development with Flutter There could be several benefits to choosing Flutter for game development. Following are some of the worth mentioning benefits. One of the major benefits of Game development with Flutter is the enhanced control of the canvas. This allows you to create intuitive visuals inside the game and ultimately come up with an amazing game app at the end. In addition, you can see Flutter’s source code from within the IDE.  Flutter is the only platform that is easy to understand. It uses Dart language, which has a similar context as Java, JavaScrip, and C#. So if you have a basic knowledge of any of these programming languages then Flutter isn’t a difficult thing to adopt. It has an easier interface and a clear development

Read More »

How to Install Flutter on Windows, macOS, Linux & Chrome

Flutter is Google’s launched framework that uses a single codebase system to build fast, productive, and beautiful apps. Although there are other development frameworks available, Flutter has its own significance in the software industry. It has several benefits over other platforms which makes it stand out in the market. As you know, the mobile app trends are evolving day by day, it’s becoming more challenging to build apps of the future. Similarly, development frameworks are advancing to cope with the newer and more complex challenges in mobile, web, and desktop app development. Moving on further, we will be discussing how to install flutter on different development platforms like windows, macOS, Linux, and chrome. It has never been so difficult to install flutter on any operating system. Having such beneficial and useful features to build apps, flutter has an easy installation process as well. You need to make sure that your system must meet the minimum requirements to install flutter. Let’s start with the basic steps to install flutter on windows, macOS, Linux, and Chrome OS. How to Install Flutter on Windows? To install flutter on windows, your system should first meet the minimum requirements. According to Flutter, the system requirements to install flutter and run it on windows are: Get the Flutter SDK You need to download the following installation bundle to get the latest stable release of the Flutter SDK. Download it now. You can visit the flutter SDK releases page for the latest releases and older builds. After downloading this zip file, extract the contained flutter SDK in your desired location. We recommend creating a new folder and extracting the SDK in that folder e.g C:\src\flutter). Flutter doesn’t recommend installing flutter in a directory like C:\Program Files\ that requires high privileges. Update the Path If you prefer running Flutter commands in the regular Windows console, you can add Flutter to the PATH environment variable. Just follow these steps: Enter ‘env’ from the window’s search bar and select Edit environment variables for your account. Check if there is an entry called ‘Path’ under user variables. If the entry exists, add the full path to flutter\bin using the symbol “;” as a separator from existing values. And if the entry doesn’t exist, create a new user variable. Name this variable as “Path” with the full path to flutter\bin as its value. You have to close and launch any existing console windows again for these changes to take effect. Run Flutter Doctor           Flutter doctor checks your environment and installation status to show if there are any platform dependencies you need to complete the setup. Run the following command and check the output carefully for any remaining task you may need to complete (report shows in the bold text).   C:\src\flutter>flutter doctor Once you have finished every task, you can run the flutter doctor command again to verify everything has been done correctly. Android Setup For android setup, you need to install android studio. Install Android Studio Follow these steps to install Android Studio. Set Up your Android Device You need an Android device running Android 4.1 (API level 16) or higher to run and test your Flutter app on an Android device. Install Flutter on macOS Installing flutter on macOS has never been so difficult. Flutter lays a simple and easy way to start development and build your first app and so on. To install flutter on macOS, your system must meet the following requirements: Get the Flutter SDK for macOS You can access other release channels and older builds of Flutter SDK for macOS from here. Finishing Installation Process After setting up the path, run the flutter doctor command ($ flutter doctor) so that you can identify if anything is left to finish the setup. See example: [-] Android toolchain – develop for Android devices     • Android SDK at /Users/obiwan/Library/Android/sdk     ✗ Android SDK is missing command-line tools; download from https://developer.android.com/studio/index.html#downloads     • Try re-installing or updating your Android SDK,       Visit https://docs.flutter.dev/setup/#android-setup for detailed instructions. The report mentions every missing dependency and gives you the solution. Install the missing dependencies and run the flutter doctor again to check if everything has been done perfectly. After all, you have to set up the platform. This includes iOS setup, Android setup, mac setup, and web set up. Head over to Flutter’s brief documentation about how to set up all platforms for macOS. Install Flutter on Linux To install flutter on Linux, your development environment must meet the following requirements: bash, curl, file, git 2.x, mkdir, rm, unzip, which, xz-utils, zip. Flutter also depends on shared libraries (libGLU.so.1) to be available on Linux. Get the Flutter SDK for Linux You can install flutter on Linux in two ways. Install Flutter Using Snapd To use snapd is the easiest way to install flutter on Linux. Install snapd from here. After installing snapd, you can install Flutter using Snap Store. You can also install flutter at the command line: $ sudo snap install flutter –classic. Install Flutter Manually If you don’t want to use snapd for flutter installation, you can also install flutter manually. Just follow these steps to install flutter on Linux OS. If you don’t want to install a fixed version, get the source code from the Flutter repo on GitHub. Run the following command: $ git clone https://github.com/flutter/flutter.git $ export PATH=”$PATH:`pwd`/flutter/bin” Pre-download the development binaries and run the following command: Finally, you are now ready to run Flutter commands. After doing all the steps mentioned above, run the flutter doctor command. This checks if there are any dependencies you need to complete the setup. Run the command $ flutter doctor (for verbose output, add the –v flag) to verify every installation dependency. Install Flutter on Chrome OS As for all other OS, your development environment must meet the minimum requirements. For Chrome OS, these are: The library is libGLU.so.1 which is provided by mesa packages such as libglu1-mesa on Ubuntu/Debian. Get the Flutter SDK The rest of the installation steps are the same as for the flutter installation on Linux OS. What

Read More »

A Beginner’s Guide to Firebase Authentication in Flutter

Flutter is a powerful tool when it comes to cross-platform app development. It focuses on delivering an ultimate development experience with its cutting-edge features and reliable coding mechanism. Flutter uses Dart language to write the code for building apps. Dart is a client-oriented programming language that offers to build fast apps for multiple platforms. Many developers leverage this technology to build highly responsive, easy-to-use, and scalable mobile, web, and desktop apps. App development with Flutter becomes more productive when we add firebase to it. In this article, we are going to know everything about firebase authentication. Related Post – using dart enum in flutter What is Firebase Authentication? Flutter User authentication is one of the most important considerations in app development. Any app must know the identity of a user. Knowing a user’s identity allows an app to save user data in the cloud safely. In addition, it provides the same personalized experience across all of the user’s devices. Firebase Authentication provides several useful operations. To authenticate users to your app, Firebase authentication provides services like backend services, easy-to-use SDKs, and ready-made UI libraries. It usually authenticates users with the help of passwords, phone numbers, and some popular federated identity providers like Google, Facebook and Twitter, and more. Firebase Authentication firmly integrates with other Firebase services leveraging industry standards like OAuth 2.0 and OpenID Connect. So you can easily integrate it with your custom backend. Get Started with Firebase Authentication Firstly, you need to get authentication credentials from the users to sign them into your app. Commonly, these credentials can be the user’s email address and password. Or, it could be an OAuth token from a federated identity provider. After all, you pass these credentials to the Firebase Authentication SDK. Then the backend services of Firebase verify those credentials and return a response to the client. You can access the user’s basic profile information when you successfully sign in. Moreover, you can also control the user’s access to data that is stored in other Firebase products. Also, you can use the provided authentication token to verify the identity of users in your own backend services. Before moving further, go through the quick guide of how to integrate Firebase with Flutter app. It is the first and foremost step to learning firebase authentication. Different Ways to Implement Firebase Authentication There are two basic approaches with which we can implement firebase authentication. And these are as follows: FirebaseUI Auth FirebaseUI Auth involves three basic steps to authenticate a user and these are discussed below. You can enable email address and password or phone number sign-in and any federated identity providers you want to support from the Firebase console. Furthermore, complete any configuration required by the identity provider, like setting your OAuth redirect URL. You can customize the user sign-in UI with the help of different FirebaseUI options. You can also fork the code on GitHub and make the possible changes to customize the sign-in experience further. Import the FirebaseUI library. After that, specify the sign-in methods you want to support and initiate the FirebaseUI sign-in flow. Firebase Authentication SDK It has the same procedure for email, password, or phone number sign-in and any identity providers you want to support. You need to enable them in the Firebase console and complete any configuration required by the identity provider, such as setting your OAuth redirect URL. We need to implement a flow that prompts users to enter their credentials for the email address and password sign-in. Similarly, for phone number sign-in, create a flow that prompts users for their phone number. Afterward, ask for the code from the SMS message they receive. For federated sign-in, implement the flow that each provider requires. After implementing UI flows, you have to pass the user’s email address and password or the OAuth token. What’s Next? This is it for a basic guide to Firebase authentication. For further information about integration guides for all other sign-in providers, head over to Firebase Authentication where to start. After all, if you have any queries or suggestions, feel free to leave a comment below. FlutterDesk team would be happy to be of help.

Read More »

How to Add a Border to a Container in Flutter

During flutter app development, you have to use a lot of widgets. These widgets could be text, row, columns, stack, and containers. Sometimes you might need to add a border to a container widget to create a UI box like a button, key, or card. In this practical guide, we are going to learn how to add a border to a container in Flutter. Related Post – Flutter Conditional Show Widgets You can simply add borders to container flutter by applying the BoxDecoration class. I will be giving you an example with a code to add borders to containers in Flutter. Moreover, you can change the border’s width, height, color, or radius. You can also add a border to only one or more than one side of the container. Such as only the left side of the container or only the top and bottom of the container etc. Add Border to Containers in Flutter To add a border to a container in flutter is not a big deal. You just need to wrap a widget in a container and add BoxDecoration class to it as in the code below. As you can see there are some defined parameters like width, height, and colors. You can change the values of these parameters and put them according to your needs. Related Post – animatedcontainer drawer flutter Add Border to Specific Sides of Container in Flutter As discussed earlier, you can add borders to specific sides of a container in Flutter. You just need to specify the side to which you want to add borders and the rest of the code will be the same as above. You can also use the code given below to add a border to a specific side of a container. Add Borders to Symmetrical Sides of a Container You can also add borders to the symmetrical side of a container. The side may be symmetrical vertically or horizontally. Use the code given below to add a border to the symmetrical side of a container. Conclusion In this blog, we have learned how to add a border to a container in Flutter. We’ve also learned how to add borders to one side or more than one side of a container in Flutter. Hopefully, this helps you out with adding borders to a container in Flutter. Also leave a comment below if you have any suggestions or questions to ask. FlutterDesk always inspires Flutter enthusiasts to learn Flutter App Development and help individuals in every way possible.

Read More »

How to Add Borders to TextField in Flutter

TextField in Flutter is a text input widget that is most commonly used to collect inputs from users. We can the input either from a hardware keyboard or an on-screen keyboard. We can use the TextField widget in different forms like building forms, sending messages, creating search experiences, and many more. Flutter TextField allows different kinds of customizations like styling and alignment of the text as well as the cursor inside the TextField. Adding borders to TextField in Flutter is also a major concern of developers while building an app. Delivering the best user experience to end-users is always the utmost priority of developers as well as enterprises. In order to accomplish that, you need to value several aspects of building a user-friendly app. Adding borders to TextField in Flutter You can add borders to TextField in Flutter to make your UI more interactive. Making each and every field prominent that is present on your screen is the only way to make your app user-friendly. A TextField in any flutter app usually requires a hint text and a label. Let’s move towards the code to add borders to TextField in Flutter. Related Post – How to change text color in flutter? Screenshots of the Output As you can see, we have declared the label as “Name”. And you can see, the text field is showing “Name” as the label. Additionally, we defined the border color as gray and its circular radius as “10”. All the results are displayed accordingly in the code. Furthermore, we declared the hint text as “Enter your name”. We declared its color as black, width as “2” and circular radius as 15. As you can see in the screenshot above, the label moves upwards and the hint text displays. It has a border around it with an increased width and circular radius representing what to write in the field. Moreover, if there exists any error in the TextField flutter, the border will change its color to red. Conclusion Thus, you might become aware of the importance of adding borders to TextFields in Flutter after going through this article. We hope this blog helps you one way or the other. Furthermore, if you have any questions or suggestions, you can leave a comment below. Also, you can hire a flutter developer to discuss your ideas related to flutter app development.

Read More »

How to implement a dropdown list in flutter?

A dropdown button is a widget that helps users to select a value or an option from a set of values. The dropdown list is an important element in an app that increases the ease of the users using the app. In this article, we are going to learn how to implement a dropdown list in Flutter. For example, you have a form with city selection. There are two widgets that you can use to show those city details. One option is using the radio button, which allows for selecting a single value. The other option is to use DropDownButton. In scenarios like this, using a dropdown widget will be the best option. This is because you can add a large list of cities. And when the user selects a city, it will show only that selected city in particular. So, it is much more likely to provide a better user experience to the end-user. Code to Add DropDown Button in Flutter Screenshots of Results

Read More »

How to Store Data in Firebase Cloud Firestore Using Flutter App

In the recent article, we gave you a complete guide on how to integrate firebase with your Android, iOS, and Web flutter apps. Before we move on, you should give it a look. If you know how to do that, let’s move forward to learn how to store data in the cloud firestore for flutter apps. In mobile app development, storing and saving users’ data is the most important part of your app. You can save data in different ways using cloud firestore. You can either save the data locally, which means that you can’t share it with others, or save it permanently. So If you want to share your data, you need to save it in the cloud. One of the easiest solutions to this problem is Google’s Cloud Firestore database. Cloud Firestore is a flexible and scalable NoSQL-style database. It is the best approach for small-sized projects to store and sync data for client and server-side development. Unlike traditional databases that require a lot of work to insert data, Firestore lets you save JSON blobs to collections. This method doesn’t limit you to structure your data and allows you to change it at any time. Creating Firestore Database After that, you’re done creating the project and integrating it with the flutter app, now it’s time to create the Firestore database. For this purpose, click on the Firestore database option appearing in the left navigation menu bar on the firebase homepage. As shown here: The cloud firebase window will appear. Click on the “Create database” button. See here: As you click on the create database, a new popup window will appear asking you to choose production mode or test mode. Now the question is which one to choose? The production mode has increased security which requires a series of steps to consider. You won’t be able to handle the requests or the errors if you’re not ready for them. So we choose test mode which you can alternatively call debug mode. In this mode, you can make changes, remove errors, etc. We are moving on with test mode. As I said earlier, you can choose production mode if you’re ready for it. No enforcement. 😛 When you select a mode, the next step is to state the location where you want to create the database. There are different locations to choose from. By clicking on the Cloud Firestore location dropdown, you’ll be able to choose a multi-regional or regional location. You can choose the location according to your requirements or that is closest to your location and then click ‘enable’. As you click enable, the Firebase will provision your Cloud Firestore database and you will be ready to use the database and perform what we are here for. The database console page is shown in the figure below: Collections and Documents in NoSQL A NoSQL database is made up of collections that contain documents in it. A document basically contains the fields that you plan to store, fields being the information or the parameters. You can add collections using simple steps. Let me give you a quick go-through of it. Click on “start collection” in the Cloud Firebase console. A new “start a collection” popup will appear. Enter a collection ID, which is a set of documents that contain data. Then click next. But It will require a document ID that denotes a particular set of data. And then you have to enter different fields like the name, age, or height of a person. We are going to have a coding approach using the flutter app that we integrated with firebase. Add, Update, Delete or Fetch Documents in Firestore Using Flutter App In contrary to storing data in firestore through the console, you can also store data in firestore using the flutter app.To accomplish this task, firstly, you need to create a model to store the data. But here, we are storing users’ data like name, age, etc. Creating a model To organize the data of users, we need to create a model from which we can access the data of an individual or everyone present in the model. So the code to create a model in the flutter app is given below. class UserModel{   UserModel({     required this.name,     required this.phone,     required this.age,   });     String name;   String phone;   int age;   Map<String, dynamic> toJson() => <String, dynamic>{         ‘name’: name,         ‘phone’: phone,         ‘age’: age,       };     factory UserModel.fromJson(Map<String, dynamic> json) => UserModel(     name: json[‘name’] as String,     phone: json[‘phone’] as String,     age: json[‘age’] as int,   ); } Add a Document So you can add a document in firestore using the flutter app with the code given below. Future<UserModel> insertFirestore(UserModel model) async {   try {     final document = await FirebaseFirestore.instance         .collection(collectionName)         .add(model.toJson());     model.id = document.id;     return model;   } catch (e) {     rethrow;   } } Update the Document You can update an existing document in firestore using the code as follows. Future updateFirestore(UserModel model) async {   try {     await FirebaseFirestore.instance         .collection(collectionName)         .doc(model.id)         .update(model.toJson());   } catch (e) {     rethrow;   } } Delete a Document But If you want to delete any document in firestore, you can use the code given below. Future deleteFirestore(String documentId) async {   try {     await FirebaseFirestore.instance         .collection(collectionName)         .doc(documentId)         .delete();   } catch (e) {     rethrow;   } } Fetch a Document You can also fetch the data stored in a particular document in Firestore using the flutter app. Just use the code given below. Future<UserModel> fetchOneFirestore(String id) async {   try {     return parseModel(await FirebaseFirestore.instance         .collection(collectionName)         .doc(id)         .get());   } catch (_) {     rethrow;   } } Fetch all Documents You can also fetch all the documents stored in Firestore. Future<List<UserModel>> fetchAll() async {   try {     final _data =         await FirebaseFirestore.instance.collection(collectionName).get();     return _data.docs.map((document) => UserModel.fromJson(document.data())).toList();

Read More »