最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在Flutter中制作翻轉(zhuǎn)卡片動畫的完整實例代碼

 更新時間:2021年10月13日 08:58:44   作者:Breeze_Luckly  
最近Flutter的勢頭是越來越猛了,作為一個Android程序猿,我自然也是想要趕緊嘗試一把,這篇文章主要給大家介紹了關(guān)于在Flutter中制作翻轉(zhuǎn)卡片動畫的相關(guān)資料,需要的朋友可以參考下

前言

本文將帶您了解在 Flutter 中制作翻轉(zhuǎn)卡片動畫的兩個完整示例。第一個示例從頭開始實現(xiàn),第二個示例使用第三方包。閑話少說,讓我們動手吧。

使用自寫代碼

本示例使用變換小部件創(chuàng)建翻轉(zhuǎn)卡片效果。

預(yù)覽

我們將要構(gòu)建的演示應(yīng)用程序顯示了兩張隱藏一些秘密的卡片。您可以通過按“揭示秘密” 按鈕來揭開面具背后的東西。最上面的卡片展示了一個水平翻轉(zhuǎn)動畫,底部一張展示了一個垂直翻轉(zhuǎn)動畫。

完整代碼

// main.dart
import 'package:flutter/material.dart';
import 'dart:math';
​
void main() {
  runApp(MyApp());
}
​
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        // Remove the debug banner
        debugShowCheckedModeBanner: false,
        title: 'Kindacode.com',
        theme: ThemeData(
          primarySwatch: Colors.amber,
        ),
        home: HomePage());
  }
}
​
class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);
​
  @override
  _HomePageState createState() => _HomePageState();
}
​
class _HomePageState extends State with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation _animation;
  AnimationStatus _status = AnimationStatus.dismissed;
​
  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(vsync: this, duration: Duration(seconds: 1));
    _animation = Tween(end: 1.0, begin: 0.0).animate(_controller)
      ..addListener(() {
        setState(() {});
      })
      ..addStatusListener((status) {
        _status = status;
      });
  }
​
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Kindacode.com'),
      ),
      body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(
              height: 30,
            ),
            // Horizontal Flipping
            Transform(
              alignment: FractionalOffset.center,
              transform: Matrix4.identity()
                ..setEntry(3, 2, 0.0015)
                ..rotateY(pi * _animation.value),
              child: Card(
                child: _animation.value <= 0.5
                    ? Container(
                        color: Colors.deepOrange,
                        width: 240,
                        height: 300,
                        child: Center(
                            child: Text(
                          '?',
                          style: TextStyle(fontSize: 100, color: Colors.white),
                        )))
                    : Container(
                        width: 240,
                        height: 300,
                        color: Colors.grey,
                        child: Image.network(
                          'https://www.kindacode.com/wp-content/uploads/2021/09/girl.jpeg',
                          fit: BoxFit.cover,
                        )),
              ),
            ),
            // Vertical Flipping
            SizedBox(
              height: 30,
            ),
            Transform(
              alignment: FractionalOffset.center,
              transform: Matrix4.identity()
                ..setEntry(3, 2, 0.0015)
                ..rotateX(pi * _animation.value),
              child: Card(
                child: _animation.value <= 0.5
                    ? Container(
                        color: Colors.deepPurple,
                        width: 240,
                        height: 300,
                        child: Center(
                            child: Text(
                          '?',
                          style: TextStyle(fontSize: 100, color: Colors.white),
                        )))
                    : Container(
                        width: 240,
                        height: 300,
                        color: Colors.grey,
                        child: RotatedBox(
                          quarterTurns: 2,
                          child: Image.network(
                            'https://www.kindacode.com/wp-content/uploads/2021/09/flower.jpeg',
                            fit: BoxFit.cover,
                          ),
                        )),
              ),
            ),
            ElevatedButton(
                onPressed: () {
                  if (_status == AnimationStatus.dismissed) {
                    _controller.forward();
                  } else {
                    _controller.reverse();
                  }
                },
                child: Text('Reveal The Secrets'))
          ],
        ),
      ),
    );
  }
}

使用第三個插件

從頭開始編寫代碼可能既麻煩又耗時。如果您想快速而整潔地完成工作,那么使用插件中的預(yù)制小部件是一個不錯的選擇。下面的示例使用了一個名為flip_card的很棒的包。

編碼

1.將插件添加到您的項目中:

flutter pub add flip_card

您可能需要運(yùn)行:

flutter pub get

安裝插件。

2.實現(xiàn)插件提供的FlipCard小部件:

Center(
        child: FlipCard(
          direction: FlipDirection.HORIZONTAL, 
          front: Container(
            width: 300,
            height: 400,
            color: Colors.red,
          ),
          back: Container(
            width: 300,
            height: 400,
            color: Colors.blue,
          ),
        ),
      ),

結(jié)論

我們已經(jīng)通過幾個在應(yīng)用程序中實現(xiàn)翻轉(zhuǎn)效果的示例。

到此這篇關(guān)于在Flutter中制作翻轉(zhuǎn)卡片動畫的文章就介紹到這了,更多相關(guān)Flutter翻轉(zhuǎn)卡片動畫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

铜梁县| 当涂县| 唐海县| 子洲县| 石首市| 太白县| 赫章县| 玛曲县| 赞皇县| 甘谷县| 千阳县| 揭阳市| 蓬溪县| 阳江市| 黑河市| 农安县| 北宁市| 阿拉善盟| 合山市| 深圳市| 安岳县| 东方市| 双城市| 宁陕县| 南丰县| 栾城县| 南宁市| 朝阳市| 沈阳市| 贵南县| 庆阳市| 盐津县| 垫江县| 溧阳市| 射洪县| 沈阳市| 清新县| 中宁县| 乌拉特前旗| 东乌| 邻水|