'How to change value from a string function inside of Text widget in Flutter

I want to change the value of Text Widget in Flutter. I have tried to use Stateful Widget and setState() method, it works well when I initialized the String and update the value like this:

String textHolder = "example text" ;

void changeText(){
    setState(() {
      textHolder = 'Resend OTP';
    });
  }

Row buildTimer() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        TweenAnimationBuilder(
          tween: Tween(begin: 120, end: 0.0),
          duration: const Duration(seconds: 120),
          builder: (_, dynamic value, child) => 
         
          Text(
            textHolder, //call the string
            style: const TextStyle(
                decoration: TextDecoration.underline,
                fontSize: fontSmallerSize,
                height: 0.8,
                color: ColorConstants.basicColor,
              ),
          ),
          onEnd: changeText, //update the value
        ),
      ],
    );
  }

In my case I can't use that kind of String, because I have to pass a value inside of the String. Due to that reason, I tried to use String function instead and initialized it like this:

String textHold (double value){
   textHolder = "Resend OTP in " + _minutes(value) + ":" + _seconds(value);
   return textHolder;
}

Because of that, the value of Text Widget doesn't change. How to change the value of Text Widget properly based on my case?. I'm new to Flutter stuffs, any kind of helps would be appreciated.


class _UpdateTextTimerState extends State<UpdateTextTimer> {

  String textHolder = " " ;

  String textHold (double value){
    textHolder = "Resend OTP in " + _minutes(value) + ":" + _seconds(value);
    return textHolder;
  }

  void changeText(){
    setState(() {
      textHolder = 'Resend OTP';
      //print(textHold(0).substring(0,11));
    });
  }

 @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          height: 24,
          child: buildTimer(),
        ),
      ],
    );
  }

   Row buildTimer() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        TweenAnimationBuilder(
          tween: Tween(begin: 120, end: 0.0),
          duration: const Duration(seconds: 120),
          builder: (_, dynamic value, child) => 
         
          Text(
            textHold(value), //this is how do I call my text 
            style: const TextStyle(
                decoration: TextDecoration.underline,
                fontSize: fontSmallerSize,
                height: 0.8,
                color: ColorConstants.basicColor,
              ),
          ),
          onEnd: changeText, //this is how do I change the String when the timer is ended up
        ),
      ],
    );
  }

  String _minutes(double value){
    String mMinute = ((value/60)%60).floor().toString().padLeft(2, '0');
    return mMinute;
  }

  String _seconds(double value){
    String mSeconds = (value % 60).floor().toString().padLeft(2, '0');
    return mSeconds;
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source