Skip to content

Handling state in a widget needs it extends StatefulWidget But if you want to get notified of state changes in a StatelessWidget, you can use ValueNotifier

License

Notifications You must be signed in to change notification settings

abbasghomi/flutter-state-in-stateless-widget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

State in StateLess widget

in Flutter

Handling state in a widget needs it extends StatefulWidget But if you want to get notified of state changes in a StatelessWidget, you can use ValueNotifier

ValueNotifier definition

final ValueNotifier<int> _counter = ValueNotifier<int>(0);

and using this ValueNotifier in widget tree

ValueListenableBuilder(
    valueListenable: _counter,
    builder: (context, _, __) {
      return Text(
        '${_counter.value}',
        style: Theme.of(context).textTheme.headline4,
      );
    }),

About

Handling state in a widget needs it extends StatefulWidget But if you want to get notified of state changes in a StatelessWidget, you can use ValueNotifier

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published