Flutter – Hide a line that shouldn’t be shown

I’m trying to create a text with an animation on hover, including a dot in front of it, using Flutter.
The design comes from this website (look at the bottom section you’ll find what I’m reproducing).

Here’s the code for my component:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import 'package:flutter/material.dart';
class MyText extends StatefulWidget {
final String text;
final TextStyle textStyle;
final double width;
final double underlineOffset;
final bool hasDot;
const MyText({
super.key,
required this.text,
required this.textStyle,
required this.width,
required this.underlineOffset,
this.hasDot = false,
});
@override
State<MyText> createState() => _MyTextState();
}
class _MyTextState extends State<MyText> with TickerProviderStateMixin {
late AnimationController _colorAnimationController;
late Animation _colorAnimation;
late AnimationController _underlineAnimationController;
late Animation _underlineAnimation;
@override
void initState() {
_colorAnimationController = AnimationController(
duration: const Duration(milliseconds: 250),
vsync: this,
)..addListener(() {
setState(() {});
});
_colorAnimation = ColorTween(
begin: Colors.black,
end: Colors.orange,
).animate(_colorAnimationController);
_underlineAnimationController = AnimationController(
duration: const Duration(milliseconds: 500),
vsync: this,
)..addListener(() {
if (_underlineAnimationController.isCompleted &&
_underlineAnimationController.value == 1) {
_underlineAnimationController.reset();
}
setState(() {});
});
_underlineAnimation = Tween(begin: -widget.width, end: widget.width)
.animate(_underlineAnimationController);
super.initState();
}
@override
Widget build(BuildContext context) {
return MouseRegion(
onEnter: (event) {
_colorAnimationController.forward();
_underlineAnimationController.animateTo(0.5);
},
onExit: (event) {
_colorAnimationController.reverse();
_underlineAnimationController.animateTo(1);
},
cursor: SystemMouseCursors.click,
child: ClipRRect(
child: Container(
alignment: Alignment.centerRight,
width: widget.hasDot ? widget.width + 25 : widget.width,
height: widget.underlineOffset + 2,
// color: Colors.green,
child: Stack(
clipBehavior: Clip.none,
children: [
// Points (si il y en a un)
if (widget.hasDot)
const Positioned(
top: 9,
left: -26,
child: Icon(
Icons.circle,
color: Colors.black,
size: 10,
),
),
// Texte
Stack(
children: [
Text(
widget.text,
style: widget.textStyle.copyWith(
color: _colorAnimation.value,
),
),
],
),
// Underline (onHover animation)
Positioned(
top: widget.underlineOffset,
left: _underlineAnimation.value,
child: Container(
width: widget.width,
height: 1,
color: Colors.orange,
),
)
],
),
),
),
);
}
}
</code>
<code>import 'package:flutter/material.dart'; class MyText extends StatefulWidget { final String text; final TextStyle textStyle; final double width; final double underlineOffset; final bool hasDot; const MyText({ super.key, required this.text, required this.textStyle, required this.width, required this.underlineOffset, this.hasDot = false, }); @override State<MyText> createState() => _MyTextState(); } class _MyTextState extends State<MyText> with TickerProviderStateMixin { late AnimationController _colorAnimationController; late Animation _colorAnimation; late AnimationController _underlineAnimationController; late Animation _underlineAnimation; @override void initState() { _colorAnimationController = AnimationController( duration: const Duration(milliseconds: 250), vsync: this, )..addListener(() { setState(() {}); }); _colorAnimation = ColorTween( begin: Colors.black, end: Colors.orange, ).animate(_colorAnimationController); _underlineAnimationController = AnimationController( duration: const Duration(milliseconds: 500), vsync: this, )..addListener(() { if (_underlineAnimationController.isCompleted && _underlineAnimationController.value == 1) { _underlineAnimationController.reset(); } setState(() {}); }); _underlineAnimation = Tween(begin: -widget.width, end: widget.width) .animate(_underlineAnimationController); super.initState(); } @override Widget build(BuildContext context) { return MouseRegion( onEnter: (event) { _colorAnimationController.forward(); _underlineAnimationController.animateTo(0.5); }, onExit: (event) { _colorAnimationController.reverse(); _underlineAnimationController.animateTo(1); }, cursor: SystemMouseCursors.click, child: ClipRRect( child: Container( alignment: Alignment.centerRight, width: widget.hasDot ? widget.width + 25 : widget.width, height: widget.underlineOffset + 2, // color: Colors.green, child: Stack( clipBehavior: Clip.none, children: [ // Points (si il y en a un) if (widget.hasDot) const Positioned( top: 9, left: -26, child: Icon( Icons.circle, color: Colors.black, size: 10, ), ), // Texte Stack( children: [ Text( widget.text, style: widget.textStyle.copyWith( color: _colorAnimation.value, ), ), ], ), // Underline (onHover animation) Positioned( top: widget.underlineOffset, left: _underlineAnimation.value, child: Container( width: widget.width, height: 1, color: Colors.orange, ), ) ], ), ), ), ); } } </code>
import 'package:flutter/material.dart';

class MyText extends StatefulWidget {
  final String text;
  final TextStyle textStyle;
  final double width;
  final double underlineOffset;
  final bool hasDot;
  const MyText({
    super.key,
    required this.text,
    required this.textStyle,
    required this.width,
    required this.underlineOffset,
    this.hasDot = false,
  });

  @override
  State<MyText> createState() => _MyTextState();
}

class _MyTextState extends State<MyText> with TickerProviderStateMixin {
  late AnimationController _colorAnimationController;
  late Animation _colorAnimation;
  late AnimationController _underlineAnimationController;
  late Animation _underlineAnimation;

  @override
  void initState() {
    _colorAnimationController = AnimationController(
      duration: const Duration(milliseconds: 250),
      vsync: this,
    )..addListener(() {
        setState(() {});
      });
    _colorAnimation = ColorTween(
      begin: Colors.black,
      end: Colors.orange,
    ).animate(_colorAnimationController);
    _underlineAnimationController = AnimationController(
      duration: const Duration(milliseconds: 500),
      vsync: this,
    )..addListener(() {
        if (_underlineAnimationController.isCompleted &&
            _underlineAnimationController.value == 1) {
          _underlineAnimationController.reset();
        }
        setState(() {});
      });
    _underlineAnimation = Tween(begin: -widget.width, end: widget.width)
        .animate(_underlineAnimationController);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
      onEnter: (event) {
        _colorAnimationController.forward();
        _underlineAnimationController.animateTo(0.5);
      },
      onExit: (event) {
        _colorAnimationController.reverse();
        _underlineAnimationController.animateTo(1);
      },
      cursor: SystemMouseCursors.click,
      child: ClipRRect(
        child: Container(
          alignment: Alignment.centerRight,
          width: widget.hasDot ? widget.width + 25 : widget.width,
          height: widget.underlineOffset + 2,
          // color: Colors.green,
          child: Stack(
            clipBehavior: Clip.none,
            children: [
              // Points (si il y en a un)
              if (widget.hasDot)
                const Positioned(
                  top: 9,
                  left: -26,
                  child: Icon(
                    Icons.circle,
                    color: Colors.black,
                    size: 10,
                  ),
                ),

              // Texte
              Stack(
                children: [
                  Text(
                    widget.text,
                    style: widget.textStyle.copyWith(
                      color: _colorAnimation.value,
                    ),
                  ),
                ],
              ),

              // Underline (onHover animation)
              Positioned(
                top: widget.underlineOffset,
                left: _underlineAnimation.value,
                child: Container(
                  width: widget.width,
                  height: 1,
                  color: Colors.orange,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

It’s all working fine, but when I set hasDot: true, the orange line appears under the dot.

Note: I want the underline animation to occur only under the text and not under the dot.

My issue is how to achieve the same animation effect as when hasDot is false, but with the dot included and the orange line hidden under the dot.

Additional info: If you need the full code of the Flutter project, please check my GitHub repo.

Thank you in advance for your help.

Have a great time coding!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật