我正在开发一个游戏类型的应用程序,该应用程序基本上是像真相和敢于旋转瓶子的游戏,并且在onTap()中调用了fuction move()来生成随机旋转瓶子的时间,要在动画完成后显示一些文本,addStatusListener无法正常工作,并且无法以某种方式在屏幕上返回文本,因此它正在控制台中显示文本,我该如何实现?
import 'package:flutter/material.dart';
import 'dart:math';
import 'dart:async';
int check1 = 0;
void main() async => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(primarySwatch: Colors.blue),
home: new LoginPage(),
);
}
}
class LoginPage extends StatefulWidget {
@override
State createState() => new LoginPageState();
}
class LoginPageState extends State<LoginPage>
with SingleTickerProviderStateMixin {
Animation<double> _iconAnimation;
AnimationController _iconAnimationController;
String selectedValues;
@override
void initState() {
super.initState();
_iconAnimationController = new AnimationController(
vsync: this, duration: new Duration(milliseconds: 500));
_iconAnimation = new CurvedAnimation(
parent: _iconAnimationController,
curve: Curves.bounceOut,
);
_iconAnimation.addListener(() => this.setState(() {}));
_iconAnimationController.forward();
}
//Background Image Code Starts From here
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.white,
body: new Stack(fit: StackFit.expand, children: <Widget>[
new Image(
image: new AssetImage('asset/bg.png'),
fit: BoxFit.cover,
),
new Theme(
child: Container(
padding: const EdgeInsets.fromLTRB(100.0, 10.0, 100.0, 00.0),
decoration: BoxDecoration(
image: DecorationImage(
image: new AssetImage('asset/I2.png'),
alignment: Alignment.topRight,
),
),
),
data: new ThemeData(
canvasColor: Colors.blue.shade200,
brightness: Brightness.dark,
inputDecorationTheme: new InputDecorationTheme()),
isMaterialAppTheme: true,
),
new Column(
children: <Widget>[
new Padding(
padding: new EdgeInsets.only(
top: 50.0,
)),
new Padding(
padding: new EdgeInsets.only(
top: 50.0,
)),
new DropdownButton<String>(
onChanged: (String value) {
setState(() {
new Text(
selectedValues,
style: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.w900,
fontFamily: "Georgia",
color: Colors.grey[300],
),
);
});
},
hint: new Text('Select Type'),
value: selectedValues,
items: <String>[
"Questions",
"Something else",
].map((String value) {
return new DropdownMenuItem<String>(
value: value.toString(),
child: new Text(value),
);
}).toList(),
),
],
),
ImageRotate(),
]),
);
}
}
//Background Image Code Ends From here
//Animation code starts from here
class ImageRotate extends StatefulWidget {
@override
_ImageRotateState createState() => new _ImageRotateState();
}
class _ImageRotateState extends State<ImageRotate>
with SingleTickerProviderStateMixin {
AnimationController animationController;
static var rng = new Random();
double random_number = 0.0;
@override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this,
duration: Duration(seconds: random_number.toInt()),
)..addStatusListener((status) {
if ((status == AnimationStatus.completed) ||
(status == AnimationStatus.dismissed)) {
// custom code here
}
});
}
void move() {
double random_number = (5 +
((rng.nextInt((5 - 1).ceil() * 1000) +
rng.nextInt((30 - 10).ceil() * 1000) +
rng.nextInt((30 - 10).ceil() * 1000) +
rng.nextInt((30 - 10).ceil())) /
4000.0));
double random_number1 = (4 +
((rng.nextInt((5 - 1).ceil() * 1000) +
rng.nextInt((30 - 10).ceil() * 1000) +
rng.nextInt((30 - 10).ceil() * 1000) +
rng.nextInt((30 - 10).ceil())) /
4000.0));
print(random_number);
print("Hello");
print(MediaQuery.of(context).size.height);
print(MediaQuery.of(context).size.width);
animationController.duration = Duration(seconds: random_number.toInt());
animationController.forward(from: -1.0);
animationController.forward();
print(animationController.value);
print(animationController.value * random_number1);
animationController.addListener(() {
this.setState(() {
animationController.addStatusListener((status) {
if ((status == AnimationStatus.dismissed)) {
new Padding(
padding: new EdgeInsets.only(
top: 100.0,
));
return new Text("bla bla bla");
}
});
});
});
}
@override
Widget build(BuildContext context) {
double random_number3 = (60 +
((rng.nextInt((5 - 1).ceil() * 1000) +
rng.nextInt((30 - 10).ceil() * 1000) +
rng.nextInt((30 - 10).ceil() * 1000) +
rng.nextInt((30 - 10).ceil())) /
4000.0));
return new Container(
padding: new EdgeInsets.only(
left: 0.0,
right: 0.0,
bottom: MediaQuery.of(context).size.height -
(39 * MediaQuery.of(context).size.height) / 100),
alignment: Alignment.bottomCenter,
child: new AnimatedBuilder(
animation: animationController,
child: new GestureDetector(
child: new Image.asset('asset/5.png'),
onTap: () {
move();
},
),
builder: (BuildContext context, Widget _widget) {
return new Transform.rotate(
angle: animationController.value * random_number3.toInt(),
child: _widget,
);
},
),
);
}
}
//Animation code Ends from here
class QuestionDisplay extends StatefulWidget {
@override
_QuestionDisplayState createState() => _QuestionDisplayState();
}
class _QuestionDisplayState extends State<QuestionDisplay> {
@override
Widget build(BuildContext context) {
new Padding(
padding: new EdgeInsets.only(
top: 100.0,
));
print("qwerty");
return new Text("123");
}
}