How to apply ternary operator on text widget