2

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 _pageIndex. And I determine the content to be displayed with the statePage function. I have given statePage to body.

But there is a problem. I have no clue how to listen for this _pageIndex. How can I do that? Do you want the _pageIndex variable to listen continuously?

Codes:

statePage() {
  StreamBuilder<int>(
    // stream: _pageIndex,
    builder: (BuildContext context, AsyncSnapshot<int> 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();
      }
    },
  );
}

All codes:

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<welcomeMain> createState() => _welcomeMainState();
}

int? _pageIndex = 1;

class _welcomeMainState extends State<welcomeMain> {
  void initState() {
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: statePage(),
      bottomSheet: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          Text("example text, not important."),
        ],
      ),
    );
  }
}

statePage() {
  StreamBuilder<int>(
    // stream: _pageIndex,
    builder: (BuildContext context, AsyncSnapshot<int> 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();
      }
    },
  );
}

I will place a progress bar on the bottomSheet. I can handle this. Just help me how to listen for _pageIndex. Thanks in advance for your help.

Emir Bolat
  • 899
  • 3
  • 14
  • 37

0 Answers0