Page MenuHomec4science

Ac8.Dart
No OneTemporary

File Metadata

Created
Sat, Aug 17, 19:21

Ac8.Dart

import 'package:flutter/material.dart';
import 'package:student/SoCKet.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'dart:convert';
import 'package:student/widgets/linePainter.Dart';
class Ac8 extends StatefulWidget {
Ac8({Key key}) : super(key: key);
@override
_Ac8State createState() => _Ac8State();
}
class _Ac8State extends State<Ac8> with SingleTickerProviderStateMixin {
final acID = 8;
double _progress = 0.0;
final celluloSize = 60;
final functionFormulas = [
'X -> Y',
'X+1 -> Y',
'X+2 -> Y',
'2*X -> Y',
'-X -> Y'
];
Offset beginpath = Offset(0, 0);
Offset endpath = Offset(10, 100);
AnimationController controller;
Animation<double> animation;
TextEditingController controller1 = TextEditingController();
TextEditingController controller2 = TextEditingController();
TextEditingController controller3 = TextEditingController();
var counterfunctionImage = 0;
var imagespath = [
'assets/images/function1.svg',
'assets/images/function2.svg',
'assets/images/function3.svg'
];
var correctAnswer = [
1,
3,
4,
];
var currentTurn = 1;
var currentTap = 0;
var tapCounter = 0;
var progress = 0;
var mistakesSlopematrix = [
[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[1, 1, 1, 0, 1]
];
var mistakesIntrepetmatrix = [
[0, 1, 1, 0, 0],
[1, 1, 0, 1, 1],
[0, 1, 1, 0, 0]
];
var mistakesSlope = 0;
var mistakesIntrepet = 0;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: Duration(milliseconds: 10000), vsync: this);
///
/// Ask to be notified when messages related to the game
/// are sent by the server
///
websocket.addListener(_onDataReceived);
}
_onDataReceived(message) {
Map<String, dynamic> messageparse = jsonDecode(message);
switch (messageparse['action']) {
///
/// The opponent resigned, so let's leave this screen
///
case 'identity':
break;
}
// force rebuild
// setState(() {});
}
_onCorrectAnswer() {
debugPrint(currentTurn.toString());
currentTurn = currentTurn + 1;
if (currentTurn >= 4) {
debugPrint("currentTurn.toString()");
currentTurn = 1;
}
debugPrint(currentTurn.toString());
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cellulo Game'),
),
backgroundColor: Colors.white,
body: Column(children: <Widget>[
Container(
height: 200.0,
child: ListView(
children: <Widget>[
Card(
child: ListTile(
title: Text(
'Choose the option that describes the blue line, you have only THREE choices:'),
),
),
Card(
child: ListTile(
onTap: () {
currentTap = 1;
if (currentTap == correctAnswer[currentTurn - 1]) {
_onCorrectAnswer();
}
beginpath = Offset(150, 430);
endpath = Offset(540, 40);
controller.reset();
animation =
Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
_progress = animation.value;
});
});
controller.forward();
tapCounter = tapCounter + 1;
mistakesSlope = mistakesSlope +
mistakesSlopematrix[currentTurn - 1]
[currentTap - 1];
mistakesIntrepet = mistakesIntrepet +
mistakesIntrepetmatrix[currentTurn - 1]
[currentTap - 1];
websocket.send(json.encode({
"action": "progress_update",
"ID": student_ID,
"AcID": acID,
"data": {
"progress": currentTurn,
"totalTaps": tapCounter,
"inactivity": 0,
"mistakesSlope": mistakesSlope,
"mistakesIntrepet": mistakesIntrepet,
}
}));
setState(() {});
},
leading: Icon(Icons.play_circle_outline),
title: Text(functionFormulas[0]),
trailing: Icon(Icons.more_vert),
),
),
Card(
child: ListTile(
onTap: () {
currentTap = 2;
if (currentTap == correctAnswer[currentTurn - 1]) {
_onCorrectAnswer();
}
beginpath = Offset(100, 432);
endpath = Offset(480, 52);
controller.reset();
animation =
Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
_progress = animation.value;
});
});
controller.forward();
tapCounter = tapCounter + 1;
mistakesSlope = mistakesSlope +
mistakesSlopematrix[currentTurn - 1]
[currentTap - 1];
mistakesIntrepet = mistakesIntrepet +
mistakesIntrepetmatrix[currentTurn - 1]
[currentTap - 1];
websocket.send(json.encode({
"action": "progress_update",
"ID": student_ID,
"AcID": acID,
"data": {
"progress": currentTurn,
"totalTaps": tapCounter,
"inactivity": 0,
"mistakesSlope": mistakesSlope,
"mistakesIntrepet": mistakesIntrepet,
}
}));
// setState(() {});
},
leading: Icon(Icons.play_circle_outline),
title: Text(functionFormulas[1]),
trailing: Icon(Icons.more_vert),
),
),
Card(
child: ListTile(
onTap: () {
currentTap = 3;
if (currentTap == correctAnswer[currentTurn - 1]) {
_onCorrectAnswer();
}
beginpath = Offset(100, 390);
endpath = Offset(480, 10);
controller.reset();
animation =
Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
_progress = animation.value;
});
});
controller.forward();
tapCounter = tapCounter + 1;
mistakesSlope = mistakesSlope +
mistakesSlopematrix[currentTurn - 1]
[currentTap - 1];
mistakesIntrepet = mistakesIntrepet +
mistakesIntrepetmatrix[currentTurn - 1]
[currentTap - 1];
websocket.send(json.encode({
"action": "progress_update",
"ID": student_ID,
"AcID": acID,
"data": {
"progress": currentTurn,
"totalTaps": tapCounter,
"inactivity": 0,
"mistakesSlope": mistakesSlope,
"mistakesIntrepet": mistakesIntrepet,
}
}));
/* react to the tile being tapped */
},
leading: Icon(Icons.play_circle_outline),
title: Text(functionFormulas[2]),
trailing: Icon(Icons.more_vert),
),
),
Card(
child: ListTile(
onTap: () {
currentTap = 4;
if (currentTap == correctAnswer[currentTurn - 1]) {
_onCorrectAnswer();
}
beginpath = Offset(215, 490);
endpath = Offset(425, 40);
controller.reset();
animation =
Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
_progress = animation.value;
});
});
controller.forward();
tapCounter = tapCounter + 1;
mistakesSlope = mistakesSlope +
mistakesSlopematrix[currentTurn - 1]
[currentTap - 1];
mistakesIntrepet = mistakesIntrepet +
mistakesIntrepetmatrix[currentTurn - 1]
[currentTap - 1];
websocket.send(json.encode({
"action": "progress_update",
"ID": student_ID,
"AcID": acID,
"data": {
"progress": currentTurn,
"totalTaps": tapCounter,
"inactivity": 0,
"mistakesSlope": mistakesSlope,
"mistakesIntrepet": mistakesIntrepet,
}
}));
/* react to the tile being tapped */
},
leading: Icon(Icons.play_circle_outline),
title: Text(functionFormulas[3]),
trailing: Icon(Icons.more_vert),
),
),
Card(
child: ListTile(
onTap: () {
currentTap = 5;
if (currentTap == correctAnswer[currentTurn - 1]) {
_onCorrectAnswer();
}
beginpath = Offset(110, 50);
endpath = Offset(500, 430);
controller.reset();
animation =
Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
_progress = animation.value;
});
});
controller.forward();
/* react to the tile being tapped */
tapCounter = tapCounter + 1;
mistakesSlope = mistakesSlope +
mistakesSlopematrix[currentTurn - 1]
[currentTap - 1];
mistakesIntrepet = mistakesIntrepet +
mistakesIntrepetmatrix[currentTurn - 1]
[currentTap - 1];
websocket.send(json.encode({
"action": "progress_update",
"ID": student_ID,
"AcID": acID,
"data": {
"progress": currentTurn,
"totalTaps": tapCounter,
"inactivity": 0,
"mistakesSlope": mistakesSlope,
"mistakesIntrepet": mistakesIntrepet,
}
}));
},
leading: Icon(Icons.play_circle_outline),
title: Text(functionFormulas[4]),
trailing: Icon(Icons.more_vert),
),
),
],
)),
SizedBox(
height: 100,
),
Container(
height: 500,
width: 700,
child: Stack(children: <Widget>[
Container(
height: 700,
width: 700,
child: SvgPicture.asset(imagespath[currentTurn - 1])),
Container(
height: 700,
width: 700,
child: SvgPicture.asset("assets/images/Grid.svg")),
Align(
alignment: Alignment(-0.75 + _progress * (1.1), 0),
child: Card(
child: SvgPicture.asset("assets/images/cellulox.svg",
height: 60, width: 60),
),
),
Align(
alignment: Alignment(-0.07, 0.65 + _progress * (-1.65)),
child: Card(
child: SvgPicture.asset("assets/images/celluloy.svg",
height: 60, width: 60),
),
),
CustomPaint(
// <-- CustomPaint widget
size: Size(300, 500),
painter: LinePainter(_progress, beginpath, endpath),
),
]))
]));
}
}

Event Timeline