0

This is from: https://firebase.google.com/codelabs/firebase-get-to-know-flutter#1

void main() {
  runApp(
    ChangeNotifierProvider(
      create: (context) => ApplicationState(),
      builder: (context, _) => App(),
    ),
  );
}

That's flutter's website so I thought code is trustworthy which means perhaps create and builder both are required.

This answer: https://stackoverflow.com/a/59101137/462608. says that builder is depreciated and create should be used instead.

But the above code is using create and builder both. What is the use of this builder here when create is also there? How are builder and create different from each other?

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411

1 Answers1

1

yeah, there big difference between create and builder

  • create : if you want to instantiate you notifier you should use create but if you notifier already instantiate you don't need use create simply use ChangeNotifierProvider.value

  • builder : usefull if you have some condition to show specific widget for example if in your logic you need tp choose between 2 widget to be showen you will use builder and you passe it child it's the static widget

ChangeNotifierProvider(
      create: (context) => ApplicationState(),
      builder: (context, child){
           if(condition){
             return SomeWidget();
           }
          return child;
      },
     child:App(),
    )

except that no need for builder

Dali Hamza
  • 568
  • 1
  • 4
  • 8