Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:firebase_database/firebase_database.dart';
- import 'package:firebase_database/ui/firebase_animated_list.dart';
- import 'package:flutter/material.dart';
- import 'JsonModel_page.dart';
- class FirebasePrenotations extends StatefulWidget {
- @override
- _FirebasePrenotations createState() => _FirebasePrenotations();
- }
- class _FirebasePrenotations extends State<FirebasePrenotations> {
- List<Capelli> capelliList;
- Capelli capelliInit;
- DatabaseReference capelliRef;
- @override
- void initState() {
- super.initState();
- capelliList = new List();
- capelliInit = Capelli("", "", "", "");
- final FirebaseDatabase database = FirebaseDatabase.instance;
- capelliRef = database.reference().child('capelli');
- capelliRef.onChildAdded.listen(_onEntryAdded);
- capelliRef.onChildChanged.listen(_onEntryChanged);
- var db = FirebaseDatabase.instance.reference();
- db.once().then((DataSnapshot snapshot) {
- Map<dynamic, dynamic> values = snapshot.value;
- values.forEach((key, values) {
- print(values['prezzo']);
- });
- });
- }
- _onEntryAdded(Event event) {
- setState(() {
- capelliList.add(Capelli.fromSnapshot(event.snapshot));
- });
- }
- _onEntryChanged(Event event) {
- var capelliOld = capelliList.singleWhere((entry) {
- return entry.capelliKey == event.snapshot.key;
- });
- setState(() {
- capelliList[capelliList.indexOf(capelliOld)] =
- Capelli.fromSnapshot(event.snapshot);
- });
- }
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: new AppBar(
- backgroundColor: Colors.transparent,
- elevation: 0,
- title: new Text(
- "SELEZIONA SERVIZI",
- style: TextStyle(
- fontSize: 16.0,
- color: Colors.black,
- fontWeight: FontWeight.bold,
- letterSpacing: 1),
- ),
- centerTitle: true,
- leading: IconButton(
- icon: Icon(Icons.arrow_back),
- color: Colors.black,
- onPressed: () => Navigator.pop(context),
- ),
- ),
- resizeToAvoidBottomPadding: false,
- body: Column(
- children: <Widget>[
- Flexible(
- child: FirebaseAnimatedList(
- query: capelliRef,
- itemBuilder: (BuildContext context, DataSnapshot snapshot,
- Animation<double> animation, int index) {
- return new ListTile(
- title: Text(capelliList[index].capelliServizi),
- subtitle: Text(capelliList[index].capelliDescrizione,
- style: TextStyle(color: Colors.black54)),
- trailing: Column(
- children: <Widget>[
- Text(capelliList[index].capelliTempo,
- style: TextStyle(color: Colors.black54)),
- Text(capelliList[index].capelliPrezzo,
- style: TextStyle(color: Colors.black54)),
- ],
- ),
- );
- },
- ),
- ),
- ],
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement