### FutureProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/bn_BD/README.md Demonstrates the migration of FutureProvider from version 4.x.x to 5.0.0-nullsafety, highlighting the requirement for 'initialData'. ```dart FutureProvider( create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { final value = context.watch(); return Text('$value'); } ``` ```dart FutureProvider( initialValue: null, create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { // খেয়াল রাখবেন যেন "?" দেওয়া হয়, যেমনঃ context.watch(); return Text('$value'); } ``` -------------------------------- ### FutureProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Demonstrates the migration of FutureProvider from version 4.x.x to 5.0.0-nullsafety, highlighting the requirement for initialData. ```dart FutureProvider( create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { final value = context.watch(); return Text('$value'); } ``` ```dart FutureProvider( initialValue: null, create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { // ? ile işaretlendiğine emin ol watch final value = context.watch(); return Text('$value'); } ``` -------------------------------- ### ValueListenableProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/bn_BD/README.md Shows how to migrate from ValueListenableProvider by using Provider with ValueListenableBuilder. ```dart ValueListenableBuilder( valueListenable: myValueListenable, builder: (context, value, _) { return Provider.value( value: value, child: MyApp(), ); } ) ``` -------------------------------- ### ValueListenableProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md Shows how to migrate from ValueListenableProvider to using Provider with ValueListenableBuilder, as ValueListenableProvider has been removed in newer versions. ```dart ValueListenableBuilder( valueListenable: myValueListenable, builder: (context, value, _) { return Provider.value( value: value, child: MyApp(), ); } ) ``` -------------------------------- ### ValueListenableProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/fr_FR/README.md Shows how to migrate from the removed ValueListenableProvider by using Provider with ValueListenableBuilder. ```dart ValueListenableBuilder( valueListenable: myValueListenable, builder: (context, value, _) { return Provider.value( value: value, child: MyApp(), ); } ) ``` -------------------------------- ### FutureProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/fr_FR/README.md Demonstrates the migration of FutureProvider from version 4.x.x to 5.0.0-nullsafety, highlighting the change in handling initial data and type hinting. ```dart FutureProvider( create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { final value = context.watch(); return Text('$value'); } ``` ```dart FutureProvider( initialValue: null, create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { // be sure to specify the ? in watch final value = context.watch(); return Text('$value'); } ``` -------------------------------- ### FutureProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/pt_br/README.md Demonstrates the migration of FutureProvider from provider v4.x.x to v5.0.0-nullsafety, highlighting the mandatory 'initialData' parameter and the need for null safety. ```dart FutureProvider( create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { final value = context.watch(); return Text('$value'); } ``` ```dart FutureProvider( initialValue: null, create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { // be sure to specify the ? in watch final value = context.watch(); return Text('$value'); } ``` -------------------------------- ### Phased Provider Loading Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md Demonstrates how to load providers in stages to prevent StackOverflowErrors, especially during application startup or splash screens. This approach helps manage the build process by deferring the creation of some widgets. ```dart MultiProvider( providers: [ if (step1) ...[ , ], if (step2) ...[ ] ], ) ``` ```dart bool step1 = false; bool step2 = false; @override initState() { super.initState(); Future(() { setState(() => step1 = true); Future(() { setState(() => step2 = true); }); }); } ``` -------------------------------- ### FutureProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md Demonstrates the migration of FutureProvider from version 4.x.x to 5.0.0-nullsafety, highlighting the change in handling initial data and the need for null safety. ```dart FutureProvider( create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { final value = context.watch(); return Text('$value'); } ``` ```dart FutureProvider( initialValue: null, create: (context) => Future.value(42), child: MyApp(), ) Widget build(BuildContext context) { // assicurati di specificare ? in watch final value = context.watch(); return Text('$value'); } ``` -------------------------------- ### Counter Example with Provider.value Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md Demonstrates how to manage a counter's state using StatefulWidget and Provider.value. It shows how to provide the state (int) and the state object (ExampleState) down the widget tree, and how to consume and modify the state using context.watch and context.read. ```dart class Example extends StatefulWidget { const Example({Key key, this.child}) : super(key: key); final Widget child; @override ExampleState createState() => ExampleState(); } class ExampleState extends State { int _count; void increment() { setState(() { _count++; }); } @override Widget build(BuildContext context) { return Provider.value( value: _count, child: Provider.value( value: this, child: widget.child, ), ); } } // Reading the state: // return Text(context.watch().toString()); // Modifying the state: // return FloatingActionButton( // onPressed: () => context.read().increment(), // child: Icon(Icons.plus_one), // ); ``` -------------------------------- ### ProxyProvider Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Illustrates how to use ProxyProvider to create a new provider (`Translations`) that depends on and listens to changes in another provider (`Counter`). ```dart Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => Counter()), ProxyProvider( update: (_, counter, __) => Translations(counter.value), ), ], child: Foo(), ); } class Translations { const Translations(this._value); final int _value; String get title => 'You clicked $_value times'; } ``` -------------------------------- ### ValueListenableProvider Migration Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/pt_br/README.md Shows how to migrate from ValueListenableProvider to using Provider with ValueListenableBuilder, a common pattern for managing mutable state in Flutter. ```dart ValueListenableBuilder( valueListenable: myValueListenable, builder: (context, value, _) { return Provider.value( value: value, child: MyApp(), ); } ) ``` -------------------------------- ### Consuming Interface with Implementation Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/bn_BD/README.md Provides an example of how to consume an abstract interface while providing a concrete implementation using `ChangeNotifierProvider`. This requires a type hint to the compiler. ```dart abstract class ProviderInterface with ChangeNotifier { ... } class ProviderImplementation with ChangeNotifier implements ProviderInterface { ... } class Foo extends StatelessWidget { @override build(context) { final provider = Provider.of(context); return ... } } ChangeNotifierProvider( create: (_) => ProviderImplementation(), child: Foo(), ), ``` -------------------------------- ### Handling Provider Access in initState Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/bn_BD/README.md This example illustrates how to correctly access providers within the `initState` method to avoid exceptions. It shows how to use `context.watch` and `context.read` appropriately, and how to handle state changes by comparing values or using `Future.microtask`. ```dart Value value; Widget build(BuildContext context) { final value = context.watch().value; if (value != this.value) { this.value = value; print(value); } } ``` ```dart initState() { super.initState(); print(context.read().value); } ``` -------------------------------- ### ProxyProvider Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md Illustrates the use of ProxyProvider to combine values from other providers into a new object. The new object is updated whenever the dependent providers change. This example shows creating Translations based on a Counter. ```dart Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => Counter()), ProxyProvider( update: (_, counter, __) => Translations(counter.value), ), ], child: Foo(), ); } class Translations { const Translations(this._value); final int _value; String get title => 'You clicked $_value times'; } ``` -------------------------------- ### ProxyProvider Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/es_MX/README.md An example of using ProxyProvider to combine a Counter value from one provider to create a Translations object for another provider. The Translations object updates when the Counter changes. ```dart Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => Counter()), ProxyProvider( update: (_, counter, __) => Translations(counter.value), ), ], child: Foo(), ); } class Translations { const Translations(this._value); final int _value; String get title => 'You clicked $_value times'; } ``` -------------------------------- ### State Management with StatefulWidget and Provider.value Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Demonstrates how to manage state using a StatefulWidget combined with Provider.value. This example shows how to increment a counter and provide the state and the state management class to the widget tree. ```dart class Example extends StatefulWidget { const Example({Key key, this.child}) : super(key: key); final Widget child; @override ExampleState createState() => ExampleState(); } class ExampleState extends State { int _count; void increment() { setState(() { _count++; }); } @override Widget build(BuildContext context) { return Provider.value( value: _count, child: Provider.value( value: this, child: widget.child, ), ); } } ``` -------------------------------- ### Counter Example with Provider.value Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/fr_FR/README.md Demonstrates how to use Provider.value to manage state within a StatefulWidget. It shows how to provide the state (an integer count) and the state management class itself, allowing child widgets to read and modify the state. ```dart class Example extends StatefulWidget { const Example({Key key, this.child}) : super(key: key); final Widget child; @override ExampleState createState() => ExampleState(); } class ExampleState extends State { int _count; void increment() { setState(() { _count++; }); } @override Widget build(BuildContext context) { return Provider.value( value: _count, child: Provider.value( value: this, child: widget.child, ), ); } } ``` -------------------------------- ### Using StatefulWidget with Provider.value Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ja_JP/README.md An example of managing state using a StatefulWidget and providing values down the widget tree using Provider.value. It shows how to read and update the state. ```dart class Example extends StatefulWidget { const Example({Key key, this.child}) : super(key: key); final Widget child; @override ExampleState createState() => ExampleState(); } class ExampleState extends State { int _count; void increment() { setState(() { _count++; }); } @override Widget build(BuildContext context) { return Provider.value( value: _count, child: Provider.value( value: this, child: widget.child, ), ); } } ``` ```dart return Text(context.watch().toString()); ``` ```dart return FloatingActionButton( onPressed: () => context.read().increment(), child: Icon(Icons.plus_one), ); ``` -------------------------------- ### ProxyProvider Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ja_JP/README.md Demonstrates how to use ProxyProvider to combine values from multiple providers to create a new object. The new object is updated whenever any of the dependent providers change. ```dart Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => Counter()), ProxyProvider( update: (_, counter, __) => Translations(counter.value), ), ], child: Foo(), ); } class Translations { const Translations(this._value); final int _value; String get title => 'You clicked $_value times'; } ``` -------------------------------- ### ProxyProvider Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/pt_br/README.md Demonstrates how to use ProxyProvider to combine multiple providers into a new object. The Translations object is updated when the Counter provider changes. ```dart Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => Counter()), ProxyProvider( update: (_, counter, __) => Translations(counter.value), ), ], child: Foo(), ); } class Translations { const Translations(this._value); final int _value; String get title => 'You clicked $_value times'; } ``` -------------------------------- ### Handling Providers in Lifecycle Methods Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ko-KR/README.md This example shows how to correctly access providers within lifecycle methods like initState. It contrasts an incorrect approach that causes exceptions with a correct approach using context.watch or context.read to avoid issues related to the widget lifecycle. ```dart initState() { super.initState(); print(context.watch().value); } ``` ```dart Value value; Widget build(BuildContext context) { final value = context.watch().value; if (value != this.value) { this.value = value; print(value); } } ``` ```dart initState() { super.initState(); print(context.read().value); } ``` -------------------------------- ### Creating Custom Providers Source: https://github.com/rrousselgit/provider/blob/master/packages/provider/README.md Highlights the components exposed by the provider package for creating custom providers, such as SingleChildStatelessWidget and InheritedProvider, with a link to a ValueNotifier example. ```dart # Provider exposes all the small components that make a fully-fledged provider. # # - SingleChildStatelessWidget, to make any widget works with MultiProvider. # This interface is exposed as part of `package:provider/single_child_widget` # # - [InheritedProvider], the generic `InheritedWidget` obtained when doing `context.watch`. # # Here's an example of a custom provider to use `ValueNotifier` as the state: # https://gist.github.com/rrousselGit/4910f3125e41600df3c2577e26967c91 ``` -------------------------------- ### ProxyProvider Example Source: https://github.com/rrousselgit/provider/blob/master/packages/provider/README.md Shows how to use ProxyProvider to combine values from a Counter provider into a Translations object. The Translations object updates automatically when the Counter changes. ```dart Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => Counter()), ProxyProvider( update: (_, counter, __) => Translations(counter.value), ), ], child: Foo(), ); } class Translations { const Translations(this._value); final int _value; String get title => 'You clicked $_value times'; } ``` -------------------------------- ### Creating Custom Providers Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/zh-CN/README.md Details how the provider package exposes components for building custom providers, including SingleChildStatelessWidget and InheritedProvider. It also links to an example of a custom provider using ValueNotifier. ```dart // Example link: https://gist.github.com/rrousselGit/4910f3125e41600df3c2577e26967c91 ``` -------------------------------- ### Creating Custom Providers Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ko-KR/README.md This section explains that the provider package exposes components for building custom providers. It mentions SingleChildStatelessWidget for integration with MultiProvider and InheritedProvider for use with context.watch, and provides a link to an example of a custom provider using ValueNotifier. ```dart https://gist.github.com/rrousselGit/4910f3125e41600df3c2577e26967c91 ``` -------------------------------- ### Accessing Providers in initState Safely Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md This example shows how to safely access providers within the initState method. It contrasts an incorrect approach that listens to providers in initState with correct alternatives using the build method or context.read for one-time access, preventing lifecycle issues. ```dart initState() { super.initState(); print(context.watch().value); } ``` ```dart Value value; Widget build(BuildContext context) { final value = context.watch().value; if (value != this.value) { this.value = value; print(value); } } ``` ```dart initState() { super.initState(); print(context.read().value); } ``` -------------------------------- ### Using StatefulWidget and Provider.value for Complex State Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ko-KR/README.md This example illustrates an alternative to ChangeNotifier for managing complex state by combining StatefulWidget with Provider.value. It shows how to expose state and methods to the widget tree, allowing for state reading and modification. ```dart class Example extends StatefulWidget { const Example({Key key, this.child}) : super(key: key); final Widget child; @override ExampleState createState() => ExampleState(); } class ExampleState extends State { int _count; void increment() { setState(() { _count++; }); } @override Widget build(BuildContext context) { return Provider.value( value: _count, child: Provider.value( value: this, child: widget.child, ), ); } } ``` ```dart return Text(context.watch().toString()); ``` ```dart return FloatingActionButton( onPressed: () => context.read().increment(), child: Icon(Icons.plus_one), ); ``` -------------------------------- ### Accessing Providers in initState Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md This example illustrates how to correctly access providers within the initState method to avoid exceptions. It shows using context.watch for reactive updates or context.read for a one-time read, preventing issues with the widget lifecycle. ```dart initState() { super.initState(); print(context.read().value); } ``` -------------------------------- ### Reading Values from the Widget Tree Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/es_MX/README.md Details the methods available for reading provider values within the widget tree: `context.watch()`, `context.read()`, `context.select()`, and `Provider.of(context)`. It explains their behavior regarding listening to changes and provides an example of reading a String value. ```dart class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Text( // Don't forget to pass the type of the object you want to obtain to `watch`! context.watch(), ); } } ``` -------------------------------- ### Exposing a New Object Instance (Recommended) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/zh-CN/README.md Demonstrates the recommended way to expose a newly created object instance using the `create` constructor. This ensures proper lifecycle management and avoids unexpected side effects. ```dart Provider( create: (_) => MyModel(), child: ... ) ``` -------------------------------- ### Modifying State with context.read Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Demonstrates how to modify state using context.read in Flutter. This example triggers an increment function on a state object. ```dart return FloatingActionButton( onPressed: () => context.read().increment(), child: Icon(Icons.plus_one), ); ``` -------------------------------- ### Veri Okuma (context.read) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Veriyi okumak ancak dinlememek için `context.read()` kullanılır. Bu işlem widget rebuild'ını tetiklemez ve `build` metodu dışında kullanılmalıdır. ```dart // context.read() örneği (build metodu dışında kullanılmalı) ``` -------------------------------- ### Listening to State with context.watch Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Shows how to listen to state changes using context.watch in Flutter. This example displays the current value of an integer state. ```dart return Text(context.watch().toString()); ``` -------------------------------- ### Yeni Obje Oluşturma (Doğru Yöntem) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Provider ile yeni bir obje örneğini expose etmek için `create` metodu kullanılmalıdır. Bu, objenin yaşam döngüsünü doğru yönetir. ```dart Provider( create: (_) => MyModel(), child: ... ) ``` -------------------------------- ### Mevcut Instance Yeniden Kullanma (Doğru Yöntem) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Halihazırda bir obje instance'ına sahipseniz ve onu yeniden kullanmak istiyorsanız, `ChangeNotifierProvider.value` kullanılmalıdır. ```dart MyChangeNotifier variable; ChangeNotifierProvider.value( value: variable, child: ... ) ``` -------------------------------- ### Exposing a New Object Instance Source: https://github.com/rrousselgit/provider/blob/master/packages/provider/README.md Demonstrates the correct way to expose a newly created object instance using the default constructor of a provider. It highlights the importance of using `create` over `value` for new object creation to avoid side effects and explains how to pass changing variables using `ProxyProvider`. ```dart Provider( create: (_) => MyModel(), child: ... ) ``` ```dart ChangeNotifierProvider.value( value: MyModel(), child: ... ) ``` ```dart int count; Provider( create: (_) => MyModel(count), child: ... ) ``` ```dart int count; ProxyProvider0( update: (_, __) => MyModel(count), child: ... ) ``` ```dart MyProvider( create: (_) => Something(), lazy: false, ) ``` -------------------------------- ### Veri Dinleme (context.watch) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Widget'ların veri değişimlerini dinlemesi için `context.watch()` kullanılır. Bu, ilgili widget'ın yeniden oluşturulmasını tetikler. ```dart class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Text( // "watch" işlemi ile elde etmek istediğiniz objenin tipini belirtmeyi unutmayın! context.watch(), ); } } ``` -------------------------------- ### Nested Providers vs. MultiProvider Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/es_MX/README.md Demonstrates how to refactor deeply nested Providers into a more readable structure using MultiProvider. Both examples achieve the same functionality. ```dart Provider( create: (_) => Something(), child: Provider( create: (_) => SomethingElse(), child: Provider( create: (_) => AnotherThing(), child: someWidget, ), ), ), ``` ```dart MultiProvider( providers: [ Provider(create: (_) => Something()), Provider(create: (_) => SomethingElse()), Provider(create: (_) => AnotherThing()), ], child: someWidget, ) ``` -------------------------------- ### Mevcut Instance Yeniden Kullanma (Yanlış Yöntem) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md `ChangeNotifierProvider` ile zaten çağrılmış bir veriyi kullanmak, `dispose` metodunun yanlış tetiklenmesine neden olabilir. ```dart MyChangeNotifier variable; ChangeNotifierProvider( create: (_) => variable, child: ... ) ``` -------------------------------- ### Exposing a New Object Instance Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md Demonstrates how to expose a newly created object instance using the default constructor of a Provider. It highlights the importance of using `create` and avoiding `.value` for new object creation to prevent side effects. ```dart Provider( create: (_) => MyModel(), child: ... ) ``` -------------------------------- ### ProxyProvider Example Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/bn_BD/README.md Illustrates the use of ProxyProvider to combine values from other providers into a new object. The new object is updated whenever any of the dependent providers change. ```dart Widget build(BuildContext context) { return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => Counter()), ProxyProvider( update: (_, counter, __) => Translations(counter.value), ), ], child: Foo(), ); } class Translations { const Translations(this._value); final int _value; String get title => 'You clicked $_value times'; } ``` -------------------------------- ### Using MultiProvider for Multiple Providers Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/pt_br/README.md Illustrates how to use `MultiProvider` to simplify the management of multiple nested providers, making the widget tree cleaner and more readable. ```dart MultiProvider( providers: [ Provider(create: (_) => Something()), Provider(create: (_) => SomethingElse()), Provider(create: (_) => AnotherThing()), ], child: someWidget, ) ``` -------------------------------- ### Exposing a New Object Instance Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/bn_BD/README.md Demonstrates how to expose a new object instance using the default constructor of a Provider. It emphasizes not using the `.value` constructor for creation to avoid side effects and shows the correct way to create an object within the `create` callback. ```dart Provider( create: (_) => MyModel(), child: ... ) ``` -------------------------------- ### Veri Dinleme (context.select) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Verinin sadece belirli bir kısmı için dinleme yapmak üzere `context.select(R cb(T value))` kullanılır. Bu, gereksiz widget rebuild'larını önler. ```dart // context.select(R cb(T value)) örneği ``` -------------------------------- ### Exposing a New Object Instance Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/es_MX/README.md Demonstrates how to expose a newly created object using the default constructor of a provider. It emphasizes using `create` over `.value` for new objects to avoid side effects and shows how to handle mutable variables with `ProxyProvider0`. ```dart Provider( create: (_) => MyModel(), child: ... ) ``` ```dart ChangeNotifierProvider.value( value: MyModel(), child: ... ) ``` ```dart int count; ProxyProvider0( update: (_, __) => MyModel(count), child: ... ) ``` ```dart MyProvider( create: (_) => Something(), lazy: false, ) ``` -------------------------------- ### Customizing Object Inspection with DiagnosticableTreeMixin Source: https://github.com/rrousselgit/provider/blob/master/packages/provider/README.md Provides an example of implementing DiagnosticableTreeMixin and debugFillProperties to enhance the visibility of custom objects in Flutter DevTools. This allows for detailed inspection of object properties. ```dart class MyClass with DiagnosticableTreeMixin { MyClass({this.a, this.b}); final int a; final String b; @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(IntProperty('a', a)); properties.add(StringProperty('b', b)); } } ``` -------------------------------- ### Veri Dinleme (Provider.of) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md `Provider.of(context)` static metodu da dinleme için kullanılabilir. `listen: false` ile `read` işlemi gibi davranır. ```dart // Provider.of(context, listen: false) örneği ``` -------------------------------- ### Interface Consumption and Implementation Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/pt_br/README.md Demonstrates how to consume an interface and provide its implementation using `ChangeNotifierProvider`. It shows the definition of an abstract provider interface, its concrete implementation, and how to access it within a widget using `Provider.of`. ```dart abstract class ProviderInterface with ChangeNotifier { // ... } class ProviderImplementation with ChangeNotifier implements ProviderInterface { // ... } class Foo extends StatelessWidget { @override build(context) { final provider = Provider.of(context); return ... } } ChangeNotifierProvider( create: (_) => ProviderImplementation(), child: Foo(), ), ``` -------------------------------- ### Implementing Hot-Reload with ReassembleHandler Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md This snippet demonstrates how to make custom objects hot-reloadable by implementing the ReassembleHandler interface and its reassemble method. It shows the typical provider setup required to integrate this functionality. ```dart class Example extends ChangeNotifier implements ReassembleHandler { @override void reassemble() { print('Did hot-reload'); } } ChangeNotifierProvider(create: (_) => Example()), ``` -------------------------------- ### Reading Values with Context Extensions Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ko-KR/README.md Illustrates how to read values from the provider tree using `context.watch()`, `context.read()`, and `context.select()`. It also mentions the static `Provider.of(context)` method and the `listen` parameter. ```dart class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Text( // Don't forget to pass the type of the object you want to obtain to `watch`! context.watch(), ); } } ``` -------------------------------- ### Updating ChangeNotifier Asynchronously Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md This example addresses exceptions that occur when updating a ChangeNotifier from a descendant widget during the build phase. It suggests using Future.microtask to defer the update until after the current frame, ensuring state consistency. ```dart initState() { super.initState(); Future.microtask(() => context.read().fetchSomething(someValue); ); } ``` -------------------------------- ### Consuming Interfaces with Provider Implementations Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/zh-CN/README.md Shows how to provide an implementation of an abstract class (interface) and consume it using the interface type. This requires type hints for the consumer and providing the concrete implementation in the `create` method of the provider. ```dart abstract class ProviderInterface with ChangeNotifier { ... } class ProviderImplementation with ChangeNotifier implements ProviderInterface { ... } class Foo extends StatelessWidget { @override build(context) { final provider = Provider.of(context); return ... } } ChangeNotifierProvider( create: (_) => ProviderImplementation(), child: Foo(), ) ``` -------------------------------- ### Simplifying Nested Providers with MultiProvider Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ja_JP/README.md Illustrates how `MultiProvider` can be used to simplify the management of multiple nested providers, making the widget tree more readable and maintainable compared to deep nesting. ```dart MultiProvider( providers: [ Provider(create: (_) => Something()), Provider(create: (_) => SomethingElse()), Provider(create: (_) => AnotherThing()), ], child: someWidget, ) ``` -------------------------------- ### Creating Objects from Stable Variables Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ja_JP/README.md Shows an example of creating an object with a variable that is not expected to change frequently. It warns against using frequently changing variables directly in `create` as it won't update the object's state. ```dart int count; Provider( create: (_) => MyModel(count), child: ... ) ``` -------------------------------- ### Exposing New Object Instances Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ko-KR/README.md Demonstrates how to expose newly created object instances using the default constructor of a provider. It emphasizes not using the `.value` constructor for creating new objects to avoid unintended side effects. ```dart Provider( create: (_) => MyModel(), child: ... ) ``` ```dart ChangeNotifierProvider.value( value: MyModel(), child: ... ) ``` ```dart int count; Provider( create: (_) => MyModel(count), child: ... ) ``` ```dart int count; ProxyProvider0( update: (_, __) => MyModel(count), child: ... ) ``` ```dart MyProvider( create: (_) => Something(), lazy: false, ) ``` -------------------------------- ### Providing an Interface with Implementation Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/it_IT/README.md Demonstrates how to provide an implementation of an abstract class (interface) using ChangeNotifierProvider. This allows widgets to depend on the interface while receiving a concrete implementation. ```dart abstract class ProviderInterface with ChangeNotifier { // ... } class ProviderImplementation with ChangeNotifier implements ProviderInterface { // ... } class Foo extends StatelessWidget { @override build(context) { final provider = Provider.of(context); return ... } } ChangeNotifierProvider( create: (_) => ProviderImplementation(), child: Foo(), ), ``` -------------------------------- ### Handling Optional Dependencies Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ko-KR/README.md Shows how to handle cases where a provider might not exist by using nullable types with `context.watch` or `context.read`. This prevents `ProviderNotFoundException` and returns `null` instead. ```dart context.watch() // Throws ProviderNotFoundException if Model is not found context.watch() // Returns null if Model is not found ``` -------------------------------- ### Using MultiProvider for Nested Providers Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ko-KR/README.md Demonstrates how `MultiProvider` simplifies the management of multiple nested `Provider` widgets by allowing them to be declared in a list. ```dart Provider( create: (_) => Something(), child: Provider( create: (_) => SomethingElse(), child: Provider( create: (_) => AnotherThing(), child: someWidget, ), ), ), ``` ```dart MultiProvider( providers: [ Provider(create: (_) => Something()), Provider(create: (_) => SomethingElse()), Provider(create: (_) => AnotherThing()), ], child: someWidget, ) ``` -------------------------------- ### Consuming an Interface with its Implementation Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/es_MX/README.md Demonstrates how to consume an abstract interface while providing its concrete implementation. This involves using `ChangeNotifierProvider` with the interface type and providing an instance of the implementation. ```dart abstract class ProviderInterface with ChangeNotifier { ... } class ProviderImplementation with ChangeNotifier implements ProviderInterface { ... } class Foo extends StatelessWidget { @override build(context) { final provider = Provider.of(context); return ... } } ChangeNotifierProvider( create: (_) => ProviderImplementation(), child: Foo(), ) ``` -------------------------------- ### Asynchronous State Updates with ChangeNotifier Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/bn_BD/README.md This example addresses exceptions that occur when updating a `ChangeNotifier` during the widget tree build phase. It provides two solutions: performing mutations within the provider's `create` method or deferring them to the end of the frame using `Future.microtask`. ```dart class MyNotifier with ChangeNotifier { MyNotifier() { _fetchSomething(); } Future _fetchSomething() async {} } ``` ```dart initState() { super.initState(); Future.microtask(() => context.read().fetchSomething(someValue); ); } ``` -------------------------------- ### Değişkenlere Dayalı Obje Oluşturma (Yanlış Yöntem) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Zamanla değişebilecek değişkenlere dayalı obje oluşturmak, verilerin güncellenmemesine neden olur. Bu durumda `ProxyProvider` tercih edilmelidir. ```dart int count; Provider( create: (_) => MyModel(count), child: ... ) ``` -------------------------------- ### Using StatefulWidget with Provider.value for State Management Source: https://github.com/rrousselgit/provider/blob/master/packages/provider/README.md Demonstrates an alternative architecture using StatefulWidget and Provider.value to manage state, including reading and modifying state. ```dart class Example extends StatefulWidget { const Example({Key key, this.child}) : super(key: key); final Widget child; @override ExampleState createState() => ExampleState(); } class ExampleState extends State { int _count; void increment() { setState(() { _count++; }); } @override Widget build(BuildContext context) { return Provider.value( value: _count, child: Provider.value( value: this, child: widget.child, ), ); } } return Text(context.watch().toString()); return FloatingActionButton( onPressed: () => context.read().increment(), child: Icon(Icons.plus_one), ); ``` -------------------------------- ### Creating New Objects with Provider Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/ja_JP/README.md Demonstrates the correct way to create and expose a new object instance using the default Provider constructor. It emphasizes avoiding `.value` for new object creation to prevent unexpected side effects and highlights the importance of creating objects within the `create` callback. ```dart Provider( create: (_) => MyModel(), child: ... ) ``` -------------------------------- ### Yeni Obje Oluşturma (Yanlış Yöntem) Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md `Provider.value` constructor'ı yeni obje oluşturmak için kullanılmamalıdır. Bu, istenmeyen yan etkilere yol açabilir. ```dart ChangeNotifierProvider.value( value: MyModel(), child: ... ) ``` -------------------------------- ### Lazy Yükleme Kontrolü Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/tr_TR/README.md Provider'ın `create`/`update` callback'leri varsayılan olarak lazydir. Bu davranışı değiştirmek için `lazy: false` parametresi kullanılabilir. ```dart MyProvider( create: (_) => Something(), lazy: false, ) ``` -------------------------------- ### Creating a New Object with Provider Source: https://github.com/rrousselgit/provider/blob/master/resources/translations/fr_FR/README.md Demonstrates the correct way to create and expose a new object instance using the `create` constructor of a Provider. Avoid using `Provider.value` for creation to prevent unintended side effects. ```dart Provider( create: (_) => MyModel(), child: ... ) ```