I already created an authentication module for an application but now I would like to retrieve the data and maybe modify them.
I already made this:
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:harcelementapp/authentification/controlAuth.dart';
import 'package:provider/provider.dart';
class Test extends StatefulWidget {
@override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
@override
Widget build(BuildContext context) {
Utilisateur _utilisateurDeFirebaseUser(FirebaseUser user){
return user != null ? Utilisateur(idUtil: user.uid) : null;
}
var utilisateur = Provider.of<FirebaseUser>(context);
final db = DataService();
child: Scaffold(
appBar: new AppBar(
title: Text('Test'),
),
body: StreamBuilder(
stream: Firestore.instance.collection('utilisateurs').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Text('loading');
return Column(
children: <Widget>[
StreamProvider<Personne>.value(
stream: db.streamPersonne(user), // All children will have access to SuperHero data
child: Text('here i would like to show name or email or role for example. juste choose one information from current user data'),
),
]
);
}
)
);
}
}
class Personne {
final String userId;
final String nom;
final String mail;
final String tel;
final String role;
Personne({this.userId, this.nom, this.mail, this.tel, this.role});
factory Personne.fromFirestore(DocumentSnapshot doc) {
Map data = doc.data;
return Personne(
userId: doc.documentID,
nom: data['nomComplet'],
mail: data['emailUtil'],
tel: data['numeroTel'],
role: data['userRole'],
);
}
}
class DataService {
final Firestore _db = Firestore.instance;
Stream<Personne> streamPersonne(String id) {
return _db
.collection('utilisateurs')
.document(id)
.snapshots()
.map((snap) => Personne.fromMap(snap.data));
}
}
I know it doesn't really make sense but i'm a bit confused with some parts of the library. I would like to extract information from my current user which has been authenticated from my database. Then put these information into an object in order to have access to all of each information when I need it. If I want to print just name somewhere I think about something like "text(object.name)".
I tried many different things from different website then it's becomming chaos and I think I'm mixing several concepts.