[text] Sips for qr

Viewer

copydownloadembedprintName: Sips for qr
  1. import 'package:firebase_storage/firebase_storage.dart';
  2. import 'package:cloud_firestore/cloud_firestore.dart';
  3.  
  4. class AnimalInfo extends StatefulWidget {
  5.   final String qrCodeResult;
  6.  
  7.   AnimalInfo({this.qrCodeResult});
  8.  
  9.   @override
  10.   _AnimalInfoState createState() => _AnimalInfoState();
  11. }
  12.  
  13. class _AnimalInfoState extends State<AnimalInfo> {
  14.   Animal animal;
  15.   Gin gin;
  16.  
  17.   @override
  18.   void initState() {
  19.     super.initState();
  20.  
  21.     // Get the animal document from Firestore
  22.     Firestore.instance
  23.         .collection('animals')
  24.         .where('qrCodeResult', isEqualTo: widget.qrCodeResult)
  25.         .get()
  26.         .then((querySnapshot) {
  27.       if (querySnapshot.documents.isNotEmpty) {
  28.         setState(() {
  29.           animal = Animal(
  30.             name: querySnapshot.documents[0]['name'],
  31.             description: querySnapshot.documents[0]['description'],
  32.             imageUrl: querySnapshot.documents[0]['imageUrl'],
  33.           );
  34.         });
  35.       }
  36.     });
  37.  
  38.     // Get the gin document from Firestore
  39.     Firestore.instance
  40.         .collection('gins')
  41.         .where('qrCodeResult', isEqualTo: widget.qrCodeResult)
  42.         .get()
  43.         .then((querySnapshot) {
  44.       if (querySnapshot.documents.isNotEmpty) {
  45.         setState(() {
  46.           gin = Gin(
  47.             name: querySnapshot.documents[0]['name'],
  48.             description: querySnapshot.documents[0]['description'],
  49.             imageUrl: querySnapshot.documents[0]['imageUrl'],
  50.           );
  51.         });
  52.       }
  53.     });
  54.   }
  55.  
  56.   @override
  57.   Widget build(BuildContext context) {
  58.     return Scaffold(
  59.       appBar: AppBar(
  60.         title: Text('Animal Info'),
  61.       ),
  62.       body: Center(
  63.         child: Column(
  64.           mainAxisAlignment: MainAxisAlignment.center,
  65.           children: <Widget>[
  66.             Text('Animal Name: ${animal?.name ?? ''}'),
  67.             Text('Animal Description: ${animal?.description ?? ''}'),
  68.             Image.network(animal?.imageUrl ?? ''),
  69.             SizedBox(height: 20),
  70.             Text('Gin Name: ${gin?.name ?? ''}'),
  71.             Text('Gin Description: ${gin?.description ?? ''}'),
  72.             Image.network(gin?.imageUrl ?? ''),
  73.           ],
  74.         ),
  75.       ),
  76.     );
  77.   }
  78. }
  79.  

Editor

You can edit this paste and save as new:


File Description
  • Sips for qr
  • Paste Code
  • 09 May-2024
  • 2.2 Kb
You can Share it: