我想显示用户的全名。它存储在Firestore中,如下图所示。我正在尝试,但没有任何效果。我该如何解决此问题?
第一次
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:file_picker/file_picker.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
import 'package:flutter_dev/reusable.dart';
class Fy extends StatefulWidget {
const Fy({super.key});
@override
State<Fy> createState() => _FyState();
}
class _FyState extends State<Fy> {
PlatformFile? pickedFile;
dynamic data;
dynamic user = FirebaseAuth.instance.currentUser;
final db = FirebaseFirestore.instance;
Future getName() async {
final getFullName = db.collection("users").doc(user.uid);
getFullName.get().then((DocumentSnapshot doc) {
setState(() {
dynamic data = doc.data["fullName"].toString();
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
'Hello $data}}',
style: const TextStyle(color: Colors.white),
),
Text(
'${user.uid}',
style: const TextStyle(color: Colors.white),
),
]),
),
);
}
}
错误行
1条答案
按热度按时间swvgeqrz1#
“如果能帮助别人,我自己会找到”