I’m not able to retrieve data from cloud firestore using the flutter web app.
I can write data but cant read it.
In the app for android / ios it works fine with the emulator. I hope that someone can help me.
This is my index.html:
<!DOCTYPE html>
<html>
<head>
<base href="/">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="hsgaburg">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<title>test</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('flutter-first-frame', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-functions.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.7/firebase-messaging.js"></script>
<script>
var firebaseConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
With the StreamBuilder I want to retrieve the data:
StreamBuilder<List<News>>(
stream: newsBloc.getAllNews,
builder: (context, snapshot) {
if (!snapshot.hasData)
return (UniversalPlatform.isIOS)
? CupertinoActivityIndicator()
: CircularProgressIndicator();
return Column(
children: (
Expanded(
child: ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.all(10),
decoration: BoxDecoration(),
child: Bubble(
color: Colors.white,
elevation: 5,
margin: BubbleEdges.only(top: 10),
stick: true,
nip: BubbleNip.leftTop,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: (
Text(
snapshot.data(index).creator,
style: TextStyles.headline3,
),
AppDivider(),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 10.0),
child: Text(snapshot.data(index).newsText,
style: TextStyles.body),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: (
Text(
formatDate(snapshot.data(index).createdAt),
style: TextStyles.placeholder,
),
),
),
),
),
),
);
},
),
),
),
);
/* } else
return CircularProgressIndicator(); */
})
Here is my pubspec.yaml:
flutter:
sdk: flutter
http:
firebase_messaging: ^8.0.0-dev.11
groovin_widgets: ^1.6.0
provider: ^4.3.2+2
shared_preferences: ^0.5.12+4
firebase_core: ^0.7.0
cloud_firestore: ^0.16.0
firebase_auth: ^0.20.0+1
device_info: ^1.0.0
package_info: ^0.4.3+2
uuid: ^2.2.2
google_fonts: ^1.1.1
rxdart: ^0.25.0
bubble: ^1.1.9+1
intl: ^0.16.1
table_calendar: ^2.3.3
flutter_bloc: ^6.1.1
numberpicker: ^1.3.0
##for web:
universal_platform: ^0.1.3