skip to Main Content

I want to make the word Capital UNDERLINE here. How can we do that in String.

QuestionCategory(question: 'What is the Capital of India?', correctAnswer: 'Delhi'),

2

Answers


  1. I think you can do it in two ways. First, you can use underline text generator websites to generate the underlined version of the word ‘Capital’ and paste it into your string.

    String question = 'What is the C͟a͟p͟i͟t͟a͟l͟ of India?';
    

    Second, you can use RichText. Split the string into multiple Text widgets and give the ‘Capital’ text a style with TextDecoration.underline.

    RichText(
          text: const TextSpan(
        text: 'What is the ',
        style: TextStyle(color: Colors.black),
        children: [
          TextSpan(
              text: 'Capital',
              style: TextStyle(decoration: TextDecoration.underline)),
          TextSpan(text: ' of India?')
        ],
      )),
    
    Login or Signup to reply.
  2. You can use Text.rich or RichText for this:

    Text.rich:

    Text.rich(
      TextSpan(
        text: 'What is the ',
        children: <TextSpan>[
          TextSpan(
            text: 'Capital ',
            style: TextStyle(decoration: TextDecoration.underline),
          ),
          TextSpan(text: 'of India?'),
        ],
      ),
    )
    

    RichText:

    RichText(
      text: TextSpan(
        text: 'What is the ',
        children: <TextSpan>[
          TextSpan(
            text: 'Capital ',
            style: TextStyle(decoration: TextDecoration.underline),
          ),
          TextSpan(text: 'of India?'),
        ],
      ),
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search