自定PopupRoute(二)動(dòng)畫


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

class CustomerAnimationView extends StatefulWidget {
  const CustomerAnimationView({Key? key}) : super(key: key);

  @override
  State<CustomerAnimationView> createState() => _CustomerAnimationViewState();
}

class _CustomerAnimationViewState extends State<CustomerAnimationView>
    with TickerProviderStateMixin {
  Animation<double>? alphaAnim;
  Animation<double>? colorAlphaAnim;

  AnimationController? alphaController;
  AnimationController? colorController;
  List dataSource = [];

  @override
  void initState() {
    alphaController =
        AnimationController(vsync: this, duration: Duration(milliseconds: 300));
    colorController =
        AnimationController(vsync: this, duration: Duration(milliseconds: 300));

    this.alphaAnim = Tween<double>(begin: 0, end: 100).animate(this.alphaController!);
    // this.alphaAnim = Tween<double>(begin: 300, end: 100).animate(this.alphaController!);
    this.colorAlphaAnim = Tween<double>(begin: 0, end: 150).animate(this.colorController!);

    this.alphaController!.forward();
    this.colorController!.forward();

    super.initState();
  }

  @override
  dispose() {
    this.alphaController?.reverse();
    this.colorController?.reverse();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.pop(context);
      },
      child: AnimatedBuilder(
          animation: this.alphaController!,
          builder: (_, __) {
            return Container(
              color: Colors.black.withAlpha(
                  this.colorAlphaAnim!.value.toInt()),
              child: Stack(
                children: [
                  Container(
                    // padding: EdgeInsets.only(top: 100,bottom: 100,left: 10,right: 10),
                    margin: EdgeInsets.only(top: this.alphaAnim!.value.toDouble(),bottom: 100,left: 10,right: 10),
                    height:  100,//this.alphaAnim!.value.toDouble(),
                    // width: 300,
                    color: Colors.blue,
                    child: Text("123"),
                  )
                ],
              )
            );
          }),
    );
  }
}

如果單個(gè)動(dòng)畫 可以

with SingleTickerProviderStateMixin
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容