-
Notifications
You must be signed in to change notification settings - Fork 9
/
chat.dart
231 lines (206 loc) · 7.12 KB
/
chat.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import 'dart:ui';
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;
//import 'package:characters/characters.dart';
class MychatState extends StatefulWidget {
@override
_MychatState createState() => _MychatState();
}
class _MychatState extends State<MychatState> {
var firestoresconnect = FirebaseFirestore.instance;
String command;
var output;
var authc = FirebaseAuth.instance;
var color;
// Function to retreive the output of the Linux Commands from the Firebase!
getData() async {
var data =
await firestoresconnect.collection("<Firebase Collection Name>").get();
for (var i in data.docs) {
print(i.data());
}
}
// Funciton to get the output of the Linux Command running!
getLinuxOutput(cmd) async {
var url = "http://192.168.43.40/cgi-bin/web.py?x=myx";
setState(()async {
output = await http.get(url);
});
print(output.body);
await firestoresconnect
.collection("Firebase Collection Name")
.add({command: "date"});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Linux & Redhat"),// style TextStyle(color: Colors.yellow),),
actions: <Widget>[
IconButton(
icon: Icon(Icons.close),
onPressed: () async {
print("sign off");
await authc.signOut();
Navigator.pushNamed(context, "login");
}),
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
//crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.amber,
margin: EdgeInsets.all(40),
child: TextField(
onChanged: (value) {
command = value;
},
autocorrect: false,
textAlign: TextAlign.center,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: "Enter the Linux Command",
prefixIcon: Icon(Icons.code),
fillColor: Colors.amber,
focusColor: Colors.red,
),
),
),
// Row(
// children: <Widget>[
// Container(
// child: Image.asset('image/Redhat logo/png',height: 150, width: 120),),],),
RaisedButton(
color: Colors.yellow,
child: Text(
"Submit ",
style: TextStyle(
color: Colors.redAccent[200],
// fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
onPressed: () {
getLinuxOutput(command);
print("Output Sent");
},
),
Container(
child: Text(
output == null? "String is there" : output),
),])));
}
}
// 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 MychatState extends StatefulWidget {
// @override
// _MychatStateState createState() => _MychatStateState;
// }
// class_MychatStateState extends State<MychatState> {
// var firestoresconnect = FirebaseFirestore.instance;
// String command;
// var output;
// var authc = FirebaseAuth.instance;
// // Function to retreive the output of the Linux Commands fromf the Firebase!
// getData() async {
// var data =
// await firestoresconnect.collection("<Firebase Collection Name>").get();
// for (var i in data.docs) {
// print(i.data());
// }
// }
// // Funciton to get the output of the Linux Command running!
// getLinuxOutput(cmd) async {
// var url = "http://192.168.43.40/cgi-bin/web.py?y=date";
// var output = await http.get(url);
// print(output.body);
// await firestoresconnect
// .collection("Firebase Collection Name")
// .add({command: "date"});
// }
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: Text("Chat Page"),
// actions: <Widget>[
// IconButton(
// icon: Icon(Icons.close),
// onPressed: () async {
// print("sign off");
// await authc.signOut();
// Navigator.pushNamed(context, "login");
// }),
// ],
// ),
// body: Center(
// child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
// //crossAxisAlignment: CrossAxisAlignment.center,
// children: <Widget>[
// Container(
// color: Colors.amber,
// margin: EdgeInsets.all(20),
// child: TextField(
// onChanged: (value) {
// command = value;
// },
// autocorrect: false,
// textAlign: TextAlign.center,
// decoration: InputDecoration(
// border: OutlineInputBorder(),
// hintText: "Enter the Linux Command",
// prefixIcon: Icon(Icons.code),
// fillColor: Colors.greenAccent,
// focusColor: Colors.red,
// ),
// ),
// ),
// RaisedButton(
// color: Colors.greenAccent[100],
// child: Text(
// "Submit ",
// style: TextStyle(
// color: Colors.redAccent[200],
// fontStyle: FontStyle.italic,
// fontWeight: FontWeight.bold,
// fontSize: 20,
// ),
// ),
// onPressed: () {
// getLinuxOutput(command);
// print("Output Sent");
// },
// ),
// RaisedButton(
// color: Colors.amberAccent[100],
// child: Text(
// "Get Linux Commands Output from Firebase!",
// style: TextStyle(
// color: Colors.redAccent[200],
// fontStyle: FontStyle.italic,
// fontWeight: FontWeight.bold,
// fontFamily: "SF Pro",
// fontSize: 18,
// ),
// ),
// onPressed: () {
// getData();
// print("Output Received!");
// },
// ),
// ],
// ),
// ),
// );
// }
// }