Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63544750
Ac8.Dart
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, May 20, 21:45
Size
17 KB
Mime Type
text/x-c++
Expires
Wed, May 22, 21:45 (2 d)
Engine
blob
Format
Raw Data
Handle
17786220
Attached To
R10646 Orchestration
Ac8.Dart
View Options
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'dart:convert';
import 'dart:core';
import 'package:student/widgets/linePainter.Dart';
import 'dart:async';
import 'package:student/Data/data.dart';
import 'package:student/Database.dart';
import 'package:student/model/Group.dart';
import 'package:student/widgets/showAlertDialog.Dart';
import 'package:student/widgets/membersBar.Dart';
import 'package:student/model/Cellulo.dart';
class Ac8 extends StatefulWidget {
Ac8({Key key}) : super(key: key);
@override
_Ac8State createState() => _Ac8State();
}
class _Ac8State extends State<Ac8>
with SingleTickerProviderStateMixin, WidgetsBindingObserver {
//Learning Parameters
// UI parameters
// Cellulo Simulation Parameters
Timer timer;
final acID = 8;
final acIDstring = 'Ac8';
var onStop = false;
int wrongcounts = 0;
double _progress = 0.0;
final celluloSize = 60;
final ScrollController _scrollController = ScrollController();
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();
List<int> mistakesSlope = [0, 0, 0];
List<int> mistakesIntercept = [0, 0, 0];
List<int> mistakesInitialPosition = [0, 0, 0];
List<int> progressElpasedTime = [0, 0, 0];
var counterfunctionImage = 0;
var imagespath = [
'assets/images/Ac8_function1.svg',
'assets/images/Ac8_function2.svg',
'assets/images/Ac8_function3.svg',
'assets/images/Grid_Ac8_Screen.svg',
];
var correctAnswer = [
1,
3,
4,
4,
4,
];
var onTap = [false, false, false, false, false];
// var onTap=[false,false,false,false,false];
static var originCoordinates = [427.3, 429.3];
List<Offset> beginpathlist = [
Offset(originCoordinates[0] - 300, originCoordinates[1] + 300),
Offset(originCoordinates[0] - 300, originCoordinates[1] + 200),
Offset(originCoordinates[0] - 300, originCoordinates[1] + 100),
Offset(originCoordinates[0] - 200, originCoordinates[1] + 400),
Offset(originCoordinates[0] - 300, originCoordinates[1] - 300),
];
List<Offset> endpathlist = [
Offset(originCoordinates[0] + 300, originCoordinates[1] - 300),
Offset(originCoordinates[0] + 300, originCoordinates[1] - 400),
Offset(originCoordinates[0] + 200, originCoordinates[1] - 400),
Offset(originCoordinates[0] + 200, originCoordinates[1] - 400),
Offset(originCoordinates[0] + 300, originCoordinates[1] + 300),
];
var currentTurn = 1;
var currentTap = 0;
var tapCounter = 0;
List<int> progress = [0, -2, -2];
bool waitforanimation = false;
var mistakesSlopematrix = [
[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[1, 1, 1, 0, 1]
];
var mistakesInterceptmatrix = [
[0, 1, 1, 0, 0],
[1, 1, 0, 1, 1],
[0, 1, 1, 0, 0]
];
var inactivity = 0;
var elapseTimer = new Stopwatch();
AppLifecycleState _notification;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
dbRef.child('groups').child(group.id).child('tabletStatus').set("YES");
} else {
dbRef.child('groups').child(group.id).child('tabletStatus').set("NO");
}
setState(() {
_notification = state;
});
}
@override
void initState() {
cellulox.setColor(0, 255, 0, 0, 0);
celluloy.setColor(0, 0, 255, 0, 0);
cellulox.clearrobot();
celluloy.clearrobot();
WidgetsBinding.instance.addObserver(this);
elapseTimer.start();
dbRef.child('groups').child(group.id).child('tabletStatus').set("YES");
dbRef.child('groups').child(group.id).child('currentActivity').set("Ac8");
onDataSend();
super.initState();
// group.numCurrentActivity = 8;
controller = AnimationController(
duration: Duration(milliseconds: 7000), vsync: this);
///
/// Ask to be notified when messages related to the game
/// are sent by the server
///
inactivityDtectionTimer();
}
@override
void dispose() {
elapseTimer.stop();
timer.cancel();
super.dispose();
}
void onDataSend() {
print(mistakesSlope);
dbRef.child('attempts').push().set(json.encode({
"numAttempts": tapCounter,
"groupID": group.id,
"acID": acIDstring,
"elpasedTime": elapseTimer.elapsedMilliseconds -
progressElpasedTime[currentTurn - 1],
"progress": {
"turn1": progress[0],
"turn2": progress[1],
"turn3": progress[2]
},
"progressElpasedTime": {
"turn1": progressElpasedTime[0],
"turn2": progressElpasedTime[1],
"turn3": progressElpasedTime[2],
},
"currentTurn": currentTurn,
"mistakes": {
"turn1": {
"slope": mistakesSlope[0],
"initialPoint": mistakesInitialPosition[0],
"intercept": mistakesIntercept[0]
},
"turn2": {
"slope": mistakesSlope[1],
"initialPoint": mistakesInitialPosition[1],
"intercept": mistakesIntercept[1]
},
"turn3": {
"slope": mistakesSlope[2],
"initialPoint": mistakesInitialPosition[2],
"intercept": mistakesIntercept[2]
},
}
}));
}
_onCorrectAnswer(BuildContext context) {
if (currentTurn <= 3) {
showAlertDialog(context, 'Congrats',
'your answer was correct. Now its next player turn');
currentTurn = currentTurn + 1;
}
print(currentTurn);
if (currentTurn > 3) {
setState(() {
waitforanimation = false;
});
showAlertDialog(context, 'The Game has Finished', '');
// Navigator.pushNamed(context, '/second');
}
onTap = [false, false, false, false, false];
}
_onWrongAnswer(BuildContext context) {
// _onCorrectAnswer();
// play the animation
// go to next player
debugPrint("wroganswer");
wrongcounts = 0;
// debugPrint(currentTurn.toString());
// currentTurn = currentTurn + 1;
if (currentTurn >= 4) {
//currentTurn = 1;
}
// debugPrint(currentTurn.toString());
}
void inactivityDtectionTimer() {
timer = new Timer.periodic(new Duration(seconds: 10), (time) {
inactivity = inactivity + 1;
// dbRefonTapAll
// .child(group.id)
// .child("activity 8")
//.child("inactivity")
// .push()
// .set(inactivity);
});
// Start the periodic timer which prints something every 1 seconds
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Simulate your robot'),
),
backgroundColor: Colors.white,
body: Builder(
builder: (context) => SingleChildScrollView(
child: Column(children: <Widget>[
Card(
color: Colors.blue,
child: ListTile(
title: Text(
'Choose the option that matches with the red line, try to :',
style: new TextStyle(
color: Colors.white,
),
),
),
),
Container(
margin: const EdgeInsets.all(15.0),
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(border: Border.all()),
height: 250.0,
child: Scrollbar(
controller: _scrollController,
isAlwaysShown: true,
child: Container(
child: ListView.builder(
controller: _scrollController,
itemCount: 5,
itemBuilder: (context, int position) {
return Card(
child: ListTile(
onTap: () {
if (!waitforanimation) {
// Find the Scaffold in the widget tree and use
// it to show a SnackBar.
// timer.cancel();
// inactivityDtectionTimer();
currentTap = position + 1;
//inactivity = inactivity - 1;
onTap[currentTap - 1] = true;
setState(() {
beginpath = beginpathlist[position];
endpath = endpathlist[position];
});
controller.reset();
tapCounter = tapCounter + 1;
animation = Tween(begin: 0.0, end: 1.0)
.animate(controller)
..addListener(() {
setState(() {
_progress = animation.value;
});
})
..addStatusListener(
(AnimationStatus status) {
if (status ==
AnimationStatus.completed) {
waitforanimation = false;
if (currentTap ==
correctAnswer[
currentTurn - 1]) {
if (currentTurn < 3) {
progress[currentTurn - 1] = 1;
progress[currentTurn] = 0;
}
tapCounter = 0;
_onCorrectAnswer(context);
// controller.reverse();
endpath = beginpath;
}
//print('completed');
} else {
waitforanimation = true;
}
});
controller.forward();
mistakesSlope[currentTurn - 1] =
mistakesSlope[currentTurn - 1] +
mistakesSlopematrix[currentTurn - 1]
[currentTap - 1];
mistakesIntercept[currentTurn - 1] =
mistakesIntercept[currentTurn - 1] +
mistakesInterceptmatrix[
currentTurn - 1]
[currentTap - 1];
setState(() {});
if (currentTap ==
correctAnswer[currentTurn - 1]) {
if (currentTurn < 3) {
progress[currentTurn - 1] = 1;
progress[currentTurn] = 0;
tapCounter = 0;
}
}
onDataSend();
}
},
leading: (currentTap == position + 1)
? ((_progress > 0 && _progress < 1)
? Icon(Icons.pause_circle_filled)
: Icon(Icons.play_circle_filled))
: Icon(Icons.play_circle_filled),
title: Text(functionFormulas[position],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
)),
trailing: onTap[position]
? (position ==
correctAnswer[currentTurn - 1] - 1)
? Icon(Icons.check_circle)
: Icon(Icons.cancel)
: Icon(Icons.more_vert),
),
);
},
))),
),
SizedBox(
height: 20,
),
Container(
height: 500,
width: 500,
// decoration: BoxDecoration(border: Border.all()),
child: Stack(children: <Widget>[
Container(
height: 500,
width: 500,
child:
SvgPicture.asset(imagespath[currentTurn - 1])),
Container(
height: 500,
width: 500,
child: SvgPicture.asset(
"assets/images/Grid_Ac8_Screen.svg")),
Align(
alignment: Alignment(
2 *
(beginpath.dx +
_progress *
(endpath.dx - beginpath.dx)) /
860 -
1,
0),
child: Card(
child: SvgPicture.asset(
"assets/images/cellulox.svg",
height: 48,
width: 48),
),
),
Align(
alignment: Alignment(
-0.07,
2 *
(beginpath.dy +
_progress *
(endpath.dy - beginpath.dy)) /
860 -
1),
child: Card(
child: SvgPicture.asset(
"assets/images/celluloy.svg",
height: 48,
width: 48),
),
),
Align(
alignment: Alignment(
2 *
(beginpath.dx +
_progress *
(endpath.dx - beginpath.dx)) /
860 -
1,
2 *
(beginpath.dy +
_progress *
(endpath.dy - beginpath.dy)) /
860 -
1),
child: Card(
child: SvgPicture.asset(
"assets/images/celluloPurple.svg",
height: 48,
width: 48),
),
),
CustomPaint(
size: Size(500, 500),
painter: LinePainter(_progress, beginpath, endpath),
),
Align(
alignment: Alignment(1, 0.1),
child: Text(
'X',
style: new TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
Align(
alignment: Alignment(0.05, -1),
child: Text(
'Y',
style: new TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
])),
SizedBox(
height: 20,
),
MembersBar(
curTurn: currentTurn,
),
]))));
}
}
Event Timeline
Log In to Comment