Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:cloud_firestore/cloud_firestore.dart';
- import 'package:firebase_auth/firebase_auth.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'add_view.dart';
- class Homeview extends StatefulWidget {
- const Homeview({Key? key}) : super(key: key);
- @override
- State<Homeview> createState() => _HomeviewState();
- }
- class _HomeviewState extends State<Homeview> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Container(
- decoration: BoxDecoration(
- color: Colors.white,
- ),
- width: MediaQuery.of(context).size.width,
- height: MediaQuery.of(context).size.height,
- child: StreamBuilder(
- stream: FirebaseFirestore.instance
- .collection('Users')
- .doc(FirebaseAuth.instance.currentUser?.uid)
- .collection('Coins')
- .snapshots(),
- builder:
- (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
- if (!snapshot.hasData) {
- return Center(
- child: CircularProgressIndicator(),
- );
- }
- return ListView(
- children: snapshot.data!.docs.map((document) {
- return Container(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- Text("Coin Name: ${document.id}"),
- Text("Amount owned: ${document.data()!["amount"]}"),
- ],
- ),
- );
- }).toList(),
- );
- },
- ),
- ),
- floatingActionButton: FloatingActionButton(
- onPressed: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => Addview(),
- ));
- },
- child: Icon(
- Icons.add,
- color: Colors.white,
- ),
- backgroundColor: Colors.blue,
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment