Skip to content
Snippets Groups Projects
Commit 5545c7f4 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Animate while picking next move

parent 26a2a3f9
No related branches found
No related tags found
1 merge request!16Resolve "Add animations"
Pipeline #4815 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.14
app.versionCode=14
app.versionName=0.0.15
app.versionCode=15
Animate while picking next move.
Animation pendant la sélection du prochain mouvement.
import 'dart:async';
import 'dart:math';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
......@@ -15,14 +18,43 @@ class Game extends StatefulWidget {
class _GameState extends State<Game> {
final player = AudioPlayer();
bool shuffling = false;
Move? shuffledMove;
@override
Widget build(BuildContext context) {
return BlocBuilder<GameCubit, GameState>(
builder: (BuildContext context, GameState gameState) {
return GestureDetector(
child: ShowMove(move: gameState.move ?? Move.createNull()),
onTap: () {
void animate() {
const interval = const Duration(milliseconds: 200);
int iterationsLeft = 10;
shuffling = true;
shuffledMove = null;
setState(() {});
Timer.periodic(
interval,
(Timer timer) {
if (iterationsLeft > 1) {
shuffledMove = Move.pickRandom();
}
if (iterationsLeft == 1) {
shuffledMove = null;
}
if (iterationsLeft == 0) {
shuffledMove = null;
pickNewMove();
timer.cancel();
shuffling = false;
}
setState(() {});
iterationsLeft--;
},
);
}
void pickNewMove() {
Move newMove = Move.pickRandom();
BlocProvider.of<GameCubit>(context).setValues(
......@@ -30,6 +62,21 @@ class _GameState extends State<Game> {
);
player.play(AssetSource(newMove.toSoundAsset()));
}
@override
Widget build(BuildContext context) {
return BlocBuilder<GameCubit, GameState>(
builder: (BuildContext context, GameState gameState) {
return GestureDetector(
child: shuffling
? Transform.rotate(
angle: 2 * pi * Random().nextDouble(),
child: ShowMove(move: shuffledMove ?? Move.createNull()),
)
: ShowMove(move: gameState.move ?? Move.createNull()),
onTap: () {
animate();
},
);
},
......
......@@ -3,7 +3,7 @@ description: twister game companion
publish_to: 'none'
version: 0.0.14+14
version: 0.0.15+15
environment:
sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment