How to remove extra space on right side of Text when using TextOverflow.ellipsis

后端 未结 1 999
半阙折子戏
半阙折子戏 2021-01-24 13:26

Here is a code:

import \'package:flutter/material.dart\';

void main() {
  runApp(MaterialApp(home: Home()));
}

class Home extends StatelessWidget {
  @override
         


        
相关标签:
1条回答
  • 2021-01-24 14:18

    Following the Github issue: Text overflow with ellipsis is weird and ugly by design

    Here is a quick fix for it:

    1. The TextOverflow.ellipsis uses a regex pattern \u2026, you can apply a regex pattern[\u{200B}] on the Text data

    Code :

    class Home extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Container(
              width: 200,
              color: Colors.green[200],
              child: Text(
                'https://someurl.com/479247900828929846'.replaceAll("", "\u{200B}"),
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ),
        );
      }
    }
    

    OUTPUT:

    1. Use the flutter package which gives you the ability to do this Assorted Layout Widgets
    0 讨论(0)
提交回复
热议问题