type ‘String’ is not a subtype of type ‘Movie’
please someone help me solve this problem thaks
I am getting error when trying to run in flutter (type ‘String’ is not a subtype of type ‘int’ of ‘index’)
import 'dart:math';
import 'package:firebase_database/firebase_database.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:realstate/home%20page/addingpage.dart';
import 'package:realstate/home%20page/inkwall.dart';
import 'package:sqflite/sqflite.dart';
import '../account page/account page.dart';
import '../my stats.dart';
import '../notifcatoin.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
CollectionReference Detabase =
FirebaseFirestore.instance.collection('Detabase');
final Stream<QuerySnapshot> _usersStream =
FirebaseFirestore.instance.collection('Detabase').snapshots();
Stream<QuerySnapshot> getData() {
return Detabase.snapshots();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
centerTitle: true,
title: const Text(
"Home",
style: TextStyle(
color: Colors.black,
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
fontSize: 32),
),
leading: IconButton(
icon: Icon(
Icons.add_business_sharp,
color: Colors.black,
size: 26,
),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => Addingpage()));
},
),
backgroundColor: Colors.white,
actions: [
IconButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => AccountPage()));
},
icon: const Icon(
Icons.account_circle,
),
color: Colors.black,
highlightColor: Colors.transparent,
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
splashColor: Colors.transparent,
)
],
),
body: Container(
padding: EdgeInsets.all(30),
child: StreamBuilder<QuerySnapshot>(
stream: _usersStream,
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return ListView(
children: snapshot.data!.docs.map(
(DocumentSnapshot document) {
Map<String, dynamic>? data =
document.data() as Map<String, dynamic>;
return MovieItem(data[Index] ?? "");
},
).toList(),
);
},
),
),
),
);
}
}
plEASE someone solve this problem it toke me 2 weeks
I am getting error when trying to run in flutter (type ‘String’ is not a subtype of type ‘int’ of ‘index’)
3
Answers
you provided 2 diffrent errors
so yea and the coode looks diffrent at the snippet
Ok so at
you are returning data[index] but if it is null you are returning
""
so
MovieItem("")
you should do it
And what do you get in
snapshot.data
from Firebase? Can you display that data?try add where before map
and ! instead of ??""
like this :
because some of docs items is is null and you cannot replace it with String