SHARE
TWEET

ListView

a guest Jan 23rd, 2020 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:firebase_database/firebase_database.dart';
  2. import 'package:firebase_database/ui/firebase_animated_list.dart';
  3. import 'package:flutter/material.dart';
  4. import 'JsonModel_page.dart';
  5.  
  6. class FirebasePrenotations extends StatefulWidget {
  7.   @override
  8.   _FirebasePrenotations createState() => _FirebasePrenotations();
  9. }
  10.  
  11. class _FirebasePrenotations extends State<FirebasePrenotations> {
  12.   List<Capelli> capelliList;
  13.   Capelli capelliInit;
  14.   DatabaseReference capelliRef;
  15.  
  16.   @override
  17.   void initState() {
  18.     super.initState();
  19.  
  20.     capelliList = new List();
  21.     capelliInit = Capelli("", "", "", "");
  22.  
  23.     final FirebaseDatabase database = FirebaseDatabase.instance;
  24.  
  25.     capelliRef = database.reference().child('capelli');
  26.     capelliRef.onChildAdded.listen(_onEntryAdded);
  27.     capelliRef.onChildChanged.listen(_onEntryChanged);
  28.  
  29.     var db = FirebaseDatabase.instance.reference();
  30.     db.once().then((DataSnapshot snapshot) {
  31.       Map<dynamic, dynamic> values = snapshot.value;
  32.       values.forEach((key, values) {
  33.         print(values['prezzo']);
  34.       });
  35.     });
  36.   }
  37.  
  38.   _onEntryAdded(Event event) {
  39.     setState(() {
  40.       capelliList.add(Capelli.fromSnapshot(event.snapshot));
  41.     });
  42.   }
  43.  
  44.   _onEntryChanged(Event event) {
  45.     var capelliOld = capelliList.singleWhere((entry) {
  46.       return entry.capelliKey == event.snapshot.key;
  47.     });
  48.     setState(() {
  49.       capelliList[capelliList.indexOf(capelliOld)] =
  50.           Capelli.fromSnapshot(event.snapshot);
  51.     });
  52.   }
  53.  
  54.   Widget build(BuildContext context) {
  55.     return Scaffold(
  56.       appBar: new AppBar(
  57.         backgroundColor: Colors.transparent,
  58.         elevation: 0,
  59.         title: new Text(
  60.           "SELEZIONA SERVIZI",
  61.           style: TextStyle(
  62.               fontSize: 16.0,
  63.               color: Colors.black,
  64.               fontWeight: FontWeight.bold,
  65.               letterSpacing: 1),
  66.         ),
  67.         centerTitle: true,
  68.         leading: IconButton(
  69.           icon: Icon(Icons.arrow_back),
  70.           color: Colors.black,
  71.           onPressed: () => Navigator.pop(context),
  72.         ),
  73.       ),
  74.       resizeToAvoidBottomPadding: false,
  75.       body: Column(
  76.         children: <Widget>[
  77.           Flexible(
  78.             child: FirebaseAnimatedList(
  79.               query: capelliRef,
  80.               itemBuilder: (BuildContext context, DataSnapshot snapshot,
  81.                   Animation<double> animation, int index) {
  82.                 return new ListTile(
  83.                   title: Text(capelliList[index].capelliServizi),
  84.                   subtitle: Text(capelliList[index].capelliDescrizione,
  85.                       style: TextStyle(color: Colors.black54)),
  86.                   trailing: Column(
  87.                     children: <Widget>[
  88.                       Text(capelliList[index].capelliTempo,
  89.                           style: TextStyle(color: Colors.black54)),
  90.                       Text(capelliList[index].capelliPrezzo,
  91.                           style: TextStyle(color: Colors.black54)),
  92.                     ],
  93.                   ),
  94.                 );
  95.               },
  96.             ),
  97.           ),
  98.         ],
  99.       ),
  100.     );
  101.   }
  102. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top