Created
March 11, 2021 19:51
-
-
Save cankush625/8d2322209db1213070f250c4ae44cf94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:cloud_firestore/cloud_firestore.dart'; | |
import 'package:flutter/rendering.dart'; | |
class History extends StatefulWidget { | |
@override | |
_HistoryState createState() => _HistoryState(); | |
} | |
class _HistoryState extends State<History> { | |
var fsconnect = FirebaseFirestore.instance; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.black, | |
appBar: AppBar( | |
backgroundColor: Colors.black26, | |
title: Text( | |
'Command History', | |
), | |
), | |
body: SafeArea( | |
child: SingleChildScrollView( | |
child: Container( | |
child: StreamBuilder<QuerySnapshot>( | |
stream: fsconnect.collection('terminal_outputs').snapshots(), | |
builder: (context, snapshot) { | |
if(snapshot.data == null) return CircularProgressIndicator(); | |
var msg = snapshot.data.docs; | |
List<Widget> y = []; | |
for (var d in msg) { | |
var commandName = d.data()['commandName'].toString(); | |
var commandOutput = d.data()['commandOutput'].toString(); | |
print(commandName); | |
var comm = FutureBuilder( | |
future: getData("kYS7uQdqxVHwqEggtHcW"), | |
builder: (BuildContext context, AsyncSnapshot<List> snapshot){ | |
Widget widget; | |
if (snapshot.connectionState == ConnectionState.done) { | |
print("snapshot data ${snapshot}"); | |
widget = Text( | |
snapshot.data[0], | |
style: TextStyle( | |
color: Colors.white, | |
), | |
); | |
} else { | |
widget = CircularProgressIndicator(); | |
} | |
return widget; | |
}, | |
); | |
y.add(comm); | |
} | |
return Container( | |
child: Column( | |
children: y, | |
), | |
); | |
}, | |
), | |
), | |
), | |
), | |
); | |
} | |
Future<List> getData(String Id) async { | |
var workoutData; | |
await fsconnect.collection("terminal_outputs").doc(Id).get().then((value) { | |
// Getting data from the document from another collection | |
workoutData = value.data(); | |
}); | |
// retrieving data from particular field | |
var data = await workoutData["timestamp"]; | |
var commandName = await workoutData['commandName']; | |
print("workoutData: $workoutData"); | |
print("data is:: $data"); | |
List l = [data, commandName]; | |
print("List is ${l}"); | |
return l; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment