1
votes

I am getting english numbers (e.g. 123) as integer, now I want to show it in another language form (e.g. ১২৩).

I used a function and it also worked. But, it doesn't work in same stateful class more than once. It worked for the first Text widget but not for the second one

Column(
 children<Widget>:[
  Text(
   "${convertNumber(123)}"
  ),
  Text(
   "${convertNumber(5630)}"
  )
 ]
)
  String convertNumber(int eng){
    String bengali = '';
    for(int i = 0; i < eng.toString().length; i ++){
      setState(() {
        switch(eng.toString()[i]){
          case '1':
            bengali = bengali + '১';
            break;
          case '2':
            bengali = bengali + '২';
            break;
          case '3':
            bengali = bengali + '৩';
            break;
          case '4':
            bengali = bengali + '৪';
            break;
          case '5':
            bengali = bengali + '৫';
            break;
          case '6':
            bengali = bengali + '৬';
            break;
          case '7':
            bengali = bengali + '৭';
            break;
          case '8':
            bengali = bengali + '৮';
            break;
          case '9':
            bengali = bengali + '৯';
            break;
          default:
            bengali = bengali + '0';
        }
      });
    }
    return bengali;
  }

While I am using it for other numbers in the same stateful class, it doesn't work. And error was :

setState() or markNeedsBuild() called during build This LowerHalf widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase. The widget on which setState() or markNeedsBuild() was called was: LowerHalf

1
I edited the question nowMd.Abdul Halim Rafi

1 Answers

1
votes

Do not call setState inside your convert function, just use your function to get a value.

Widgets rebuild after you call setState function. In your case, build calls setState that triggers build again.