作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试制作一个从左到右过渡的容器,尺寸增加直到到达中心,到达中心后尺寸减小。
我尝试使用两个 Controller 和更多的Tween-s,但未找到结果。
`import 'package:flutter/material.dart';
import 'package:flutter/animation.dart';
class Basic_animation_view extends StatefulWidget {
@override
_Basic_animation_viewState createState() => _Basic_animation_viewState();
}
class _Basic_animation_viewState extends State<Basic_animation_view>
with TickerProviderStateMixin {
AnimationController controller;
Animation<Offset> animation;
Animation<Size> growAnimation;
@override
void initState() {
super.initState();
controller =
AnimationController(vsync: this, duration: const Duration(seconds: 3))
..addListener(() {
setState(() {});
});
animation = Tween<Offset>(begin: Offset(0, 0), end: Offset(5, 0))
.animate(controller);
growAnimation =
Tween<Size>(begin: Size(50.0, 50.0), end: Size(100.0, 100.0))
.animate(CurvedAnimation(parent: controller,curve: Curves.linear));
controller.repeat();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SlideTransition(
position: animation,
child: Container(***strong text***
width:growAnimation.value.width,
height:growAnimation.value.height,
color: Colors.red,
),
),
],
));
}
}
`
最佳答案
Maybe an animated container class will be closer to what you want. You can find more details using the documented sample with more details found at the source.
// Flutter code sample for
// The following example (depicted above) transitions an AnimatedContainer
// between two states. It adjusts the [height], [width], [color], and
// [alignment] properties when tapped.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: MyStatefulWidget(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
bool selected = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
setState(() {
selected = !selected;
});
},
child: Center(
child: AnimatedContainer(
width: selected ? 200.0 : 100.0,
height: selected ? 100.0 : 200.0,
color: selected ? Colors.red : Colors.blue,
alignment:
selected ? Alignment.center : AlignmentDirectional.topCenter,
duration: Duration(seconds: 2),
curve: Curves.fastOutSlowIn,
child: FlutterLogo(size: 75),
),
),
);
}
}
关于animation - 不能使移动的容器逐渐变大,并且从屏幕中心开始变小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58738679/
COW 不是奶牛,是 Copy-On-Write 的缩写,这是一种是复制但也不完全是复制的技术。 一般来说复制就是创建出完全相同的两份,两份是独立的: 但是,有的时候复制这件事没多大必要
我是一名优秀的程序员,十分优秀!