Created
August 17, 2025 22:05
-
-
Save BarryDaBee/ae360e008ebe15b09b349ced7e939e8b to your computer and use it in GitHub Desktop.
Simple blinking cursor widget using Flutter Hooks, mimicking the internal cursor animation from EditableText. It uses an AnimationController with a CurvedAnimation (fastOutSlowIn) and a FadeTransition to smoothly animate the opacity back and forth, giving a natural caret blink effect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AppAnimatedCursor extends HookWidget { | |
| const AppAnimatedCursor({super.key, this.height = 40}); | |
| final double height; | |
| @override | |
| Widget build(BuildContext context) { | |
| final controller = useAnimationController( | |
| duration: const Duration(milliseconds: 500), | |
| )..repeat(reverse: true); | |
| final animation = useMemoized( | |
| () => CurvedAnimation(parent: controller, curve: Curves.fastOutSlowIn), | |
| [controller], | |
| ); | |
| return FadeTransition( | |
| opacity: animation, | |
| child: Container( | |
| width: 1, | |
| height: height, | |
| color: Colors.black, | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment