Page MenuHomec4science

Ac6.dart
No OneTemporary

File Metadata

Created
Wed, Jun 12, 14:41

Ac6.dart

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:student/widgets/onlineRobotMap.Dart';
import 'package:student/widgets/celluloMap.Dart';
import 'dart:async';
import 'dart:convert';
import 'package:student/Database.dart';
import 'package:student/model/Group.dart';
import 'package:student/model/Cellulo.dart';
import 'package:student/widgets/showAlertDialog.Dart';
import 'package:student/widgets/membersBar.Dart';
import 'package:student/widgets/inactivityDetector.Dart';
import 'package:flutter_appavailability/flutter_appavailability.dart';
class Ac6 extends StatefulWidget {
Ac6({Key key}) : super(key: key);
@override
_Ac6State createState() => _Ac6State();
}
class _Ac6State extends State<Ac6> with SingleTickerProviderStateMixin {
// Activity_Independent
var elapseTimer = new Stopwatch();
Timer timerCelluloPosition;
// Cellulo
var celluloxPosition = [0.0, 0.0];
var celluloyPosition = [0.0, 0.0];
List<double> celluloxPositiontopaint = [0.0, 0.0];
List<double> celluloyPositiontopaint = [0.0, 0.0];
bool addtoprint;
AnimationController controllerRobotPath;
Animation<double> animationRobotPath;
// group
int currentTurn = 1;
int simulationVelCoeff = 1;
int numAttempts = 0;
var numAttemptsTurn = [0, 0, 0];
var progress = [0, -2, -2];
var elpasedTimeTurn = [0, 0, 0];
int elpasedTimeTotal = 0;
// Learning
List<int> mistakesSlope = [0, 0, 0];
List<int> mistakesIntercept = [0, 0, 0];
List<int> mistakesInitialPosition = [0, 0, 0];
//Activity Dependent
String activityTitle = 'Activity 6';
var linesPath = [
'assets/images/Ac7_function1.svg',
'assets/images/Ac7_function2.svg',
'assets/images/Ac7_function3.svg',
'assets/images/GridOnlyPositive.svg',
];
var correctAnswer = [
{"initialPointX": 0, "initialPointY": 0, "slope": 1},
{"initialPointX": 0, "initialPointY": 1, "slope": 1},
{"initialPointX": 0, "initialPointY": 0, "slope": 2}
];
// map-related
final double mapSizeWidth = 860;
final double mapSizeHeight = 860;
final String mapPath = 'assets/images/GridOnlyPositive.svg';
var originCoordinates = [303.08, 563.08];
@override
void initState() {
super.initState();
dbRef.child('groups').child(group.id).child('tabletStatus').set("YES");
dbRef.child('groups').child(group.id).child('currentActivity').set("Ac6");
elapseTimer.start();
timerCelluloPosition =
new Timer.periodic(new Duration(milliseconds: 500), (time) {
if (totalRobots() > 1) {
cellulox.getrobotx().then((val) => setState(() {
if (val != null) {
celluloxPosition[0] = val;
if (addtoprint == true)
celluloxPositiontopaint.add(val * 500 / mapSizeWidth);
}
// print(addtoprint.toString());
}));
cellulox.getroboty().then((val) => setState(() {
if (val != null) {
celluloxPosition[1] = val;
}
}));
celluloy.getrobotx().then((val) => setState(() {
if (val != null) {
celluloyPosition[0] = val;
}
}));
celluloy.getroboty().then((val) => setState(() {
if (val != null) {
celluloyPosition[1] = val;
if (addtoprint == true)
celluloyPositiontopaint.add(val * 500 / mapSizeHeight);
}
}));
if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) {
cellulox.setVelocity(0, 0);
celluloy.setVelocity(0, 0);
}
}
});
controllerRobotPath = AnimationController(
duration: Duration(milliseconds: 30000), vsync: this);
animationRobotPath =
Tween(begin: 0.0, end: 1.0).animate(controllerRobotPath)
..addListener(() {
var _progress = animationRobotPath.value;
if (_progress > 0.22) {
print('quelque-chode');
setState(() {
addtoprint = true;
});
}
if (_progress == 1.0) {
// cellulox.setGoalPosition(770, 600);
// celluloy.setGoalPosition(100, 80);
cellulox.setVelocity(0, 0);
celluloy.setVelocity(0, 0);
}
if (celluloxPosition[0] > 800 ||
celluloyPosition[1] < 50 ||
celluloyPosition[1] > 800) {
cellulox.setVelocity(0, 0);
celluloy.setVelocity(0, 0);
}
});
}
@override
void dispose() {
cellulox.resetrobot();
celluloy.resetrobot();
elapseTimer.stop();
super.dispose();
}
void onDataSend() {
dbRef.child('attempts').push().set(json.encode({
"numAttempts": numAttempts,
"groupID": group.id,
"acID": "Ac7",
"elpasedTime": elapseTimer.elapsedMilliseconds -
elpasedTimeTurn[currentTurn - 1],
"progress": {
"turn1": progress[0],
"turn2": progress[1],
"turn3": progress[2]
},
"progressElpasedTime": {
"turn1": elpasedTimeTurn[0],
"turn2": elpasedTimeTurn[1],
"turn3": elpasedTimeTurn[2],
},
"currentTurn": currentTurn,
"mistakes": {
"turn1": {
"slope": mistakesSlope[0],
"intercept": mistakesIntercept[0]
},
"turn2": {
"slope": mistakesSlope[1],
"intercept": mistakesIntercept[1]
},
"turn3": {
"slope": mistakesSlope[2],
"intercept": mistakesIntercept[1]
},
}
}));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Activity 7: Semi-Mathematical Control'),
),
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Column(children: <Widget>[
Card(
child: ListTile(
title: Text(
'Choose the two points that your robots start from there and also how much the blue robot should move. '),
),
),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(100)),
color: Colors.blue),
child: FlatButton(
child: Text(
"Run Robots",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 18),
),
// tooltip: 'Run the Robots',
onPressed: () => {
{
cellulox.setGoalPosition(originCoordinates[0], 600),
celluloy.setGoalPosition(100, originCoordinates[1]),
controllerRobotPath.reset(),
controllerRobotPath.forward(),
}
},
)),
SizedBox(width: 20),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(100)),
color: Colors.blue),
child: FlatButton(
child: Text(
"Next Turn",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 18),
),
onPressed: () => {},
)),
]),
),
celluloMap(
context,
celluloxPositiontopaint,
celluloyPositiontopaint,
celluloxPosition,
celluloyPosition,
mapPath,
linesPath[currentTurn - 1],
mapSizeWidth,
mapSizeHeight),
SizedBox(
height: 15,
),
MembersBar(),
])));
}
}

Event Timeline