如何使用唯一的文档id从firebase获取数据,并将其存储到变量中,如下面代码中所述,以便在_profilename中使用? import'包:cloud_firestore/cloud_firestore.dart'; 导入“包:firebase_auth/firebase_auth.dart”; 进口“包装:颤振/材料.省道”; 类ProfileScreen扩展StatefulWidget{ const ProfileScreen({Key,this.animationController}):super(Key:Key); 最终AnimationController AnimationController; @凌驾 _ProfileScreenState createState()=>\u ProfileScreenState(); } 类_ProfileScreenState扩展状态 使用TickerProviderStateMixin{ 用户; 动画topBarAnimation; 列表视图=[]; 最终ScrollController ScrollController=ScrollController(); 双顶部气压容量=0.0; @凌驾 void initState(){ topBarAnimation=Tween(开始:0.0,结束:1.0)。设置动画( 曲线化( 父项:widget.animationController, 曲线:区间(0,0.5,曲线:Curves.fastoutswowin)); scrollController.addListener((){ 如果(scrollController.offset>=24){ if(顶压能力!=1.0){ 设置状态(){ 顶压能力=1.0; }); } }else if(scrollController.offset=0){ if(TopBaroCapacity!=scrollController.offset/24){ 设置状态(){ topBarOpacity=scrollController.offset/24; }); } }else if(scrollController.offset
在您的问题中很难看到任何与Firestore相关的代码,但正如@Frank在评论中提到的,这个用例非常常见。 简单地说,如下所示:如何使用唯一的文档id从firebase获取数据,并将其存储到变量中,如下面代码中所述,以便在_profilename中使用? import'包:cloud_firestore/cloud_firestore.dart'; 导入“包:firebase_auth/firebase_auth.dart”; 进口“包装:颤振/材料.省道”; 类ProfileScreen扩展StatefulWidget{ const ProfileScreen({Key,this.animationController}):super(Key:Key); 最终AnimationController AnimationController; @凌驾 _ProfileScreenState createState()=>\u ProfileScreenState(); } 类_ProfileScreenState扩展状态 使用TickerProviderStateMixin{ 用户; 动画topBarAnimation; 列表视图=[]; 最终ScrollController ScrollController=ScrollController(); 双顶部气压容量=0.0; @凌驾 void initState(){ topBarAnimation=Tween(开始:0.0,结束:1.0)。设置动画( 曲线化( 父项:widget.animationController, 曲线:区间(0,0.5,曲线:Curves.fastoutswowin)); scrollController.addListener((){ 如果(scrollController.offset>=24){ if(顶压能力!=1.0){ 设置状态(){ 顶压能力=1.0; }); } }else if(scrollController.offset=0){ if(TopBaroCapacity!=scrollController.offset/24){ 设置状态(){ topBarOpacity=scrollController.offset/24; }); } }else if(scrollController.offset,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,在您的问题中很难看到任何与Firestore相关的代码,但正如@Frank在评论中提到的,这个用例非常常见。 简单地说,如下所示: 获取当前用户的UID 向Firestore发出文档ID为UID的请求 (不清楚文档ID是否为用户UID本身,但我将继续示例) 请确保已安装最新版本的Firebase SDK: import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_au
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
class ProfileScreen extends StatefulWidget {
const ProfileScreen({Key key, this.animationController}) : super(key: key);
final AnimationController animationController;
@override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen>
with TickerProviderStateMixin {
User user;
Animation<double> topBarAnimation;
List<Widget> listViews = <Widget>[];
final ScrollController scrollController = ScrollController();
double topBarOpacity = 0.0;
@override
void initState() {
topBarAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: widget.animationController,
curve: Interval(0, 0.5, curve: Curves.fastOutSlowIn)));
scrollController.addListener(() {
if (scrollController.offset >= 24) {
if (topBarOpacity != 1.0) {
setState(() {
topBarOpacity = 1.0;
});
}
} else if (scrollController.offset <= 24 &&
scrollController.offset >= 0) {
if (topBarOpacity != scrollController.offset / 24) {
setState(() {
topBarOpacity = scrollController.offset / 24;
});
}
} else if (scrollController.offset <= 0) {
if (topBarOpacity != 0.0) {
setState(() {
topBarOpacity = 0.0;
});
}
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
//for circle avtar image
_getHeader(),
SizedBox(
height: 10,
),
_profileName("Pranshul"),
SizedBox(
height: 14,
),
_heading("Personal Details"),
SizedBox(
height: 6,
),
_detailsCard(),
SizedBox(
height: 10,
),
_heading("Other Details"),
SizedBox(
height: 6,
),
_settingsCard(),
],
)),
);
}
Widget _getHeader() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
//borderRadius: BorderRadius.all(Radius.circular(10.0)),
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://i.pinimg.com/originals/c5/97/1e/c5971e1f8181a1d85a35f47456af4db2.gif"))
// color: Colors.orange[100],
),
),
),
],
);
}
Widget _profileName(String name) {
return Container(
width: MediaQuery.of(context).size.width * 0.80, //80% of width,
child: Center(
child: Text(
name,
style: TextStyle(
color: Colors.black, fontSize: 24, fontWeight: FontWeight.w800),
),
),
);
}
Widget _heading(String heading) {
return Container(
width: MediaQuery.of(context).size.width * 0.80, //80% of width,
child: Text(
heading,
style: TextStyle(fontSize: 16),
),
);
}
Widget _detailsCard() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
elevation: 4,
child: Column(
children: [
//row for each deatails
ListTile(
leading: Icon(Icons.email),
title: Text("Pranshulagrawal9269@gmail.com"),
),
Divider(
height: 0.6,
color: Colors.black87,
),
ListTile(
leading: Icon(Icons.phone),
title: Text("72320xxxxx"),
),
Divider(
height: 0.6,
color: Colors.black87,
),
ListTile(
leading: Icon(Icons.location_on),
title: Text("Rajasthan"),
)
],
),
),
);
}
Widget _settingsCard() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
elevation: 4,
child: Column(
children: [
ListTile(
leading: Icon(Icons.topic),
title: Text("Pranshul Agrawal"),
),
Divider(
height: 0.6,
color: Colors.black87,
),
//row for each deatails
ListTile(
leading: Icon(Icons.settings),
title: Text("3417-7885-xxxx"),
),
Divider(
height: 0.6,
color: Colors.black87,
),
ListTile(
leading: Icon(Icons.dashboard_customize),
title: Text("RJAOKFTGBVFG75468"),
),
],
),
),
);
}
}
正在获取当前用户UID,然后获取文档:
dependencies:
flutter:
sdk: flutter
firebase_core: "^0.7.0"
firebase_auth: "^0.20.1"
cloud_firestore: "^0.16.0+1"
//Latest version while answering this ^
如果UID作为字段存储在文档中,并且与文档ID不同,则可以使用。
如果您还有任何问题,请告诉我!在您的问题中很难看到任何与Firestore相关的代码,但正如@Frank在评论中提到的,此用例非常常见。 简单地说,如下所示:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
class ProfileScreen extends StatefulWidget {
const ProfileScreen({Key key, this.animationController}) : super(key: key);
final AnimationController animationController;
@override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen>
with TickerProviderStateMixin {
User user;
Animation<double> topBarAnimation;
List<Widget> listViews = <Widget>[];
final ScrollController scrollController = ScrollController();
double topBarOpacity = 0.0;
@override
void initState() {
topBarAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: widget.animationController,
curve: Interval(0, 0.5, curve: Curves.fastOutSlowIn)));
scrollController.addListener(() {
if (scrollController.offset >= 24) {
if (topBarOpacity != 1.0) {
setState(() {
topBarOpacity = 1.0;
});
}
} else if (scrollController.offset <= 24 &&
scrollController.offset >= 0) {
if (topBarOpacity != scrollController.offset / 24) {
setState(() {
topBarOpacity = scrollController.offset / 24;
});
}
} else if (scrollController.offset <= 0) {
if (topBarOpacity != 0.0) {
setState(() {
topBarOpacity = 0.0;
});
}
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
//for circle avtar image
_getHeader(),
SizedBox(
height: 10,
),
_profileName("Pranshul"),
SizedBox(
height: 14,
),
_heading("Personal Details"),
SizedBox(
height: 6,
),
_detailsCard(),
SizedBox(
height: 10,
),
_heading("Other Details"),
SizedBox(
height: 6,
),
_settingsCard(),
],
)),
);
}
Widget _getHeader() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
//borderRadius: BorderRadius.all(Radius.circular(10.0)),
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://i.pinimg.com/originals/c5/97/1e/c5971e1f8181a1d85a35f47456af4db2.gif"))
// color: Colors.orange[100],
),
),
),
],
);
}
Widget _profileName(String name) {
return Container(
width: MediaQuery.of(context).size.width * 0.80, //80% of width,
child: Center(
child: Text(
name,
style: TextStyle(
color: Colors.black, fontSize: 24, fontWeight: FontWeight.w800),
),
),
);
}
Widget _heading(String heading) {
return Container(
width: MediaQuery.of(context).size.width * 0.80, //80% of width,
child: Text(
heading,
style: TextStyle(fontSize: 16),
),
);
}
Widget _detailsCard() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
elevation: 4,
child: Column(
children: [
//row for each deatails
ListTile(
leading: Icon(Icons.email),
title: Text("Pranshulagrawal9269@gmail.com"),
),
Divider(
height: 0.6,
color: Colors.black87,
),
ListTile(
leading: Icon(Icons.phone),
title: Text("72320xxxxx"),
),
Divider(
height: 0.6,
color: Colors.black87,
),
ListTile(
leading: Icon(Icons.location_on),
title: Text("Rajasthan"),
)
],
),
),
);
}
Widget _settingsCard() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
elevation: 4,
child: Column(
children: [
ListTile(
leading: Icon(Icons.topic),
title: Text("Pranshul Agrawal"),
),
Divider(
height: 0.6,
color: Colors.black87,
),
//row for each deatails
ListTile(
leading: Icon(Icons.settings),
title: Text("3417-7885-xxxx"),
),
Divider(
height: 0.6,
color: Colors.black87,
),
ListTile(
leading: Icon(Icons.dashboard_customize),
title: Text("RJAOKFTGBVFG75468"),
),
],
),
),
);
}
}
正在获取当前用户UID,然后获取文档:
dependencies:
flutter:
sdk: flutter
firebase_core: "^0.7.0"
firebase_auth: "^0.20.1"
cloud_firestore: "^0.16.0+1"
//Latest version while answering this ^
如果UID作为字段存储在文档中,并且与文档ID不同,则可以使用。
如果您还有任何问题,请告诉我!if conditionfetchdata(){var firebaseUser=FirebaseAuth.instance.currentUser;CollectionReference CollectionReference=Firestore.instance.collection('users');CollectionReference.snapshots().listen((快照){setState((){data=snapshot.documents[0].data();name=data['Aadharno'].toString();print(name);});});已尝试此操作,但无法在文档中分配uid,因为它只需要intvalue@PranshulAgrawal请共享错误
.doc()的屏幕截图
显然也接受了前面提到的字符串值,在if conditionfetchdata(){var firebaseUser=FirebaseAuth.instance.currentUser;CollectionReference CollectionReference=Firestore.instance.collection('users');CollectionReference.snapshots().listen((快照){setState(){data=snapshot.documents[0].data();name=data['Aadharno'].toString();print(name);});});已尝试此操作,但无法在文档中分配uid,因为它只需要intvalue@PranshulAgrawal请分享错误.doc()
的屏幕截图,清楚地接受前面提到的字符串值