From 494d121c8bb6c457cf9adf948c1b4b60386e85f4 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 16 Feb 2021 18:57:14 +0530 Subject: [PATCH] feat: Added threshold --- stream_chat_v1/lib/main.dart | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stream_chat_v1/lib/main.dart b/stream_chat_v1/lib/main.dart index 5c7dfa3..63169e7 100644 --- a/stream_chat_v1/lib/main.dart +++ b/stream_chat_v1/lib/main.dart @@ -40,6 +40,7 @@ class _MyAppState extends State with TickerProviderStateMixin { Animation _animation; AnimationController _animationController; Animation _colorAnimation; + int timeOfStartMs; Future _initConnection() async { final secureStorage = FlutterSecureStorage(); @@ -67,6 +68,7 @@ class _MyAppState extends State with TickerProviderStateMixin { @override void initState() { + timeOfStartMs = DateTime.now().millisecondsSinceEpoch; _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 300)); _animation = Tween(begin: 0.0, end: 1000.0).animate( @@ -97,7 +99,17 @@ class _MyAppState extends State with TickerProviderStateMixin { : Colors.black) .animate(CurvedAnimation( parent: _animationController, curve: Curves.easeInOut)); - _animationController.forward(); + + var now = DateTime.now().millisecondsSinceEpoch; + + if (now - timeOfStartMs > 1000) { + _animationController.forward(); + } else { + var diff = 1000 - (now - timeOfStartMs); + Future.delayed(Duration(milliseconds: diff)).then((value) { + _animationController.forward(); + }); + } }, ); _animationController.addStatusListener((status) {