I want to make a ball with a number written roll to the left side, and I want to make the ball stop when it reaches at the left end. I tried to find a listener but I couldn't, and I didn't manage to find any way to notify when the ball hits left position 0. How can I make it?
I don't think this code can help but the ball code is like this:
Container(
width: Get.width,
height: 90,
padding: const EdgeInsets.only(top: 10, bottom: 10),
decoration: const BoxDecoration(
border: Border(top: BorderSide(color: Colors.black, width: 1), bottom: BorderSide(color: Colors.black, width: 1))
),
child: Stack(
alignment: Alignment.center,
children: [
AnimatedBuilder(
animation: controller.firstAnimationController,
builder: (context, widget) {
return AnimatedPositioned(
duration: const Duration(milliseconds: 1000),
left: !controller.isFirstStarted.value ? Get.width : 0,
child: Transform.rotate(
angle: -controller.firstAnimationController.value * 6.3,
child: Container(
width: 60,
height: 60,
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 1),
borderRadius: BorderRadius.circular(30),
color: Colors.white,
),
child: const Text('37', style: TextStyle(fontSize: 20)
))
)
);
}
),
]
),
);
and controller:
late AnimationController firstAnimationController;
RxBool isFirstStarted = false.obs;
@override
void onInit() async {
super.onInit();
firstAnimationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1500),
);
firstAnimationController.repeat();
}
@override
void dispose() {
super.dispose();
firstAnimationController.dispose();
}