Skip to content

Instantly share code, notes, and snippets.

@Moiz-Ali-Moomin
Last active November 8, 2020 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Moiz-Ali-Moomin/c5034ee23f77f4310ba8b46c65f8441d to your computer and use it in GitHub Desktop.
Save Moiz-Ali-Moomin/c5034ee23f77f4310ba8b46c65f8441d to your computer and use it in GitHub Desktop.
Task 3 flutter linux cmd
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class Terminal extends StatefulWidget {
@override
_TerminalState createState() => _TerminalState();
}
class _TerminalState extends State<Terminal> {
var msgtextcontroller = TextEditingController();
var fs = FirebaseFirestore.instance;
var authc = FirebaseAuth.instance;
String cmd, output;
String getans;
String newvalue;
mydata() async {
var url = 'http://fc011477e049.ngrok.io/cgi-bin/cmd2.py?x=$cmd';
var r = await http.get(url);
var data = r.body;
output = data;
}
getansdisplay() async {
await fs.collection("commands").doc(newvalue).get().then((value) {
var data = value.data;
print((data()['output']));
setState(() {
getans = data()['output'];
});
});
}
@override
Widget build(BuildContext context) {
var deviceWidth = MediaQuery.of(context).size.width;
var signInUser = authc.currentUser.email;
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
backgroundColor: Colors.green,
title: Text('Linux Terminal'),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 50,
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 15, 8, 8),
child: Center(
child: Text("Linux Terminal",
style: TextStyle(
fontSize: 30, fontWeight: FontWeight.bold))),
),
SizedBox(height: 50),
Container(
width: deviceWidth * 0.70,
child: TextFormField(
controller: msgtextcontroller,
decoration: InputDecoration(
fillColor: Colors.black,
labelText: 'Enter command',
border: new OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: new BorderSide(
color: Colors.black,
))),
onChanged: (value) {
cmd = value;
},
),
),
SizedBox(
height: 50,
),
Container(
height: deviceWidth * 0.13,
width: deviceWidth * 0.50,
child: RaisedButton(
color: Colors.green,
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.green,
width: 1,
style: BorderStyle.solid),
),
child: Text('Execute Command'),
onPressed: () async {
msgtextcontroller.clear();
await mydata();
await fs.collection("commands").add({
"cmd": cmd,
"output": output,
"sender": signInUser,
}).then((value) {
print(value.id);
print(cmd);
print(output);
newvalue = value.id;
getansdisplay();
});
print(signInUser);
},
),
),
SizedBox(
height: 20,
),
SingleChildScrollView(
child: Center(
child: Container(
margin: EdgeInsets.all(10),
height: 500,
width: 500,
decoration: BoxDecoration(
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.all(10),
child: Text(getans ?? "Output..."),
),
),
),
],
),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment