Flutter IntegrationWith Firebase’s Firestore And Running Any Linux Command Using API
This blog explains how to integrating Linux API with Firebase’s firestore using Flutter. In this integration, any Linux command will be executed using Flutter App which will fetch the command output from Linux Webserver & store the output at the Firestore. The flutter app developed will also have the functionality to retrieve the data from the Firestore.
Steps to be followed :
Step 1: For this task, we have first created an app with the project and organization name using the command prompt.
Go to your flutter folder using the command line and use the command
flutter create yourappname
A new Flutter project. This project is a starting point for a Flutter application. A few resources to get you started…
2. For integrating flutter with the firebase.
- Go to https://firebase.google.com/
- Click on the “Go to console” & then you will be landed on the Firebase homepage. Click on the button given below to add one project.
- After that enter your project name as and follow the further steps to set up the project.
- After the project creation, you will be landed on a page as shown below.
- Now click on the Android Icon shown on the above page and follow the complete process, it will guide you to set up or connect your Flutter App to Firestore.
3. Creating API
The API creation code is shown below. (This code will create one API which will help to run the Linux Commands using a webserver).
Note: For this API code to work, the Apache webserver(httpd) has to be installed on your machine.
Write this code in a file, save it with “.py” extension in the folder “/var/www/cgi-bin”.
Make this file executable by running the command “chmod +x <filename>”.
4. Creating the database in firebase using cloud firestore.
Click on create database icon.
Select the test mode option.
Enable the data-center region and give the project name.
5. For creating the Linux command app.
The packages that have been installed for this app are
- After saving these files restart the ide.
- Now to connect our app with the firebase we need to go to the WebUI first and then click on the android icon there.
- Give the organization name which you used to connect to the firebase. You can go to the your_appfolder->android folder->app-> build.gradle.
- Download the JSON file and put it in the folder as instructed.
- Make changes in both the Gradle files as instructed.
- After completing the above-mentioned steps we can now run our app.
- You can refer to my GitHub repository for code.
- Following the code the app will be looking like this:
The outputs of the commands which have been run on the app will get stored in Firestore as shown below.
I hope this blog helps everyone in making the desired app.