gpt4 book ai didi

flutter - 如何在 Flutter 中创建从左到右或从上到下叠加的飞溅动画

转载 作者:行者123 更新时间:2023-12-04 09:38:01 24 4
gpt4 key购买 nike

无法在 flutter 的布局上方创建叠加飞溅动画。

enter image description here

class AnimateContainer extends StatelessWidget {
final String assetPath;

AnimateContainer(this.assetPath);
@override
Widget build(BuildContext context) {
return Container(
width: 300,
height: 100,
child: Image.asset(
'assets/$assetPath',
),
);
}
}

最佳答案

添加

我更新了代码看起来像附加的 gif。

您可以使用如下所示的“AnimatedPositioned”小部件。

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

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "App",
theme: new ThemeData(primarySwatch: Colors.amber),
home: Test(),
);
}
}

class Test extends StatefulWidget {
@override
_TestState createState() => _TestState();
}

class _TestState extends State<Test> {
double rightValue = 0;

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Title",
theme: new ThemeData(primarySwatch: Colors.amber),
home: Scaffold(
body: SafeArea(
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.transparent,
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(
'assets/bg.png',
),
),
),
height: 200.0,
),
AnimatedPositioned(
// left: 0,
left: 70 + rightValue,
duration: Duration(milliseconds: 1000),
child: Center(
child: Container(
color: Colors.black.withOpacity(0.5),
width: MediaQuery.of(context).size.width,
height: 200.0,
),
),
),
AnimatedPositioned(
// left: 0,
left: rightValue,
duration: Duration(milliseconds: 1000),
child: Center(
child: ShaderMask(
shaderCallback: (rect) {
return LinearGradient(
begin: Alignment.centerRight,
end: Alignment.centerLeft,
colors: [Color(0xFF45ced5), Colors.transparent],
).createShader(
Rect.fromLTRB(0, 0, rect.width, rect.height));
},
blendMode: BlendMode.dstIn,
child: Container(
color: Color(0xFF45ced5),
width: 70.0,
height: 200.0,
),
),
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
rightValue = MediaQuery.of(context).size.width;
});
},
child: Icon(Icons.navigation),
backgroundColor: Colors.green,
),
),
);
}
}


enter image description here

关于flutter - 如何在 Flutter 中创建从左到右或从上到下叠加的飞溅动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62464471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com