Code:
1.
import 'package:flutter/cupertino.dart';
class Counter with ChangeNotifier{
int num = 1;
increase(){
a ++;
notifyListeners (); // adding listener mode
}
}
2.
void main() {
was counter = Counter ();
var providers = Providers();
providers..provide (Provider <Counter> .value (counter)); // Register notice
runApp(ProviderNode(child: MyApp(),providers: providers,));
}
3.
child: Provide<Counter>(
builder: (context,child,counte){
return Text (// get the data notification
'$ {} Counte.num'
style: Theme.of(context).textTheme.display1,
);
},
)
4.
onPressed: () {// trigger notifications
Provide.value<Counter>(context).increase();
},
to sum up:
Provide state remains similar to OC notice
1. Register notice by the need to maintain the data method
xx is the method name
xx(){
notifyListeners()
}
2. In the main function registration notification method
yy is the name of the object method
There yy = xx ();
was proders Providers = ();
proders..provide(Provide<xx>.value(yy));
runApp(ProviederNode(child:MyApp(),provides:proders));
3. Use the notification data
zz is an arbitrary variable name represents the XX objects
aa is XX variables under
child:Provide<xx>(
builder:(context,child,zz){
return Text(
‘${zz.aa}’
)
}
)
4. trigger notifications
mm is xx method in
onPress:(){
Provide.value<xx>(context).mm;
}