Created
June 2, 2022 02:10
-
-
Save anoochit/1a8a14d08e67716728c14fe80db36107 to your computer and use it in GitHub Desktop.
sample dropdown in future builder
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
| // get log history | |
| FutureBuilder( | |
| future: FirebaseFirestore.instance.collection('sick').doc(widget.idcard).collection('logs').get(), | |
| builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) { | |
| if (snapshot.hasError) { | |
| return Text('Error: ${snapshot.error}'); | |
| } | |
| if (!snapshot.hasData) { | |
| return Text('Loading...'); | |
| } | |
| // get data from firebase | |
| List<DocumentSnapshot> logDocument = snapshot.data!.docs; | |
| return Center( | |
| child: Container( | |
| padding: EdgeInsets.symmetric(horizontal: 16), | |
| decoration: BoxDecoration( | |
| color: Color(0xfff29a94), | |
| borderRadius: BorderRadius.circular(32.0), | |
| ), | |
| child: DropdownButton( | |
| hint: Text('ประวัติบันทึกข้อมูล'), | |
| items: logDocument.map((doc) { | |
| // get datetime format | |
| DateTime date = DateTime.fromMillisecondsSinceEpoch(int.parse(doc['timestamp'])); | |
| final datetimeTitle = DateFormat('dd MMMM yyyy HH:mm').format(date); | |
| return DropdownMenuItem( | |
| child: Text(datetimeTitle), | |
| value: doc['timestamp'], | |
| ); | |
| }).toList(), | |
| onChanged: (value) { | |
| // find a doocument with docId = value | |
| // open new page with data | |
| dev.log('goto page with docId = $value'); | |
| }, | |
| ), | |
| ), | |
| ); | |
| }, | |
| ), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment