'AutoSizeText with Marquee - How can the text be scrolled instead of being resized?

enter image description here

 AutoSizeText(
    Dummy.locations[index]['name'],
    maxLines: 1,
    overflowReplacement: Marquee(
       scrollAxis: Axis.horizontal,
       velocity: 5,
       text: Dummy.locations[index]['name'],
       style: const TextStyle(fontSize: 18, color: Colors.white)),
    style: const TextStyle(fontSize: 18, color: Colors.white),),    

The AutoSizeText widget does not replace to Marquee if the text is overflowed.



Solution 1:[1]

I just found out and to someone who needs, we just need to do the following things:

  • Specify the minFontSize property of AutoSizeText
  • Wrap Marquee widget with a width and height specified Container or SizedBox as the code below
AutoSizeText(
       Dummy.locations[index]['name'],
       maxLines: 1,
       minFontSize: 18,
       overflowReplacement: SizedBox(
              width: 180,
              height: 18,
              child: Marquee(
                   scrollAxis: Axis.horizontal,
                   velocity: 5,
                   text:'${Dummy.locations[index]['name']} ',
                   style: const TextStyle(fontSize: 18,color: Colors.white)),
              ),
       style: const TextStyle(fontSize: 18, color: Colors.white),
),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jack Wong