【发布时间】:2021-08-12 04:16:00
【问题描述】:
谁能告诉我我哪里做错了,为了克服 'Future' is not a subtype of type 'Stream?' 的错误,必须在代码中进行哪些更改? 。之前的错误就像 Future' 不是“Widget”类型的子类型
以下是导致此错误的代码
class _StudentDashboardState extends State<StudentDashboard> {
userdetails userdetail;
String res;
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
final CollectionReference student_details =
FirebaseFirestore.instance.collection('students');
final CollectionReference tutor_details =
FirebaseFirestore.instance.collection("tutors");
String uid = FirebaseAuth.instance.currentUser.uid;
@override
void initState() {
super.initState();
}
displayPercentage() async {
var percentage = 0.0;
var totalClassesTook;
var totalClassesAttended;
try {
totalClassesTook = await tutor_details.doc(uid).get().then((doc) async {
var val = await doc.data()['TotalClassesTook'];
return val;
});
totalClassesTook = await totalClassesTook == null ? 0 : totalClassesTook;
totalClassesAttended =
await student_details.doc(uid).get().then((doc) async {
var val = await doc.data()['TotalClassesAttended'];
return val;
});
totalClassesAttended =
await totalClassesAttended == null ? 0 : totalClassesAttended;
percentage =
await ((totalClassesAttended / totalClassesTook) * 100.0) / 100.0;
} catch (e) {
percentage = 0.0;
}
return Center(
child: ListView(children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(vertical: 150.0),
child: new CircularPercentIndicator(
radius: 120.0,
lineWidth: 13.0,
animation: true,
percent: percentage,
center: new Text(
"$percentage",
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
footer: Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
child: new Text(
"Attendance Percentage",
style:
new TextStyle(fontWeight: FontWeight.bold, fontSize: 17.0),
),
),
circularStrokeCap: CircularStrokeCap.round,
progressColor: Colors.purple,
),
),
]),
);
}
@override
Widget build(BuildContext context) {
return Container(
child: SafeArea(
child: StreamBuilder(
stream: displayPercentage(),
builder: (context, snapshot) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.lightGreen,
title: Text('Student Welcome'),
actions: <Widget>[
TextButton.icon(
onPressed: () async {
await _auth.signOut();
Navigator.of(context).pushNamed('/homepage');
},
icon: Icon(Icons.person),
label: Text('Logout'))
],
),
body:
displayPercentage(),
);
}),
),
);
}
【问题讨论】:
标签: android firebase flutter dart google-cloud-firestore