Fix animation markers

This commit is contained in:
Yoshi 2024-08-21 21:55:29 +03:00
parent 88a7bafffb
commit d0791279a2
2 changed files with 55 additions and 41 deletions

View file

@ -40,7 +40,8 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
final bool _isDarkMode = Get.theme.brightness == Brightness.dark; final bool _isDarkMode = Get.theme.brightness == Brightness.dark;
WeatherCard? _selectedWeatherCard; WeatherCard? _selectedWeatherCard;
bool _isCardVisible = false; bool _isCardVisible = false;
double _cardBottomPosition = -200; late final AnimationController _animationController;
late final Animation<Offset> _offsetAnimation;
final _focusNode = FocusNode(); final _focusNode = FocusNode();
late final TextEditingController _controllerSearch = TextEditingController(); late final TextEditingController _controllerSearch = TextEditingController();
@ -50,28 +51,44 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
return FileCacheStore('${dir.path}${Platform.pathSeparator}MapTiles'); return FileCacheStore('${dir.path}${Platform.pathSeparator}MapTiles');
} }
@override
void initState() {
_animationController = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: this,
);
_offsetAnimation = Tween<Offset>(
begin: const Offset(0.0, 1.0),
end: Offset.zero,
).animate(CurvedAnimation(
parent: _animationController,
curve: Curves.easeInOut,
));
super.initState();
}
@override @override
void dispose() { void dispose() {
_animatedMapController.dispose(); _animatedMapController.dispose();
_controllerSearch.dispose(); _controllerSearch.dispose();
_animationController.dispose();
super.dispose(); super.dispose();
} }
void _onMarkerTap(WeatherCard weatherCard) { void _onMarkerTap(WeatherCard weatherCard) {
setState(() { setState(() {
_selectedWeatherCard = weatherCard; _selectedWeatherCard = weatherCard;
_cardBottomPosition = 0;
_isCardVisible = true;
}); });
_animationController.forward();
_isCardVisible = true;
} }
void _hideCard() { void _hideCard() {
setState(() { _animationController.reverse().then((_) {
_cardBottomPosition = -200;
});
Future.delayed(const Duration(milliseconds: 300), () {
setState(() { setState(() {
_isCardVisible = false; _isCardVisible = false;
_selectedWeatherCard = null;
}); });
}); });
_focusNode.unfocus(); _focusNode.unfocus();
@ -160,17 +177,10 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
} }
Widget _buildWeatherCard() { Widget _buildWeatherCard() {
return AnimatedPositioned( return _isCardVisible && _selectedWeatherCard != null
duration: const Duration(milliseconds: 300), ? SlideTransition(
curve: Curves.easeInOut, position: _offsetAnimation,
left: 0, child: GestureDetector(
right: 0,
bottom: _cardBottomPosition,
child: AnimatedOpacity(
opacity: _isCardVisible ? 1.0 : 0.0,
duration: const Duration(milliseconds: 300),
child: _isCardVisible
? GestureDetector(
onTap: () => Get.to( onTap: () => Get.to(
() => InfoWeatherCard(weatherCard: _selectedWeatherCard!), () => InfoWeatherCard(weatherCard: _selectedWeatherCard!),
transition: Transition.downToUp, transition: Transition.downToUp,
@ -186,10 +196,9 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
city: _selectedWeatherCard!.city!, city: _selectedWeatherCard!.city!,
timezone: _selectedWeatherCard!.timezone!, timezone: _selectedWeatherCard!.timezone!,
), ),
)
: const SizedBox.shrink(),
), ),
); )
: const SizedBox.shrink();
} }
@override @override
@ -280,7 +289,12 @@ class _MapWeatherState extends State<MapWeather> with TickerProviderStateMixin {
markers: [mainMarker, ...cardMarkers], markers: [mainMarker, ...cardMarkers],
); );
}), }),
_buildWeatherCard(), Positioned(
left: 0,
right: 0,
bottom: 0,
child: _buildWeatherCard(),
),
], ],
), ),
RawAutocomplete<Result>( RawAutocomplete<Result>(

View file

@ -1195,10 +1195,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_android name: url_launcher_android
sha256: f0c73347dfcfa5b3db8bc06e1502668265d39c08f310c29bff4e28eea9699f79 sha256: e35a698ac302dd68e41f73250bd9517fe3ab5fa4f18fe4647a0872db61bacbab
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "6.3.9" version: "6.3.10"
url_launcher_ios: url_launcher_ios:
dependency: transitive dependency: transitive
description: description:
@ -1369,4 +1369,4 @@ packages:
version: "3.1.2" version: "3.1.2"
sdks: sdks:
dart: ">=3.5.0 <4.0.0" dart: ">=3.5.0 <4.0.0"
flutter: ">=3.22.0" flutter: ">=3.24.0"