MultiProvider sending NULL in child widgets but prints right value in Console


My HomePagewhere Providers are initilized:

Widget build(BuildContext context) {
    return SafeArea(
      child: MultiProvider(
        providers: [
          ChangeNotifierProvider<EmailAuth>(create: (context) => EmailAuth()),
        child: Scaffold(
          resizeToAvoidBottomInset: true,
          floatingActionButton: FloatingActionButton(.....

My Authentication function that is triggered when user logs-in (Firebase)

class EmailAuth extends ChangeNotifier {
  final _auth = FirebaseAuth.instance;
  final dbRef = FirebaseFirestore.instance.collection("users");
  String userid;
  Future signIn({String email, String password}) async {
    final currentUser = await _auth.signInWithEmailAndPassword(
        email: email, password: password);
    if (currentUser != null) {
      userid = _auth.currentUser.uid;
    } else {
      print("something didn't work");
    return userid;

This is how my Consumer is setup in the HomePage – AppBar

 title: Consumer<EmailAuth>(
                    builder: (context, data, child) => Text(
                      style: TextStyle(color: Colors.indigoAccent),

But the output on AppBar is NULL. What am I doing wrong?!

I have been using this as reference for implementation:


Something similar was a known error in the older Provider Package. Please update to latest and check if the issue is still there. However,

This is how a MultiProvider should look like:

  Widget build(BuildContext context) {
    return MultiProvider( //                                     <--- MultiProvider
      providers: [
        ChangeNotifierProvider<MyModel>(create: (context) => MyModel()),
        ChangeNotifierProvider<AnotherModel>(create: (context) => AnotherModel()),

And should be consumed like this

child: Consumer<MyModel>( //            <--- MyModel Consumer
                        builder: (context, myModel, child) {
                          return RaisedButton(
                            child: Text('Do something'),
                            onPressed: (){
                              // We have access to the model.

class MyModel with ChangeNotifier { //                        <--- MyModel
  String someValue = 'Hello';
  void doSomething() {
    someValue = 'Goodbye';


Answered By – Firaun

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *