Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Animation 更改颤振时动画的方向_Animation_Flutter_Mobile_Dart - Fatal编程技术网

Animation 更改颤振时动画的方向

Animation 更改颤振时动画的方向,animation,flutter,mobile,dart,Animation,Flutter,Mobile,Dart,我得到了一个名为flatter\u flip\u view的插件。它工作得很好,但我想改变动画的方向。我想控制它是从右向左还是从左向右。 这是链接。有人知道怎么做吗? 谢谢大家。您可以使用参数goBackDirection和goFrontDirection控制值AxisDirection.right和AxisDirection.left 代码片段 FlipView( animationController: _curvedAnimation,

我得到了一个名为flatter\u flip\u view的插件。它工作得很好,但我想改变动画的方向。我想控制它是从右向左还是从左向右。 这是链接。有人知道怎么做吗?
谢谢大家。

您可以使用参数
goBackDirection
goFrontDirection
控制值
AxisDirection.right
AxisDirection.left

代码片段

FlipView(
              animationController: _curvedAnimation,
              front: _buildCard('A', () => _flip(true)),
              back: _buildCard('B', () => _flip(false)),
              goBackDirection: AxisDirection.right,
              goFrontDirection: AxisDirection.right,
            )
工作演示

完整代码

import 'package:flutter/material.dart';
import 'package:flutter_flip_view/flutter_flip_view.dart';

class SimpleExample extends StatefulWidget {
  @override
  _SimpleExampleState createState() => _SimpleExampleState();
}

class _SimpleExampleState extends State<SimpleExample>
    with SingleTickerProviderStateMixin {
  AnimationController _animationController;
  Animation<double> _curvedAnimation;

  @override
  void initState() {
    super.initState();

    _animationController = AnimationController(
        vsync: this, duration: Duration(milliseconds: 1000));
    _curvedAnimation =
        CurvedAnimation(parent: _animationController, curve: Curves.easeInOut);
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  void _flip(bool reverse) {
    if (_animationController.isAnimating) return;
    if (reverse) {
      _animationController.forward();
    } else {
      _animationController.reverse();
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Center(
            child: FlipView(
              animationController: _curvedAnimation,
              front: _buildCard('A', () => _flip(true)),
              back: _buildCard('B', () => _flip(false)),
              goBackDirection: AxisDirection.right,
              goFrontDirection: AxisDirection.right,
            ),
          ),
        ),
      ),
    );
  }

  Widget _buildCard(String title, GestureTapCallback onTap) {
    return AspectRatio(
      aspectRatio: 0.7,
      child: Card(
        elevation: 4,
        clipBehavior: Clip.hardEdge,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(16),
            gradient: LinearGradient(
              colors: [
                Color(0xff92ffc0),
                Color(0Xff002661),
              ],
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
            ),
          ),
          child: Material(
            color: Colors.transparent,
            child: InkWell(
              splashColor: Colors.white.withOpacity(0.1),
              highlightColor: Colors.transparent,
              borderRadius: BorderRadius.circular(8),
              onTap: onTap,
              child: Center(
                child: Container(
                  width: 48,
                  height: 48,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(60),
                    color: Colors.amber,
                  ),
                  child: Text(
                    title,
                    style: TextStyle(
                      fontSize: 24,
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: SimpleExample(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:flatter_flip_view/flatter_flip_view.dart”;
类SimpleExample扩展StatefulWidget{
@凌驾
_SimpleExampleState createState()=>\u SimpleExampleState();
}
类\u SimpleExampleState扩展状态
使用SingleTickerProviderStateMixin{
AnimationController _AnimationController;
动画-曲线动画;
@凌驾
void initState(){
super.initState();
_animationController=animationController(
vsync:this,duration:duration(毫秒:1000));
_曲线化=
曲线动画(父对象:_animationController,曲线:Curves.easeInOut);
}
@凌驾
无效处置(){
_animationController.dispose();
super.dispose();
}
无效翻转(布尔反转){
如果(_animationController.isAnimating)返回;
如果(反向){
_animationController.forward();
}否则{
_animationController.reverse();
}
}
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
主体:填充物(
填充:常数边集全部(16.0),
儿童:中心(
孩子:FlipView(
动画控制器:_曲线动画,
正面:_buildCard('A',()=>_flip(true)),
背面:_buildCard('B',()=>_flip(false)),
goBackDirection:AxisDirection.right,
goFrontDirection:AxisDirection.right,
),
),
),
),
);
}
小部件构建卡(字符串标题、手势TapCallback onTap){
返回AspectRatio(
方面:0.7,
孩子:卡片(
标高:4,
clipBehavior:Clip.hardEdge,
形状:RoundedRectangleBorder(borderRadius:borderRadius.circular(16)),
子:容器(
装饰:盒子装饰(
边界半径:边界半径。圆形(16),
梯度:线性梯度(
颜色:[
颜色(0xff92ffc0),
颜色(0Xff002661),
],
开始:Alignment.topLeft,
结束:对齐。右下角,
),
),
儿童:材料(
颜色:颜色。透明,
孩子:InkWell(
飞溅颜色:颜色。白色。不透明度(0.1),
highlightColor:Colors.transparent,
边界半径:边界半径。圆形(8),
onTap:onTap,
儿童:中心(
子:容器(
宽度:48,
身高:48,
对齐:对齐.center,
装饰:盒子装饰(
边界半径:边界半径。圆形(60),
颜色:颜色。琥珀色,
),
子:文本(
标题
样式:TextStyle(
尺寸:24,
颜色:颜色,白色,
fontWeight:fontWeight.bold,
),
),
),
),
),
),
),
),
);
}
}
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
主页:SimpleExample(),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
int _计数器=0;
void _incrementCounter(){
设置状态(){
_计数器++;
});
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.title),
),
正文:中(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
正文(
“您已经按了这么多次按钮:”,
),
正文(
“$”计数器“,
样式:Theme.of(context).textTheme.display1,
),
],
),
),
浮动操作按钮:浮动操作按钮(
按下时:\ u递增计数器,
工具提示:“增量”,
子:图标(Icons.add),
),
);
}
}

请提供更详细的答案,解释为什么您提供的代码有助于OP。
FlipView(
              animationController: _curvedAnimation,
              front: _buildCard('A', () => _flip(true)),
              back: _buildCard('B', () => _flip(false)),
              goBackDirection: AxisDirection.right,
              goFrontDirection: AxisDirection.right,
            )