title: How to listen to an integer with Flutter StreamBuilder?
body: <p>I'm adding a dating screen to my app. I want to show the screen according to the progress in the dating screen. I tied the user's progress to a variable. The name of this variable is <code>_pageIndex</code>. And I determine the content to be displayed with the <code>statePage</code> function. I have given <code>statePage</code> to <code>body</code>.</p>
  <p>But there is a problem. I have no clue how to listen for this <code>_pageIndex</code>. How can I do that? Do you want the <code>_pageIndex</code> variable to listen continuously?</p>
  <p><strong>Codes:</strong></p>
  <pre><code>statePage() {
    StreamBuilder&lt;int&gt;(
      // stream: _pageIndex,
      builder: (BuildContext context, AsyncSnapshot&lt;int&gt; snapshot) {
        _pageIndex = snapshot.data;
        if (_pageIndex == 1) {
          return welcomeScreen_1();
        } else if (_pageIndex == 2) {
          return welcomeScreen_2();
        } else if (_pageIndex == 3) {
          return welcomeScreen_3();
        } else {
          return welcomeScreen_1();
        }
      },
    );
  }
  </code></pre>
  <p>All codes:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:teen_browser/welcome_screens/welcomeScreen1.dart';
  import 'package:teen_browser/welcome_screens/welcomeScreen2.dart';
  import 'package:teen_browser/welcome_screens/welcomeScreen3.dart';
  
  class welcomeMain extends StatefulWidget {
    welcomeMain({Key? key}) : super(key: key);
    @override
    State&lt;welcomeMain&gt; createState() =&gt; _welcomeMainState();
  }
  
  int? _pageIndex = 1;
  
  class _welcomeMainState extends State&lt;welcomeMain&gt; {
    void initState() {
      super.initState();
    }
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: statePage(),
        bottomSheet: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            Text(&quot;example text, not important.&quot;),
          ],
        ),
      );
    }
  }
  
  statePage() {
    StreamBuilder&lt;int&gt;(
      // stream: _pageIndex,
      builder: (BuildContext context, AsyncSnapshot&lt;int&gt; snapshot) {
        _pageIndex = snapshot.data;
        if (_pageIndex == 1) {
          return welcomeScreen_1();
        } else if (_pageIndex == 2) {
          return welcomeScreen_2();
        } else if (_pageIndex == 3) {
          return welcomeScreen_3();
        } else {
          return welcomeScreen_1();
        }
      },
    );
  }
  </code></pre>
  <p>I will place a progress bar on the <code>bottomSheet</code>. I can handle this. Just help me how to listen for <code>_pageIndex</code>. Thanks in advance for your help.</p>