如何解决我怎样才能像这样在 Flutter 中为对话框设置动画
我正在尝试为 Flutter 中的警报对话框设置动画,以便在它弹出时显示如下动画。
如何在 alertDialog 中实现 Pokemon Go 的以下外观和行为?
我真的很想在我的应用中加入这个动画。
感谢您的回答!
解决方法
试试这个,修改任何变量以满足您的要求:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',debugShowCheckedModeBanner: false,home: MyHomePage(),);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
AnimationController _controller;
Animation<Offset> _animation;
double _width = 20;
double _height = 200;
Color _color = Colors.transparent;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 1),vsync: this,);
_animation = Tween<Offset>(
begin: const Offset(0.0,1.0),end: const Offset(0.0,-2.0),).animate(CurvedAnimation(
parent: _controller,curve: Curves.easeInCubic,));
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,appBar: AppBar(
actions: [
IconButton(
icon: Icon(Icons.send),onPressed: () {
setState(() {
_color = Colors.white;
});
_controller.forward().then((_) {
_width = 200;
setState(() {});
});
},),],body: Stack(
children: [
Align(
alignment: Alignment.bottomCenter,child: SlideTransition(
position: _animation,child: AnimatedContainer(
width: _width,height: _height,decoration: BoxDecoration(
color: _color,borderRadius: BorderRadius.circular(10),duration: Duration(seconds: 1),curve: Curves.fastOutSlowIn,);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。