'Flutter stuck with a "DatabaseEvent subtype" error
The below code gives an error of subtype
code
StreamBuilder(
stream: _database.orderByKey().onValue,
builder: (context, snapshot) {
final valudisp = <Card>[];
if (snapshot.hasData) {
final firstdata = snapshot.data! as Map<String, dynamic>;
firstdata.forEach((key, value) {
final datalast = new Map<String, dynamic>.from(value);
final coinname = datalast.keys;
final displaycard = Card(...);
valudisp.add(displaycard);
});
}
return Expanded(...);
});
}
Now I'm getting below error
type 'DatabaseEvent' is not a subtype of type 'Map<String,dynamic>' in typecast
Solution 1:[1]
I think you're looking for the DatabaseEvent class there:
(snapshot.data! as DatabaseEvent).snapshot.value
// ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Frank van Puffelen |
