0

When i push a new screen onTap with Navigator and pass a new class constructor, how can I have that new screen updates every time _playerTimer updates without having to click again

Since the state of my new class only updates onTap, please help!

The build method of FullScreenDialog is called once since its only being built when onTap is pressed

InkWell(
            onTap: () {
              return Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (BuildContext context) => FullScreenDialog(
                        _playerTimer,
                  ));
            },
            child: VideoPlayer(
                        _controller,)
          );

2 Answers2

0

you have to use setState to rebuild the UI. ex:

setState((){
  _playerTimer = _playerTimer + 1;
});

that's about all the help I can give without seeing the rest of your code

asterisk12
  • 394
  • 2
  • 9
0

When you instantiate a new class (in your code would be the FullScreenDialog) by passing an attribute, you're only saying to your code that a new class will be initialized by using the argument you provided.

If you want your FullScreenDialog class to always be updated when _playerTimer changes, you must observe this attribute inside this class by using setState(), which is a build-in function for StatefulWidgets that makes apps' UI update every time the observable attribute changes.

Example:

setState( () {
  _playerTimer = getUpdatedTimer();
});

Supposing that inside getUpdatedTimer() method you will manage the logic for updating this variable, calling a service or so. If you want this variable to be updated without interacting with interface, you probably will need a timer, too. Check this question to more details about it.

If you're starting with Flutter development, I suggest you to read this article (Adding interactivity to your Flutter app) about state management and setState method documentation.

Hope that helps.