What is Provider in Flutter?

 Provider is a wrapper around InheritedWidget that helps manage and share app state efficiently.

Example:

class Counter with ChangeNotifier { int count = 0; void increment() { count++; notifyListeners(); // UI refreshes } }

In main:

ChangeNotifierProvider( create: (_) => Counter(), child: MyApp(), );

Use in UI:

Consumer<Counter>( builder: (context, counter, child) => Text('${counter.count}'), );

Comments

Popular posts from this blog

1. What is Flutter?

What is FutureBuilder and StreamBuilder?