透明度动画

This commit is contained in:
toly
2023-05-02 11:28:44 +08:00
parent cae6bd19b6
commit ddc9f6e274
3 changed files with 60 additions and 6 deletions

View File

@@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
class AnimateText extends StatefulWidget {
final String text;
const AnimateText({Key? key, required this.text}) : super(key: key);
@override
State<AnimateText> createState() => _FadTextState();
}
class _FadTextState extends State<AnimateText> with SingleTickerProviderStateMixin {
late AnimationController controller;
late Animation<double> opacity;
late Animation<Offset> position;
late Animation<double> scale;
@override
void initState() {
super.initState();
controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 500));
opacity = Tween(begin: 1.0, end: 0.0).animate(controller);
controller.forward();
}
@override
void didUpdateWidget(covariant AnimateText oldWidget) {
super.didUpdateWidget(oldWidget);
controller.forward(from: 0);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return FadeTransition(
opacity: opacity,
child: Text(widget.text),
);
}
}

View File

@@ -2,6 +2,7 @@ import 'dart:math';
import 'package:flame_audio/flame_audio.dart'; import 'package:flame_audio/flame_audio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_first_station/muyu/animate_text.dart';
import 'muyu_image.dart'; import 'muyu_image.dart';
import 'count_panel.dart'; import 'count_panel.dart';
@@ -16,6 +17,8 @@ class MuyuPage extends StatefulWidget {
class _MuyuPageState extends State<MuyuPage> { class _MuyuPageState extends State<MuyuPage> {
int _counter = 0; int _counter = 0;
int _cruValue = 2;
final Random _random = Random(); final Random _random = Random();
AudioPool? pool; AudioPool? pool;
@@ -49,9 +52,15 @@ class _MuyuPageState extends State<MuyuPage> {
), ),
), ),
Expanded( Expanded(
child: MuyuAssetsImage( child: Stack(
image: 'assets/images/muyu.png', alignment: Alignment.topCenter,
onTap: _onKnock, children: [
MuyuAssetsImage(
image: 'assets/images/muyu.png',
onTap: _onKnock,
),
if (_cruValue != 0) AnimateText(text: '功德+$_cruValue')
],
), ),
), ),
], ],
@@ -68,8 +77,8 @@ class _MuyuPageState extends State<MuyuPage> {
void _onKnock() { void _onKnock() {
pool?.start(); pool?.start();
setState(() { setState(() {
int addCount = 1 + _random.nextInt(3); _cruValue = 1 + _random.nextInt(3);
_counter += addCount; _counter += _cruValue;
}); });
} }
} }

View File

@@ -10,7 +10,7 @@ packages:
source: hosted source: hosted
version: "2.10.0" version: "2.10.0"
audioplayers: audioplayers:
dependency: "direct main" dependency: transitive
description: description:
name: audioplayers name: audioplayers
sha256: "6063c05f987596ba7a3dad9bb9a5d8adfa5e7c07b9bae5301b27c11d0b3a239f" sha256: "6063c05f987596ba7a3dad9bb9a5d8adfa5e7c07b9bae5301b27c11d0b3a239f"