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

Merge branch '8-add-a-mini-game-mode' into 'master'

Resolve "Add a "mini game" mode"

Closes #8

See merge request !8
parents 48d23035 402948df
No related branches found
No related tags found
1 merge request!8Resolve "Add a "mini game" mode"
Pipeline #877 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=1.1.2
app.versionCode=5
app.versionName=1.2.0
app.versionCode=6
import 'package:flutter/material.dart';
import 'dart:math';
import 'dart:async';
void main() {
runApp(MyApp());
......@@ -124,6 +125,8 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
String _randomLetter = '';
String _randomCategory = '';
Timer _timer;
int _start = 10;
void _pickRandomLetter() {
setState(() {
......@@ -137,12 +140,46 @@ class _MyHomePageState extends State<MyHomePage> {
});
}
void _startMiniGame() {
_pickRandomLetter();
_pickRandomCategory();
startTimer();
}
@override
void initState() {
_pickRandomLetter();
_pickRandomCategory();
}
void startTimer() {
const oneSec = const Duration(seconds: 1);
if (_timer != null) {
_timer.cancel();
}
_start = 10;
_timer = new Timer.periodic(
oneSec,
(Timer timer) {
if (_start == 0) {
setState(() {
timer.cancel();
});
} else {
setState(() {
_start--;
});
}
},
);
}
@override
void dispose() {
_timer.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -156,10 +193,6 @@ class _MyHomePageState extends State<MyHomePage> {
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Lettre aléatoire :',
style: Theme.of(context).textTheme.headline4,
),
Text(
'$_randomLetter',
style: Theme.of(context).textTheme.headline2,
......@@ -177,14 +210,10 @@ class _MyHomePageState extends State<MyHomePage> {
),
],
),
SizedBox(height: 50),
SizedBox(height: 20),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Catégorie aléatoire :',
style: Theme.of(context).textTheme.headline4,
),
Text(
'$_randomCategory',
style: Theme.of(context).textTheme.headline3,
......@@ -201,7 +230,27 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
],
)
),
SizedBox(height: 40),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: _startMiniGame,
color: Colors.blue,
padding: EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'$_start',
style: Theme.of(context).textTheme.headline2,
),
],
),
),
],
),
],
),
),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment