Search code examples
flutterfirebasegoogle-cloud-firestoredart-null-safety

The argument type 'Null' can't be assigned to the parameter type 'QuerySnapshot<Object?>'


import 'package:brew_crew/services/auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:brew_crew/services/database.dart';

class Home extends StatelessWidget {
  final AuthService _auth = AuthService();

  @override
  Widget build(BuildContext context) {
    return StreamProvider<QuerySnapshot>.value(
      value: DatabaseService(uid: '').brews,
      initialData: (null),
      child: Scaffold(
        backgroundColor: Colors.brown[50],
        appBar: AppBar(
          title: Text('Brew Crew'),
          backgroundColor: Colors.brown[400],
          elevation: 0.0,
          actions: <Widget>[
            TextButton.icon(
              icon: Icon(Icons.person),
              label: Text('logout'),
              onPressed: () async {
                await _auth.signOut();
              },
            )
          ],
        ),
      ),
    );
  }
}

Why am I getting this error???

The argument type 'Null' can't be assigned to the parameter type 'QuerySnapshot<Object?>'

How do I get rid of this?


Solution

  • It StreamProvider<QuerySnapshot> doesnt accept nullable data. You can make it nullable like

     StreamProvider<QuerySnapshot?>
    

    More about null-safety