Created
March 11, 2021 16:53
-
-
Save cankush625/9891e228a53c25fa22e573d6122be37b to your computer and use it in GitHub Desktop.
This file contains hidden or 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<String> snapshot){ | |
| Widget widget; | |
| if (snapshot.connectionState == ConnectionState.done) { | |
| widget = Text( | |
| snapshot.data, | |
| style: TextStyle( | |
| color: Colors.white, | |
| ), | |
| ); | |
| } else { | |
| widget = CircularProgressIndicator(); | |
| } | |
| return widget; | |
| }, | |
| ); | |
| y.add(comm); | |
| } | |
| return Container( | |
| child: Column( | |
| children: y, | |
| ), | |
| ); | |
| }, | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| Future<String> 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"]; | |
| print("workoutData: $workoutData"); | |
| print("data is:: $data"); | |
| return data; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment