INTEGRATE LINUX WITH FLUTTER

Hello Everyone

In this article I have written about how we can integrate flutter with Linux .

Step 1. Create a Flutter app.

flutter create my_app

cd my_app

Step 2. Install RHEL 8 on your pc.

Step 3. Install Python and Apache server on it.

Step 4. Write a Python script to execute Linux commands.

cd /var/www/cgi-bin

vim app.py

Python CGI Code

Step 5. Make the file executable.

chmod +x app.py

Step 6. Disable selinux and firewalld with following cmd:

setenforce 0

systemctl stop firewalld

Step 7. Now, Write the Flutter code

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:google_mobile_ads/google_mobile_ads.dart';

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

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
@override
late String cmd;
late String data = "OUTPUT";
void cgi() async {
var r = await http
.get(Uri.http("192.168.43.31", "/cgi-bin/app.py", {"x": cmd}));
data = r.body.toString();
setState(() {
data;
print(data);
});
}

Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: Text("LINUX TERMINAL"),
centerTitle: true,
),
body: Center(
child: Column(
children: [
Container(
child: Image.network(
"https://th.bing.com/th/id/R.772baf9baa36a115b147e5e114be2e0a?rik=PQUKUbgZwmDjVA&riu=http%3a%2f%2fopensourcewin.files.wordpress.com%2f2013%2f01%2fe1.jpg&ehk=gNYyw%2fl%2bB2UDcL3plgb7PChDnQTjZbZCv6rSKTiJ7wA%3d&risl=&pid=ImgRaw"),
width: 350,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
),
),
Container(
padding: EdgeInsets.all(20),
child: TextField(
onChanged: (value) {
cmd = value;
},
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "ENTER COMMAND",
),
),
),
Container(
child: TextButton(
onPressed: cgi,
child: Text("RUN"),
)),
Container(
padding:
EdgeInsets.only(left: 20, top: 20, bottom: 20, right: 20),
width: 380,
height: 400,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.circular(30),
color: Colors.lightBlue,
),
child: Center(
child: ListView(
children: [
Center(
child: Text(
"$data",
style: TextStyle(
fontSize: 8, fontWeight: FontWeight.w800),
),
)
],
),
)),
],
),
),
),
);
}
}

Step 8 . Now , let’s see some demo of my app

Output of “cal” command
Output of “date” command
Output of “pwd” command

Successfully Completed the task 😃

Thanks for Reading !! 📃

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store