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

Flutter數(shù)字切換動畫實(shí)現(xiàn)示例詳解

 更新時間:2023年08月03日 10:27:57   作者:龍之音  
這篇文章主要為大家介紹了Flutter數(shù)字切換動畫實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

效果

需求

  • 數(shù)字切換時新數(shù)字從上往下進(jìn)入,上個數(shù)字從上往下出
  • 新數(shù)字進(jìn)入時下落到位置并帶有回彈效果
  • 上個數(shù)字及新輸入切換時帶有透明度和縮放動畫

實(shí)現(xiàn)

AnimatedSwitcher

主要采用AnimatedSwitcher實(shí)現(xiàn)需求,代碼比較簡單,直接擼

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_xy/widgets/xy_app_bar.dart';
class NumAnimPage extends StatefulWidget {
  const NumAnimPage({super.key});
  @override
  State<NumAnimPage> createState() => _NumAnimPageState();
}
class _NumAnimPageState extends State<NumAnimPage> {
  int _currentNum = 0;
  // 數(shù)字文本隨機(jī)顏色
  Color get _numColor {
    Random random = Random();
    int red = random.nextInt(256);
    int green = random.nextInt(256);
    int blue = random.nextInt(256);
    return Color.fromARGB(255, red, green, blue);
  }
  // 數(shù)字累加
  void _addNumber() {
    setState(() {
      _currentNum++;
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XYAppBar(
        title: "數(shù)字動畫",
      ),
      body: Center(
        child: _bodyWidget(),
      ),
    );
  }
  Widget _bodyWidget() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        AnimatedSwitcher(
          duration: const Duration(milliseconds: 500),
          transitionBuilder: (Widget child, Animation<double> animation) {
            Offset startOffset = animation.status == AnimationStatus.completed
                ? const Offset(0.0, 1.0)
                : const Offset(0.0, -1.0);
            Offset endOffset = const Offset(0.0, 0.0);
            return SlideTransition(
              position: Tween(begin: startOffset, end: endOffset).animate(
                CurvedAnimation(parent: animation, curve: Curves.bounceOut),
              ),
              child: FadeTransition(
                opacity: Tween(begin: 0.0, end: 1.0).animate(
                  CurvedAnimation(parent: animation, curve: Curves.linear),
                ),
                child: ScaleTransition(
                  scale: Tween(begin: 0.5, end: 1.0).animate(
                    CurvedAnimation(parent: animation, curve: Curves.linear),
                  ),
                  child: child,
                ),
              ),
            );
          },
          child: Text(
            '$_currentNum',
            key: ValueKey<int>(_currentNum),
            style: TextStyle(fontSize: 100, color: _numColor),
          ),
        ),
        const SizedBox(height: 80),
        ElevatedButton(
          onPressed: _addNumber,
          child: const Text(
            '數(shù)字動畫',
            style: TextStyle(fontSize: 25, color: Colors.white),
          ),
        ),
      ],
    );
  }
}

具體見github:github.com/yixiaolunhui/flutter_xy

以上就是Flutter數(shù)字切換動畫實(shí)現(xiàn)示例詳解的詳細(xì)內(nèi)容,更多關(guān)于Flutter數(shù)字切換動畫的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

荥阳市| 南和县| 罗山县| 资溪县| 莆田市| 郑州市| 东港市| 庆安县| 仁寿县| 廊坊市| 亳州市| 通河县| 莱芜市| 兴国县| 黑龙江省| 陆川县| 宁津县| 姜堰市| 屯留县| 青海省| 峡江县| 莱芜市| 宾阳县| 普洱| 遂昌县| 房产| 昌乐县| 贵阳市| 叙永县| 航空| 阜新| 青川县| 徐州市| 卫辉市| 阳江市| 江永县| 汉寿县| 淅川县| 永城市| 阿鲁科尔沁旗| 嵊州市|