💻
Flutter documentation
  • Flutter documentation
    • Starting an App
    • Import
  • Visual Studio Code
  • Widgets
    • Stateless Widget
    • Stateful Widget
    • Scaffold
    • Text
      • OverFlow
      • Rounded background text
    • Padding
    • Align
    • DraggableScrollableSheet
    • Container
    • Decorated box
    • Expanded
    • IntrinsicHeight
    • IntrinsicWidth
    • ListView.builder(...)
    • Buttons
    • Gauge
    • Navigator
      • WillPopScope
    • Web View
    • Divider
    • Future builder
    • Image
      • Cached_network_image
      • Fade In Image
    • ClipOval
    • InkWell
    • Wrap
    • SingleChildScrollView
    • Stack
    • FittedBox
    • DropdownButton
    • ValueListenableBuilder
    • Maps
    • fl_chart
    • Set SystemNavigation Bar Color
    • Onesignal
    • Builder
    • Set orientation
    • SSE
    • Chat
    • Flutter_animate
    • Supabase
      • Android
    • Changing name and package name
    • Sign apk/abb
  • Dart
    • If / Else in one line
    • Functions
  • Others
  • Airtable
Powered by GitBook
On this page
  1. Widgets

ValueListenableBuilder

Like set state, it changes a widget every time a variable is updated

First, we will declare a variable of type ValueNotifier which is a special type of class.

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

Now in the next step let’s see the widget code.

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

To update the variable, you can do:

_varIndex.value++;
PreviousDropdownButtonNextMaps

Last updated 2 years ago