Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WidgetSpan is not proper align in Flutter

I want to set a black heart between "m" and "ms". and also I want to use "TextAlign.justify". if I use "TextAlign.center" then it's working fine. but if I use "TextAlign.justify" so the black heart is not set in the correct place. If I remove the "WidgetSpan" widget and add "TextSpan" for a black heart so also it's working. but I want to add bottom padding. Please guys help me. Thanks

enter image description here

Text.rich(
              TextSpan(
                children: <InlineSpan>[
                  TextSpan(
                      text: MyString.txtAboutUs ,

                     style: TextStyle(
                          fontSize: FontSize.size14,
                          fontFamily: MyFont.poppins_regular)),
                  TextSpan(
                      text: " m",
                      children: <InlineSpan>[
                        WidgetSpan(
                          baseline: TextBaseline.ideographic,
                            alignment: PlaceholderAlignment.top,
                            child: Container(
                              padding: EdgeInsets.only(bottom: 3),
                              child: Text("🖤", style: TextStyle(
                                  fontSize: FontSize.size8,
                                  fontFamily: MyFont.poppins_regular) ),
                            )
                        ),
                       
                        TextSpan(
                            text: "ms ",
                            style: TextStyle(
                                fontSize: FontSize.size14,
                                fontFamily: MyFont.poppins_medium,
                                color: Colors.black,
                                fontWeight: FontWeight.bold)),
                      ],
                      style: TextStyle(
                          fontSize: FontSize.size14,
                          fontFamily: MyFont.poppins_medium,
                          color: Colors.black,
                          fontWeight: FontWeight.bold)),


                  TextSpan(
                      text: MyString.txtAboutImmediately,

                      style: TextStyle(
                          fontSize: FontSize.size14,
                          fontFamily: MyFont.poppins_regular)),
                ],
              ),
              textAlign: TextAlign.justify,
            ),
like image 373
Alpit Panchal Avatar asked Feb 11 '26 11:02

Alpit Panchal


2 Answers

Try to below simple Text Widget

Text('you add 🖤 here'),
// OR 
Text('you add \u{2764} here} '),

Updated Answer using RichText

Center(
          child: Text.rich(
    TextSpan(
      children: <TextSpan>[
        TextSpan(
          text: 'You add ',
          style: TextStyle(
            fontSize: 10.0,
            color: Colors.black,
          ),
        ),
        TextSpan(
          text: '🖤',
        ),
        TextSpan(
          text: 'Here',
        ),
      ],
    ),
    textAlign: TextAlign.center,
    style: TextStyle(fontSize: 10.0,),
  ),
),

Screen like enter image description here

like image 181
Ravindra S. Patil Avatar answered Feb 14 '26 22:02

Ravindra S. Patil


replace padding with transform.

  WidgetSpan(
                      baseline: TextBaseline.ideographic,
                      alignment: PlaceholderAlignment.top,
                      child: Container(
                        transform: Matrix4.translationValues(0, -3, 0),
                        margin: EdgeInsets.only(bottom: 8),
                        child: Text(
                          "🖤",
                          style: TextStyle(
                              // fontSize: FontSize.size8,
                              // fontFamily: MyFont.poppins_regular,

                              ),
                        ),
                      ),
                    ),
like image 33
Yeasin Sheikh Avatar answered Feb 14 '26 23:02

Yeasin Sheikh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!