From d0791279a23f5750d37367b54d81a279fdc1cb74 Mon Sep 17 00:00:00 2001 From: Yoshi Date: Wed, 21 Aug 2024 21:55:29 +0300 Subject: [PATCH] Fix animation markers --- lib/app/modules/map/view/map.dart | 90 ++++++++++++++++++------------- pubspec.lock | 6 +-- 2 files changed, 55 insertions(+), 41 deletions(-) diff --git a/lib/app/modules/map/view/map.dart b/lib/app/modules/map/view/map.dart index ea4561c..7a6a6d3 100644 --- a/lib/app/modules/map/view/map.dart +++ b/lib/app/modules/map/view/map.dart @@ -40,7 +40,8 @@ class _MapWeatherState extends State with TickerProviderStateMixin { final bool _isDarkMode = Get.theme.brightness == Brightness.dark; WeatherCard? _selectedWeatherCard; bool _isCardVisible = false; - double _cardBottomPosition = -200; + late final AnimationController _animationController; + late final Animation _offsetAnimation; final _focusNode = FocusNode(); late final TextEditingController _controllerSearch = TextEditingController(); @@ -50,28 +51,44 @@ class _MapWeatherState extends State with TickerProviderStateMixin { return FileCacheStore('${dir.path}${Platform.pathSeparator}MapTiles'); } + @override + void initState() { + _animationController = AnimationController( + duration: const Duration(milliseconds: 300), + vsync: this, + ); + + _offsetAnimation = Tween( + begin: const Offset(0.0, 1.0), + end: Offset.zero, + ).animate(CurvedAnimation( + parent: _animationController, + curve: Curves.easeInOut, + )); + super.initState(); + } + @override void dispose() { _animatedMapController.dispose(); _controllerSearch.dispose(); + _animationController.dispose(); super.dispose(); } void _onMarkerTap(WeatherCard weatherCard) { setState(() { _selectedWeatherCard = weatherCard; - _cardBottomPosition = 0; - _isCardVisible = true; }); + _animationController.forward(); + _isCardVisible = true; } void _hideCard() { - setState(() { - _cardBottomPosition = -200; - }); - Future.delayed(const Duration(milliseconds: 300), () { + _animationController.reverse().then((_) { setState(() { _isCardVisible = false; + _selectedWeatherCard = null; }); }); _focusNode.unfocus(); @@ -160,36 +177,28 @@ class _MapWeatherState extends State with TickerProviderStateMixin { } Widget _buildWeatherCard() { - return AnimatedPositioned( - duration: const Duration(milliseconds: 300), - curve: Curves.easeInOut, - left: 0, - right: 0, - bottom: _cardBottomPosition, - child: AnimatedOpacity( - opacity: _isCardVisible ? 1.0 : 0.0, - duration: const Duration(milliseconds: 300), - child: _isCardVisible - ? GestureDetector( - onTap: () => Get.to( - () => InfoWeatherCard(weatherCard: _selectedWeatherCard!), - transition: Transition.downToUp, - ), - child: WeatherCardContainer( - time: _selectedWeatherCard!.time!, - timeDaily: _selectedWeatherCard!.timeDaily!, - timeDay: _selectedWeatherCard!.sunrise!, - timeNight: _selectedWeatherCard!.sunset!, - weather: _selectedWeatherCard!.weathercode!, - degree: _selectedWeatherCard!.temperature2M!, - district: _selectedWeatherCard!.district!, - city: _selectedWeatherCard!.city!, - timezone: _selectedWeatherCard!.timezone!, - ), - ) - : const SizedBox.shrink(), - ), - ); + return _isCardVisible && _selectedWeatherCard != null + ? SlideTransition( + position: _offsetAnimation, + child: GestureDetector( + onTap: () => Get.to( + () => InfoWeatherCard(weatherCard: _selectedWeatherCard!), + transition: Transition.downToUp, + ), + child: WeatherCardContainer( + time: _selectedWeatherCard!.time!, + timeDaily: _selectedWeatherCard!.timeDaily!, + timeDay: _selectedWeatherCard!.sunrise!, + timeNight: _selectedWeatherCard!.sunset!, + weather: _selectedWeatherCard!.weathercode!, + degree: _selectedWeatherCard!.temperature2M!, + district: _selectedWeatherCard!.district!, + city: _selectedWeatherCard!.city!, + timezone: _selectedWeatherCard!.timezone!, + ), + ), + ) + : const SizedBox.shrink(); } @override @@ -280,7 +289,12 @@ class _MapWeatherState extends State with TickerProviderStateMixin { markers: [mainMarker, ...cardMarkers], ); }), - _buildWeatherCard(), + Positioned( + left: 0, + right: 0, + bottom: 0, + child: _buildWeatherCard(), + ), ], ), RawAutocomplete( diff --git a/pubspec.lock b/pubspec.lock index e2b8e42..6d6e3f2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1195,10 +1195,10 @@ packages: dependency: transitive description: name: url_launcher_android - sha256: f0c73347dfcfa5b3db8bc06e1502668265d39c08f310c29bff4e28eea9699f79 + sha256: e35a698ac302dd68e41f73250bd9517fe3ab5fa4f18fe4647a0872db61bacbab url: "https://pub.dev" source: hosted - version: "6.3.9" + version: "6.3.10" url_launcher_ios: dependency: transitive description: @@ -1369,4 +1369,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.5.0 <4.0.0" - flutter: ">=3.22.0" + flutter: ">=3.24.0"