Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91125378
Ac7.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
Fri, Nov 8, 04:20
Size
18 KB
Mime Type
text/x-c++
Expires
Sun, Nov 10, 04:20 (2 d)
Engine
blob
Format
Raw Data
Handle
22201398
Attached To
R10646 Orchestration
Ac7.Dart
View Options
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:student/widgets/onlineRobotMap.Dart';
import 'dart:async';
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';
class Ac7 extends StatefulWidget {
Ac7({Key key}) : super(key: key);
@override
_Ac7State createState() => _Ac7State();
}
class _Ac7State extends State<Ac7> with SingleTickerProviderStateMixin {
Timer timerCelluloPosition;
Timer timerslopedetection;
Timer timercleartracking;
Timer timerprevCelluloPosition;
final acID = 7;
bool celluloxSwitch1 = true;
bool celluloySwitch1 = false;
bool celluloxSwitch2 = true;
bool celluloySwitch2 = false;
var onStop = false;
bool mode = 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 controllerinitialX = TextEditingController();
TextEditingController controllerinitialY = TextEditingController();
TextEditingController controllerXslope = TextEditingController();
TextEditingController controllerYslope = TextEditingController();
var counterfunctionImage = 0;
var imagespath = [
'assets/images/function1.svg',
'assets/images/function2.svg',
'assets/images/function3.svg',
'assets/images/Grid.svg',
];
var correctAnswer = [
1,
3,
4,
1,
];
var onTap = [false, false, false, false, false];
// var onTap=[false,false,false,false,false];
final double mapSizeWidth = 860;
final double mapSizeHeight = 860;
var currentTurn = 1;
var currentTap = 0;
var tapCounter = 0;
var progress = 0;
bool waitforanimation = false;
var mistakesSlope = 0;
var mistakesIntrepet = 0;
var inactivity = 0;
var prevcelluloxPositionSlope = 0.0;
var prevcelluloyPositionSlope = 0.0;
// robot related
bool setRun = false;
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];
var prevcelluloxPosition = [0.0, 0.0];
var prevcelluloyPosition = [0.0, 0.0];
var initialPositionCellulox = [0.0, 0.0];
var initialPositionCelluloy = [0.0, 0.0];
// screen-related
var originCoordinates = [303.08, 563.08];
@override
void initState() {
super.initState();
group.numCurrentActivity = 7;
cellulox.resetrobot();
celluloy.resetrobot();
timerCelluloPosition =
new Timer.periodic(new Duration(milliseconds: 400), (time) {
cellulox.getrobotx().then((val) => setState(() {
celluloxPosition[0] = val;
if (setRun == true) {
celluloxPositiontopaint.add(val * 500 / 860);
}
}));
cellulox.getroboty().then((val) => setState(() {
celluloxPosition[1] = val;
if (setRun == true) prevcelluloxPosition[1] = celluloxPosition[1];
}));
celluloy.getrobotx().then((val) => setState(() {
celluloyPosition[0] = val;
if (setRun == true) prevcelluloyPosition[0] = celluloyPosition[0];
}));
celluloy.getroboty().then((val) => setState(() {
celluloyPosition[1] = val;
if (setRun == true) celluloyPositiontopaint.add(val * 500 / 860);
}));
/*
dbRef
.child(group.id)
.child("activity 8")
.child("inactivity")
.push()
.set(inactivity);
dbRef
.child(group.id)
.child("cellulox")
.child("x")
.push()
.set(celluloxPosition);
dbRef
.child(group.id)
.child("cellulox")
.child("y")
.push()
.set(celluloxPosition);
dbRef
.child(group.id)
.child("celluloy")
.child("x")
.push()
.set(celluloyPosition);
dbRef
.child(group.id)
.child("celluloy")
.child("y")
.push()
.set(celluloyPosition);
*/
});
timerprevCelluloPosition =
new Timer.periodic(new Duration(seconds: 40), (time) {
setState(() {
if (setRun == true) {
prevcelluloxPosition[0] = celluloxPosition[0];
prevcelluloxPosition[1] = celluloxPosition[1];
prevcelluloyPosition[0] = celluloyPosition[0];
prevcelluloyPosition[1] = celluloyPosition[1];
}
});
/*
dbRef
.child(group.id)
.child("activity 8")
.child("inactivity")
.push()
.set(inactivity);
dbRef
.child(group.id)
.child("cellulox")
.child("x")
.push()
.set(celluloxPosition);
dbRef
.child(group.id)
.child("cellulox")
.child("y")
.push()
.set(celluloxPosition);
dbRef
.child(group.id)
.child("celluloy")
.child("x")
.push()
.set(celluloyPosition);
dbRef
.child(group.id)
.child("celluloy")
.child("y")
.push()
.set(celluloyPosition);
*/
});
// controller = AnimationController(
// duration: Duration(milliseconds: 10000), vsync: this);
///
/// Ask to be notified when messages related to the game
/// are sent by the server
///
}
void slopeDtectionTimer() {
timerslopedetection = new Timer.periodic(new Duration(seconds: 1), (time) {
print("prev" +
(((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() >
0)
.toString()));
// print("currwnt" + celluloxPosition[0].toString());
controllerXslope.text = 1.0.toString();
if ((celluloxPosition[0] - prevcelluloxPositionSlope).abs() < 10) {
controllerYslope.text = "You sould move the RED robot faster";
} else {
controllerYslope.text =
(((prevcelluloyPositionSlope - celluloyPosition[1])) /
(celluloxPosition[0] - prevcelluloxPositionSlope))
.roundToDouble()
.toString();
}
//showAboutDialog(context,"elseYou sould move the RED robot faster","")
prevcelluloxPositionSlope = celluloxPosition[0];
prevcelluloyPositionSlope = celluloyPosition[1];
// print(int.parse(controllerXslope.text) > 0);
print("cur" +
(((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() >
0)
.toString()));
if ((celluloxPosition[0] - prevcelluloxPositionSlope).roundToDouble() >
1) {
setState(() {
celluloxSwitch2 = true;
print(celluloxSwitch2);
});
}
if (((celluloxPosition[0] - prevcelluloxPositionSlope) / 100)
.roundToDouble() <
-1) {
setState(() {
celluloxSwitch2 = false;
print(celluloxSwitch2);
});
}
if (celluloyPosition[1] - prevcelluloyPositionSlope > 0) {
setState(() {
celluloySwitch2 = true;
print(celluloySwitch2);
});
}
if (celluloyPosition[1] - prevcelluloyPositionSlope < 1.0) {
setState(() {
celluloySwitch2 = false;
print(celluloySwitch2);
});
}
});
}
void clearTrackingTimer() {
timercleartracking = new Timer.periodic(new Duration(seconds: 5), (time) {
cellulox.resetrobot();
celluloy.resetrobot();
setState(() {
setRun = true;
});
timercleartracking.cancel();
});
}
@override
void dispose() {
timer.cancel();
super.dispose();
}
void nextPLayer() {
setState(() {
currentTurn = currentTurn + 1;
// celluloyPositiontopaint = [0.0, 0.0];
// celluloxPositiontopaint = [0.0, 0.0];
});
}
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(
margin: const EdgeInsets.all(15.0),
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent),
borderRadius: new BorderRadius.circular(25.0),
),
height: 150.0,
child: Column(children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
width: 250,
child: new TextFormField(
controller: controllerinitialX,
decoration: new InputDecoration(
labelText: "RED starts at this position:",
fillColor: Colors.red,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
validator: (val) {
if (val.length == 0) {
return "Email cannot be empty";
} else {
return null;
}
},
keyboardType: TextInputType.text,
style: new TextStyle(
fontFamily: "Poppins",
),
),
),
Container(
width: 250,
child: new TextFormField(
controller: controllerinitialY,
decoration: new InputDecoration(
labelText: "BLUE starts at this position:",
fillColor: Colors.blue,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
validator: (val) {
if (val.length == 0) {
return "Email cannot be empty";
} else {
return null;
}
},
keyboardType: TextInputType.text,
style: new TextStyle(
fontFamily: "Poppins",
),
),
),
FloatingActionButton(
onPressed: () => {
slopeDtectionTimer(),
clearTrackingTimer(),
cellulox.setGoalPosition(
originCoordinates[0] +
100 * int.parse(controllerinitialX.text),
celluloxPosition[1]),
celluloy.setGoalPosition(
celluloyPosition[0],
originCoordinates[1] -
100 * int.parse(controllerinitialY.text)),
},
child: Icon(Icons.play_circle_outline),
),
]),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 300,
child: new TextFormField(
enabled: false,
// controller: controllerXslope,
decoration: new InputDecoration(
labelText: "When RED moves by 1",
fillColor: Colors.red,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
validator: (val) {
if (val.length == 0) {
return "Email cannot be empty";
} else {
return null;
}
},
keyboardType: TextInputType.text,
style: new TextStyle(
fontFamily: "Poppins",
),
),
),
Column(children: <Widget>[
Container(
child: Switch(
value: celluloxSwitch1,
onChanged: (value) {
setState(() {
// celluloxSwitch1 = value;
});
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
inactiveTrackColor: Colors.lightGreenAccent,
inactiveThumbColor: Colors.green,
)),
Text(celluloxSwitch1 ? 'Right' : 'Left')
]),
SizedBox(width: 20),
Container(
width: 300,
child: new TextFormField(
decoration: new InputDecoration(
labelText: "Then Blue should move by:",
fillColor: Colors.blue,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
validator: (val) {
if (val.length == 0) {
return "Email cannot be empty";
} else {
return null;
}
},
keyboardType: TextInputType.text,
style: new TextStyle(
fontFamily: "Poppins",
),
)),
Column(children: <Widget>[
RotatedBox(
quarterTurns: 1,
child: Switch(
value: celluloySwitch1,
onChanged: (value) {
setState(() {
celluloySwitch1 = value;
});
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
inactiveTrackColor: Colors.lightGreenAccent,
inactiveThumbColor: Colors.green,
)),
Text(celluloySwitch1 ? 'Down' : 'Up')
]),
]),
])),
SizedBox(
height: 5,
),
celluloMap(context),
SizedBox(
height: 10,
),
MembersBar(),
])));
}
Widget celluloMap(BuildContext context) {
final double mapSizeScreenWidth = 500;
final double mapSizeScreenHeight = 500;
final double scaleWidth = mapSizeScreenWidth / mapSizeWidth;
final double scaleHeight = mapSizeScreenHeight / mapSizeHeight;
return Container(
height: mapSizeScreenWidth,
width: mapSizeScreenHeight,
decoration: BoxDecoration(border: Border.all(color: Colors.blueAccent)),
child: Stack(children: <Widget>[
Container(
height: mapSizeScreenWidth,
width: mapSizeScreenHeight,
child: SvgPicture.asset(imagespath[currentTurn - 1])),
Container(
height: mapSizeScreenWidth,
width: mapSizeScreenHeight,
child: SvgPicture.asset("assets/images/GridOnlyPositive.svg")),
Align(
alignment: Alignment(
2 * (celluloxPosition[0] * scaleWidth / mapSizeScreenWidth) - 1,
1),
child: Card(
child: SvgPicture.asset("assets/images/cellulox.svg",
height: 60, width: 60),
),
),
Align(
alignment: Alignment(
-1,
2 * (celluloyPosition[1] * scaleHeight / mapSizeScreenHeight) -
1),
child: Card(
child: SvgPicture.asset("assets/images/celluloy.svg",
height: 60, width: 60),
),
),
CustomPaint(
size: Size(mapSizeScreenWidth, mapSizeScreenHeight),
painter:
LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint),
),
]));
}
}
Event Timeline
Log In to Comment