diff --git a/Dashboard/lib/model/Class.dart b/Dashboard/lib/model/Class.dart index e867015..797ee9d 100644 --- a/Dashboard/lib/model/Class.dart +++ b/Dashboard/lib/model/Class.dart @@ -1,200 +1,203 @@ import 'package:firebase_database/firebase_database.dart'; import 'package:Teacher_Dashboard/model/Group.dart'; import 'package:flutter/widgets.dart'; import 'package:Teacher_Dashboard/model/Group.dart'; import 'package:Teacher_Dashboard/model/activities/activity.Dart'; import 'dart:async'; import 'dart:convert'; Classroom thisClass = new Classroom("1"); class Classroom extends ChangeNotifier { int inactivity; String sessionID = 'SPIA'; String teacherName; int numGroups = 0; List groups = new List(); List groupIDs = new List(); Classroom(this.sessionID); final FirebaseDatabase _database = FirebaseDatabase.instance; StreamSubscription _ongroupAddedSubscription; StreamSubscription _ongroupChangedSubscription; StreamSubscription _onattemptAddedSubscription; StreamSubscription _oninactivityAddedSubscription; StreamSubscription _onrobotpositionAddedSubscription; void toAggregate() {} void desetupDatabse() { _ongroupAddedSubscription.cancel(); _ongroupChangedSubscription.cancel(); _onattemptAddedSubscription.cancel(); + notifyListeners(); } void setupDatabse() { _ongroupAddedSubscription = _database .reference() .child(thisClass.sessionID) .child("groups") .onChildAdded .listen(onGroupAdded); _ongroupChangedSubscription = _database .reference() .child(thisClass.sessionID) .child("groups") .onChildChanged .listen(onGroupChanged); _onattemptAddedSubscription = _database .reference() .child(thisClass.sessionID) .child("attempts") .onChildAdded .listen(onAttemptAdded); _oninactivityAddedSubscription = _database .reference() .child(thisClass.sessionID) .child("celluloPosition") .onChildAdded .listen(oncelluloPositionAdded); //Query _todoQuery; } onGroupAdded(Event event) { Group newgroup = new Group(event.snapshot.value['id']); newgroup.member1name = event.snapshot.value['member1name']; newgroup.member2name = event.snapshot.value['member2name']; newgroup.member3name = event.snapshot.value['member3name']; thisClass.groups.add(newgroup); thisClass.groupIDs.add(event.snapshot.value['id']); notifyListeners(); } onGroupChanged(Event event) { //thisClass.groups.add(Group.fromSnapshot(event.snapshot)); int currentGroup = thisClass.groupIDs.indexOf(event.snapshot.key); // print("group" + currentGroup.toString().toString()); thisClass.groups[currentGroup].currentActivity = (event.snapshot.value)['currentActivity'].toString(); thisClass.groups[currentGroup].tabletStatus = (event.snapshot.value)['tabletStatus'].toString(); // setState(() {}); notifyListeners(); //print(thisClass.groups[currentGroup].currentActivity.toString()); } onAttemptAdded(Event event) { // print(jsonDecode(event.snapshot.value)['acID'].toString()); int currentGroup = thisClass.groupIDs.indexOf(jsonDecode(event.snapshot.value)['groupID']); int currentActivity = acList.indexOf(jsonDecode(event.snapshot.value)['acID'].toString()); thisClass.groups[currentGroup].currentActivity = acList[currentActivity]; int currentTurn = (jsonDecode(event.snapshot.value)['currentTurn']); thisClass .groups[currentGroup] .activities[currentActivity] .turns[currentTurn - 1] .numAttempts = jsonDecode(event.snapshot.value)['numAttempts']; thisClass.groups[currentGroup].activities[currentActivity].elapsedTime = jsonDecode(event.snapshot.value)['elpasedTime']; thisClass .groups[currentGroup] .activities[currentActivity] .turns[currentTurn - 1] .elapsedTime = jsonDecode(event.snapshot.value)['elpasedTime']; //print(jsonDecode(event.snapshot.value)['elpasedTime']); var progressmsg = jsonDecode((event.snapshot.value))['progress']; thisClass.groups[currentGroup].activities[currentActivity].progress[0] = progressmsg['turn1']; thisClass.groups[currentGroup].activities[currentActivity].progress[1] = progressmsg['turn2']; thisClass.groups[currentGroup].activities[currentActivity].progress[2] = progressmsg['turn3']; var mistakemsg = jsonDecode(event.snapshot.value)['mistakes']; var mistakemsgturn1 = (mistakemsg['turn1']); var mistakemsgturn2 = (mistakemsg['turn2']); var mistakemsgturn3 = (mistakemsg['turn3']); thisClass.groups[currentGroup].activities[currentActivity].mistakes['slope'] [0] = mistakemsgturn1['slope']; thisClass.groups[currentGroup].activities[currentActivity] .mistakes['initialPoint'][0] = mistakemsgturn1['initialPoint']; thisClass.groups[currentGroup].activities[currentActivity].mistakes['slope'] [1] = mistakemsgturn2['slope']; thisClass.groups[currentGroup].activities[currentActivity] .mistakes['initialPoint'][1] = mistakemsgturn2['initialPoint']; thisClass.groups[currentGroup].activities[currentActivity].mistakes['slope'] [2] = mistakemsgturn3['slope']; thisClass.groups[currentGroup].activities[currentActivity] .mistakes['initialPoint'][2] = mistakemsgturn3['initialPoint']; thisClass.groups[currentGroup].activities[currentActivity].turns[0] .mistakes['slope'] = mistakemsgturn1['slope']; thisClass.groups[currentGroup].activities[currentActivity].turns[0] .mistakes['initialPoint'] = mistakemsgturn1['initialPoint']; thisClass.groups[currentGroup].activities[currentActivity].turns[0] .mistakes['intercept'] = mistakemsgturn1['intercept']; thisClass.groups[currentGroup].activities[currentActivity].turns[1] .mistakes['slope'] = mistakemsgturn2['slope']; thisClass.groups[currentGroup].activities[currentActivity].turns[1] .mistakes['initialPoint'] = mistakemsgturn2['initialPoint']; thisClass.groups[currentGroup].activities[currentActivity].turns[1] .mistakes['intercept'] = mistakemsgturn2['intercept']; thisClass.groups[currentGroup].activities[currentActivity].turns[2] .mistakes['slope'] = mistakemsgturn3['slope']; thisClass.groups[currentGroup].activities[currentActivity].turns[2] .mistakes['initialPoint'] = mistakemsgturn3['initialPoint']; thisClass.groups[currentGroup].activities[currentActivity].turns[2] .mistakes['intercept'] = mistakemsgturn3['intercept']; notifyListeners(); } onInactivityAdded(Event event) { // print(jsonDecode(event.snapshot.value)['acID'].toString()); // int currentGroup = // thisClass.groupIDs.indexOf(jsonDecode(event.snapshot.value)['groupID']); // int currentActivity = // acList.indexOf(jsonDecode(event.snapshot.value)['acID'].toString()); //thisClass.groups[currentGroup].inactivity[currentstepActivation] = // (jsonDecode(event.snapshot.value)['inactivity']); //print(thisClass.groups[currentGroup].inactivity); //currentstepActivation = currentstepActivation + 1; notifyListeners(); } oncelluloPositionAdded(Event event) { int currentGroup = thisClass.groupIDs.indexOf(jsonDecode(event.snapshot.value)['groupID']); int currentActivity = acList.indexOf(jsonDecode(event.snapshot.value)['acID'].toString()); int currentTurn = 0; // print(currentGroup.toString()); if (jsonDecode(event.snapshot.value)['turn'].toString() == '1') currentTurn = 1; if (jsonDecode(event.snapshot.value)['turn'].toString() == '2') currentTurn = 2; if (jsonDecode(event.snapshot.value)['turn'].toString() == '3') currentTurn = 3; // print(currentTurn); // int currentActivity = // acList.indexOf(jsonDecode(event.snapshot.value)['acID'].toString()); // print((jsonDecode(event.snapshot.value)['x'])); - thisClass.groups[currentGroup].activities[currentActivity] - .turns[currentTurn - 1].cellulox.x - .add((jsonDecode(event.snapshot.value)['x'] * 90 / 860)); - // print((jsonDecode(event.snapshot.value)['y'])); - thisClass.groups[currentGroup].activities[currentActivity] - .turns[currentTurn - 1].celluloy.y - .add((jsonDecode(event.snapshot.value)['y'] * 90 / 860)); + if (currentGroup != -1) { + thisClass.groups[currentGroup].activities[currentActivity] + .turns[currentTurn - 1].cellulox.x + .add((jsonDecode(event.snapshot.value)['x'])); + // print((jsonDecode(event.snapshot.value)['y'])); + thisClass.groups[currentGroup].activities[currentActivity] + .turns[currentTurn - 1].celluloy.y + .add((jsonDecode(event.snapshot.value)['y'])); + } // thisClass.groups[currentGroup].celluloy.y // .add((jsonDecode(event.snapshot.value)['y'] / 40)) // setState(() {}); notifyListeners(); } } diff --git a/Dashboard/lib/screens/Debriefing.dart b/Dashboard/lib/screens/Debriefing.dart index 222139b..c36c0c9 100644 --- a/Dashboard/lib/screens/Debriefing.dart +++ b/Dashboard/lib/screens/Debriefing.dart @@ -1,249 +1,251 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:Teacher_Dashboard/widgets/custom_app_bar.dart'; import 'dart:convert'; import 'package:Teacher_Dashboard/config/palette.dart'; import 'package:Teacher_Dashboard/config/styles.dart'; import 'dart:async'; import './screens.dart'; import 'package:Teacher_Dashboard/model/Class.dart'; import 'package:Teacher_Dashboard/model/Group.dart'; import 'package:firebase_database/firebase_database.dart'; import 'package:Teacher_Dashboard/model/activities/activity.Dart'; import 'package:step_progress_indicator/step_progress_indicator.dart'; import 'package:Teacher_Dashboard/widgets/hexagonPainter.Dart'; import 'package:Teacher_Dashboard/widgets/celluloMap.Dart'; import 'package:provider/provider.dart'; //import 'package:Teacher_Dashboard/model/core/models/productModel.dart'; //import 'package:Teacher_Dashboard/model/core/viewmodels/CRUDModel.dart'; //import 'package:provider/provider.dart'; class Debriefing extends StatefulWidget { @override DebriefingState createState() => DebriefingState(); } class DebriefingState extends State { bool mistakesSwitch = false; bool rankingSwitch = false; bool robotPatternSwitch = false; int numofgroups = thisClass.groups.length; int currentstepActivation = 0; String pauseButtonText = 'Pause All'; final FirebaseDatabase _database = FirebaseDatabase.instance; @override void initState() { super.initState(); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { // final productProvider = Provider.of(context); return Scaffold( backgroundColor: Colors.white, appBar: CustomAppBar(), body: Column(children: [ SizedBox( height: 780, child: Consumer( builder: (context, model, child) => Container( child: ListView.builder( itemCount: thisClass.groups.length, itemBuilder: (context, int position) { return Card( child: ListTile( onLongPress: () { Navigator.push( context, MaterialPageRoute( builder: (context) => GroupDashboard(currentgroupID: position))); }, title: Column(children: [ Row(children: [ SizedBox(width: 17), Stack(children: [ CircularStepProgressIndicator( totalSteps: 3, // currentStep: // thisClass.groups[position].activities[0].progress, width: 100, customColor: (index) => thisClass .groups[position] .activities[acList.indexOf(thisClass .groups[position] .currentActivity)] .progress[index] > -2 ? (thisClass .groups[position] .activities[acList.indexOf( thisClass.groups[position] .currentActivity)] .progress[index] > -1 ? (thisClass .groups[position] .activities[acList.indexOf(thisClass.groups[position].currentActivity)] .progress[index] > 0 ? Colors.green : Colors.blue) : Colors.red) : Colors.grey, ), Positioned( bottom: 45, right: 28, child: Center( child: Text( thisClass.groups[position].id, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 13), )), ), ]), SizedBox(width: 25), minituare(position, 1, mistakesSwitch, rankingSwitch, robotPatternSwitch), SizedBox( width: 25, ), minituare(position, 2, mistakesSwitch, rankingSwitch, robotPatternSwitch), SizedBox( width: 25, ), minituare(position, 3, mistakesSwitch, rankingSwitch, robotPatternSwitch), ]), SizedBox(height: 20), ]), trailing: Icon(Icons.more_vert), )); }, )), )), Row( // mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( 'Show Students Mistakes', style: TextStyle( fontSize: 15.0, // color: Colors.white, fontWeight: FontWeight.bold), ), SizedBox(width: 5), Checkbox( //title: const Text('Animate Slowly'), value: mistakesSwitch, onChanged: (bool value) { setState(() { mistakesSwitch = value; }); }, // secondary: const Icon(Icons.hourglass_empty), ), SizedBox(width: 300), Text( 'Show Students robot pattern', style: TextStyle( fontSize: 15.0, // color: Colors.white, fontWeight: FontWeight.bold), ), SizedBox(width: 5), Checkbox( value: robotPatternSwitch, onChanged: (bool value) { setState(() { robotPatternSwitch = value; }); }, // secondary: const Icon(Icons.hourglass_empty), ), ]), ])); } } Widget minituare(int position, int turn, bool mistakesSwitch, bool rankingSwitch, bool robotpatternSwitch) { var colors = [Colors.grey, Colors.red, Colors.blue, Colors.green]; List gridAcsPath = [ 'assets/images/GridOnlyPositive.svg', 'assets/images/Grid.svg' ]; return Container( width: 130, height: 180, decoration: BoxDecoration( border: Border.all( width: 0.5, color: colors[ thisClass.groups[position].activities[0].progress[turn - 1] + 2])), child: Stack(children: [ Positioned( bottom: 65, right: 30, width: 90, height: 90, child: celluloMap( gridAcsPath[ acList.indexOf(thisClass.groups[position].currentActivity)], turn, acList.indexOf(thisClass.groups[position].currentActivity), robotpatternSwitch, thisClass .groups[position].activities[0].turns[turn - 1].cellulox.x, - thisClass.groups[position].activities[0].turns[turn - 1] - .celluloy.y)), + thisClass + .groups[position].activities[0].turns[turn - 1].celluloy.y, + 90, + 90)), Positioned( bottom: 155, right: 27, child: Text( ((turn > 1) ? ((turn > 2) ? 'Third ' : 'Second ') : 'First ') + "Turn ", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14), )), Positioned(bottom: 4, right: 50, child: Text(rankingSwitch ? "" : "")), Positioned( bottom: 25, right: 6, child: Text( mistakesSwitch ? (thisClass.groups[position].activities[0].progress[turn - 1] > -2 ? (thisClass.groups[position].activities[0].mistakes['slope'][turn - 1] == 0 && thisClass.groups[position].activities[0].mistakes['initialPoint'][turn - 1] == 0 ? 'No Mistakes' : (thisClass.groups[position].activities[0].mistakes['slope'][turn - 1] > 0 && thisClass.groups[position].activities[0] .mistakes['initialPoint'][turn - 1] > 0 ? 'Mistakes in finding\n Slope and\n Initial Points' : (thisClass.groups[position].activities[0].mistakes['slope'][turn - 1] > 0 && thisClass.groups[position].activities[0] .mistakes['initialPoint'][turn - 1] == 0 ? 'Mistakes in finding\n slope' : 'Mistakes in finding\n initial points'))) : '') : '', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14), ), ) ])); } diff --git a/Dashboard/lib/screens/groupDashboard.Dart b/Dashboard/lib/screens/groupDashboard.Dart index cbe46a8..2203d81 100644 --- a/Dashboard/lib/screens/groupDashboard.Dart +++ b/Dashboard/lib/screens/groupDashboard.Dart @@ -1,602 +1,604 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:Teacher_Dashboard/widgets/custom_app_bar.dart'; import 'package:Teacher_Dashboard/widgets/celluloMap.Dart'; import 'dart:convert'; import 'package:Teacher_Dashboard/config/palette.dart'; import 'dart:async'; import 'package:Teacher_Dashboard/model/Class.dart'; import 'package:Teacher_Dashboard/model/Group.dart'; import 'package:Teacher_Dashboard/model/activities/activity.Dart'; import 'package:Teacher_Dashboard/config/palette.dart'; import 'package:firebase_database/firebase_database.dart'; import 'package:step_progress_indicator/step_progress_indicator.dart'; //import 'package:Teacher_Dashboard/model/core/models/productModel.dart'; //import 'package:Teacher_Dashboard/model/core/viewmodels/CRUDModel.dart'; import 'package:provider/provider.dart'; class GroupDashboard extends StatefulWidget { final int currentgroupID; GroupDashboard({Key key, this.currentgroupID}) : super(key: key); @override GroupDashboardState createState() => GroupDashboardState(); } class GroupDashboardState extends State { final TextStyle whiteText = TextStyle(color: Colors.white, fontSize: 20); Timer timer; final FirebaseDatabase _database = FirebaseDatabase.instance; var progress; int groupID = 0; int studentListIndex = 0; int activityID = 0; int activityListIndex = 0; int turnID = 0; List gridAcsPath = [ "assets/images/GridOnlyPositive.svg", "assets/images/Grid.svg", ]; double _currentSliderValue = 0; String pauseButtonText = 'Pause'; @override void initState() { super.initState(); if (widget.currentgroupID != null) groupID = widget.currentgroupID; } //@override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: CustomAppBar(), body: SingleChildScrollView( // padding: const EdgeInsets.all(10.0), child: Row(children: [ Consumer( builder: (context, model, child) => Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 200, decoration: BoxDecoration( color: Palette.primaryColor, border: Border.all(color: Colors.purple), // borderRadius: new BorderRadius.circular(25.0), ), child: Text( 'Groups', style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18), )), Container( height: 480, width: 200, // margin: const EdgeInsets.all(15.0), // padding: const EdgeInsets.all(10.0), decoration: BoxDecoration( color: Palette.primaryColor, border: Border.all(color: Colors.purple), // borderRadius: new BorderRadius.circular(25.0), ), child: ListView.builder( itemCount: thisClass.groups.length, itemBuilder: (context, int position) { return ListTile( leading: Icon( Icons.person, color: Colors.white, ), onTap: () { setState(() { studentListIndex = position; groupID = position; }); }, title: Text( thisClass.groups[position].id, style: TextStyle( color: (studentListIndex == position) ? Colors.blue : Colors.white, fontWeight: FontWeight.bold, fontSize: 18), ), ); })), Container( width: 200, decoration: BoxDecoration( color: Palette.primaryColor, border: Border.all(color: Colors.purple), // borderRadius: new BorderRadius.circular(25.0), ), child: Text( 'Activities', style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18), )), Container( height: 350, width: 200, // margin: const EdgeInsets.all(15.0), // padding: const EdgeInsets.all(10.0), decoration: BoxDecoration( color: Palette.primaryColor, border: Border.all(color: Colors.purple), // borderRadius: new BorderRadius.circular(25.0), ), child: ListView.builder( itemCount: acList.length, itemBuilder: (context, int position) { return ListTile( leading: Icon( Icons.description, color: Colors.white, ), onTap: () { setState(() { activityListIndex = position; activityID = position; }); }, title: Text( acList[position], style: TextStyle( color: (activityListIndex == position) ? Colors.blue : Colors.white, fontWeight: FontWeight.bold, fontSize: 18), ), ); })) ])), SizedBox(width: 20), Consumer( builder: (context, model, child) => Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( height: 1, ), Row( // crossAxisAlignment: CrossAxisAlignment.start, children: [ Stack(children: [ CircularStepProgressIndicator( totalSteps: 3, // currentStep: // thisClass.groups[position].activities[0].progress, width: 100, customColor: (index) => (thisClass.groups.length > 0) ? (thisClass .groups[groupID] .activities[activityID] .progress[index] > -2 ? (thisClass .groups[groupID] .activities[activityID] .progress[index] > -1 ? (thisClass .groups[groupID] .activities[activityID] .progress[index] > 0 ? Colors.green : Colors.blue) : Colors.red) : Colors.grey) : Colors.grey, ), Positioned( bottom: 45, right: 18, child: Text( '', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 15), )), ]), SizedBox(width: 10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Icon(Icons.group), Text( (thisClass.groups.length > 0) ? (' ' + thisClass.groups[groupID].id) : '', style: TextStyle( fontSize: 30.0, color: Colors.black, fontWeight: FontWeight.w500), ), ], ), SizedBox(height: 25), Row( // crossAxisAlignment: CrossAxisAlignment.start, children: [ Row(children: [ Icon(Icons.person), Text( (thisClass.groups.length > 0) ? thisClass .groups[groupID].member1name : '', style: TextStyle( fontSize: 20.0, color: Colors.black, fontWeight: FontWeight.w500), ), ]), SizedBox(width: 20), Row(children: [ Icon(Icons.person), Text( (thisClass.groups.length > 0) ? thisClass .groups[groupID].member2name : '', style: TextStyle( fontSize: 20.0, color: Colors.black, fontWeight: FontWeight.w500), ), ]), SizedBox(width: 20), Row(children: [ Icon(Icons.person), Text( (thisClass.groups.length > 0) ? thisClass .groups[groupID].member3name : '', style: TextStyle( fontSize: 20.0, color: Colors.black, fontWeight: FontWeight.w500), ), ]) ]), ]), ]), SizedBox( height: 20, ), Container( width: 500, child: StepProgressIndicator( totalSteps: 50, // currentStep: thisClass.groups[position].inactivity.length, size: 10, padding: 0, customColor: (index) => Palette.primaryColor)), SizedBox( height: 20, ), Row( // mainAxisSize: MainAxisSize.min, children: [ infoTile( (thisClass.groups.length > 0) ? thisClass.groups[groupID].activities[activityID] .turns[turnID].numAttempts .toString() : '0', 'Attempts', Colors.blue), infoTileTime( 'Performing in', (thisClass.groups.length > 0) ? thisClass.groups[groupID].activities[activityID] .turns[turnID].elapsedTime : 0, Colors.blue), ]), Row( // mainAxisSize: MainAxisSize.min, children: [ Column( // mainAxisSize: MainAxisSize.min, children: [ Container( width: 400, height: 400, child: celluloMap( gridAcsPath[activityID], turnID + 1, activityID, true, (thisClass.groups.length > 0) ? thisClass .groups[groupID] .activities[activityID] .turns[turnID] .cellulox .x : [0, 0], (thisClass.groups.length > 0) ? thisClass .groups[groupID] .activities[activityID] .turns[turnID] .celluloy .y - : [0, 0])), + : [0, 0], + 400, + 400)), Text( ((turnID + 1 > 1) ? ((turnID + 1 > 2) ? 'Third ' : 'Second ') : 'First ') + "Turn ", style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), Slider( activeColor: Colors.purple, value: _currentSliderValue, min: 0, max: 200, // divisions: 5, // label: _currentSliderValue.round().toString(), onChanged: (double value) { setState(() { _currentSliderValue = value; }); }), ]), Column( // mainAxisSize: MainAxisSize.min, children: [ infoTile( (thisClass.groups.length > 0) ? thisClass .groups[groupID] .activities[activityID] .turns[turnID] .mistakes['slope'] .toString() : '0', 'Mistakes in finding slope', Colors.blue), (activityID == 0) ? infoTile( (thisClass.groups.length > 0) ? thisClass .groups[groupID] .activities[activityID] .turns[turnID] .mistakes['initialPoint'] .toString() : '0', 'Mistakes in finding initial Point', Colors.blue) : infoTile( (thisClass.groups.length > 0) ? thisClass .groups[groupID] .activities[activityID] .turns[turnID] .mistakes['intercept'] .toString() : '0', 'Mistakes in finding intercept', Colors.blue), ]) ]), Row( // mainAxisSize: MainAxisSize.min, children: [ SizedBox(width: 140), FloatingActionButton( heroTag: "prevButton", tooltip: 'Previous Turn', onPressed: () { if (turnID > 0) { print(thisClass .groups[groupID] .activities[activityID] .turns[turnID] .elapsedTime .toString()); setState(() { turnID = turnID - 1; }); } }, child: Icon(Icons.skip_previous), backgroundColor: Palette.primaryColor, ), SizedBox(width: 10), FloatingActionButton( heroTag: "nextButtton", tooltip: 'Next Turn', onPressed: () { if (turnID < 2) setState(() { turnID = turnID + 1; }); }, child: Icon(Icons.skip_next), backgroundColor: Palette.primaryColor, ), ]), SizedBox(height: 10), Row( // mainAxisSize: MainAxisSize.min, children: [ SizedBox(width: 125), Container( width: 200, child: MaterialButton( color: Colors.red, elevation: 0, onPressed: () { if (pauseButtonText == 'Pause') { pauseButtonText = 'Resume'; } else { pauseButtonText = 'Pause'; // dbRef.child("1").child("isPaused").set(true); } if (pauseButtonText == 'Pause') _database .reference() .child(thisClass.sessionID) .child('groups') .child(thisClass.groupIDs[groupID]) .child('isPaused') .set(false); if (pauseButtonText == 'Resume') _database .reference() .child(thisClass.sessionID) .child('groups') .child(thisClass.groupIDs[groupID]) .child('isPaused') .set(true); }, child: Container( padding: EdgeInsets.all(15.0), child: Text( pauseButtonText, textAlign: TextAlign.center, style: TextStyle( fontSize: 20.0, color: Colors.white, fontWeight: FontWeight.w500), ), ), ), ), SizedBox(width: 20), Container( width: 200, child: MaterialButton( color: Colors.blue, elevation: 0, onPressed: () { _database .reference() .child(thisClass.sessionID) .child('groups') .child(thisClass.groupIDs[groupID]) .child('currentActivity') .set('Ac8'); }, child: Container( padding: EdgeInsets.all(15.0), child: Text( "Next Activity", textAlign: TextAlign.center, style: TextStyle( fontSize: 20.0, color: Colors.white, fontWeight: FontWeight.w500), ), ), ), ), ], ) ], ), ) ]), ), ); } Container infoTile(String title, String count, MaterialColor color) { return Container( width: 120, // margin: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(10.0), decoration: BoxDecoration( color: color, borderRadius: BorderRadius.circular(10.0), ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( title, style: const TextStyle( color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.bold, ), ), Text( count, style: const TextStyle( color: Colors.white, fontSize: 15.0, fontWeight: FontWeight.w600, ), ), ], ), ); } Container infoTileTime(String title, int count, MaterialColor color) { return Container( width: 220, // margin: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(10.0), decoration: BoxDecoration( color: color, // borderRadius: BorderRadius.circular(10.0), ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( title, style: const TextStyle( color: Colors.white, fontSize: 15.0, fontWeight: FontWeight.bold, ), ), Text( ((count > 60000) ? ((count / 60000).round().toString() + ' miutes') : '') + ' ' + ((count % 60000) / 1000).round().toString() + ' Seconds', style: const TextStyle( color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.w600, ), ), ], ), ); } } diff --git a/Dashboard/lib/widgets/celluloMap.Dart b/Dashboard/lib/widgets/celluloMap.Dart index cfd0a59..e57f1c0 100644 --- a/Dashboard/lib/widgets/celluloMap.Dart +++ b/Dashboard/lib/widgets/celluloMap.Dart @@ -1,45 +1,52 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:Teacher_Dashboard/widgets/linePainter.Dart'; Widget celluloMap( String gridPath, int turn, int acID, bool robotpatternSwitch, List celluloxPositiontopaint, - List celluloyPositiontopaint) { + List celluloyPositiontopaint, + double mapSizeScreenWidth, + double mapSizeScreenHeight) { // Activity-Dependent var imagespath = [ [ 'assets/images/Ac7_function1.svg', 'assets/images/Ac7_function2.svg', 'assets/images/Ac7_function3.svg' ], [ 'assets/images/Ac8_function1.svg', 'assets/images/Ac8_function2.svg', 'assets/images/Ac8_function3.svg', // 'assets/images/GridOnlyPositive.svg', ] ]; // 'assets/images/GridOnlyPositive.svg', final double mapSizeWidth = 860; final double mapSizeHeight = 860; - final double mapSizeScreenWidth = 90; - final double mapSizeScreenHeight = 90; - final double scaleWidth = mapSizeScreenWidth / mapSizeWidth; - final double scaleHeight = mapSizeScreenHeight / mapSizeHeight; + + List normalizecellulopath(List path) { + List pathnorm = new List(); + for (int i = 0; i < path.length; i++) { + pathnorm.add(path[i] * mapSizeScreenWidth / mapSizeWidth); + } + return pathnorm; + } + return Stack(children: [ SvgPicture.asset(imagespath[acID][turn - 1]), SvgPicture.asset(gridPath), robotpatternSwitch ? CustomPaint( size: Size(mapSizeScreenWidth, mapSizeScreenHeight), - painter: - LinePainter2(celluloxPositiontopaint, celluloyPositiontopaint), + painter: LinePainter2(normalizecellulopath(celluloxPositiontopaint), + normalizecellulopath(celluloyPositiontopaint)), ) : Text(''), ]); } diff --git a/student/lib/Activities/Ac7.Dart b/student/lib/Activities/Ac7.Dart index 6d46af7..e40c312 100644 --- a/student/lib/Activities/Ac7.Dart +++ b/student/lib/Activities/Ac7.Dart @@ -1,750 +1,745 @@ 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 '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 Ac7 extends StatefulWidget { Ac7({Key key}) : super(key: key); @override _Ac7State createState() => _Ac7State(); } class _Ac7State extends State with SingleTickerProviderStateMixin, WidgetsBindingObserver { // Timers Timer timerCelluloPosition; Timer timerslopedetection; Timer timercleartracking; Timer timerprevCelluloPosition; Timer timerInactivityDetector; Timer timerprevCelluloPositiontoserver; final acID = 7; final maxLiitCellulo = 800; // UI parameters 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; + AnimationController controllerTrial; + AnimationController controllerTurn; Animation animation; + Animation animationNextTurn; TextEditingController controllerinitialX = TextEditingController(); TextEditingController controllerinitialY = TextEditingController(); TextEditingController controllerXslope = TextEditingController(); TextEditingController controllerYslope = TextEditingController(); var counterfunctionImage = 0; //Activity Dependent var imagespath = [ 'assets/images/Ac7_function1.svg', 'assets/images/Ac7_function2.svg', 'assets/images/Ac7_function3.svg', 'assets/images/GridOnlyPositive.svg', ]; 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; - + int simulationVelCoeff = 1; // Learning List progress = [0, -2, -2]; // zero: undergoing, -1: not accomplished, 1: accomplished bool waitforanimation = false; List mistakesSlope = [0, 0, 0]; List mistakesIntrepet = [0, 0, 0]; List mistakesInitialPosition = [0, 0, 0]; List progressElpasedTime = [0, 0, 0]; var inactivity = 0; var prevcelluloxPositionSlope = 0.0; var prevcelluloyPositionSlope = 0.0; // robot related var elapseTimer = new Stopwatch(); bool setRun = false; var celluloxPosition = [0.0, 0.0]; var celluloyPosition = [0.0, 0.0]; List celluloxPositiontopaint = [0.0, 0.0]; List 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]; var avgActivation = 0; int prevtotalTaps = 0; var correctAnswer = [ {"initialPointX": 0, "initialPointY": 0, "slope": 1}, {"initialPointX": 0, "initialPointY": 1, "slope": 1}, {"initialPointX": 0, "initialPointY": 0, "slope": 2} ]; @override void initState() { WidgetsBinding.instance.addObserver(this); dbRef.child('groups').child(group.id).child('tabletStatus').set("YES"); dbRef.child('groups').child(group.id).child('currentActivity').set("Ac7"); elapseTimer.start(); onDataSend(); + controllerTrial = AnimationController( + duration: Duration(milliseconds: 30000), vsync: this); + + animation = Tween(begin: 0.0, end: 1.0).animate(controllerTrial) + ..addListener(() { + _progress = animation.value; + + if (_progress < 0.2) { + //print('uuh'); + cellulox.setGoalPosition( + originCoordinates[0] + 100 * int.parse(controllerinitialX.text), + 600); + celluloy.setGoalPosition(100, + originCoordinates[1] - 100 * int.parse(controllerinitialY.text)); + } + if (_progress > 0.22) { + setState(() { + setRun = true; + }); + // cellulox.setGoalPosition(770, 600); + // celluloy.setGoalPosition(100, 80); + cellulox.setVelocity(50.0 * simulationVelCoeff, 0); + if (celluloySwitch1 == false) + celluloy.setVelocity(0, + -50.0 * simulationVelCoeff * int.parse(controllerYslope.text)); + if (celluloySwitch1 == true) + celluloy.setVelocity(0, + 50.0 * simulationVelCoeff * int.parse(controllerYslope.text)); + // } + //if (celluloxPosition[0] > 700 || + // celluloyPosition[1] < 100) { + // cellulox.resetrobot(); + // celluloy.resetrobot(); + } + 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); + } + }); + // getApps(); super.initState(); // group.numCurrentActivity = 7; cellulox.resetrobot(); celluloy.resetrobot(); timerCelluloPosition = new Timer.periodic(new Duration(milliseconds: 500), (time) { if (totalRobots() > 1) { cellulox.getrobotx().then((val) => setState(() { celluloxPosition[0] = val; if (setRun == true) celluloxPositiontopaint.add(val * 500 / 860); // print(setRun.toString()); })); 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); })); if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) { - cellulox.resetrobot(); - celluloy.resetrobot(); + // cellulox.resetrobot(); + // celluloy.resetrobot(); } } /* 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); */ }); timerprevCelluloPositiontoserver = - new Timer.periodic(new Duration(milliseconds: 400), (time) { + new Timer.periodic(new Duration(milliseconds: 800), (time) { if (setRun == true) { dbRef.child("celluloPosition").push().set(json.encode({ "x": celluloxPosition[0], "y": celluloyPosition[1], "acID": "Ac7", "turn": currentTurn, "groupID": group.id, })); } }); 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]; } }); }); timerInactivityDetector = new Timer.periodic(new Duration(seconds: 60), (time) { onInactivityTimer(); }); - controller = AnimationController( - duration: Duration(milliseconds: 10000), vsync: this); - /// /// Ask to be notified when messages related to the game /// are sent by the server /// } void onDataSend() { dbRef.child('attempts').push().set(json.encode({ "numAttempts": tapCounter, "groupID": group.id, "acID": "Ac7", "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, "inactivity": inactivity, "mistakes": { "turn1": { "slope": mistakesSlope[0], "initialPoint": mistakesInitialPosition[0] }, "turn2": { "slope": mistakesSlope[1], "initialPoint": mistakesInitialPosition[1] }, "turn3": { "slope": mistakesSlope[2], "initialPoint": mistakesInitialPosition[2] }, } })); } 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(); } 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(); }); } void onInactivityTimer() { group.inactivity = group.inactivity + 1; } @override void dispose() { + cellulox.resetrobot(); + celluloy.resetrobot(); timer.cancel(); + controllerTrial.dispose(); super.dispose(); } 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; }); } void nextPLayer() { setState(() { currentTurn = currentTurn + 1; // celluloyPositiontopaint = [0.0, 0.0]; // celluloxPositiontopaint = [0.0, 0.0]; }); } - void animationRunner(progress) { - print(progress); - if (progress < 0.4) { - cellulox.setGoalPosition( - originCoordinates[0] + 100 * int.parse(controllerinitialX.text), 600); - celluloy.setGoalPosition( - 100, originCoordinates[1] - 100 * int.parse(controllerinitialY.text)); - } - setState(() { - setRun = true; - }); - if (progress > 0.6) { - cellulox.setGoalPosition( - originCoordinates[0] + 100 * int.parse(controllerinitialX.text) + 500, - 600); - celluloy.setGoalPosition( - 100, - originCoordinates[1] - - 100 * int.parse(controllerinitialY.text) - - 500); - } - - if (celluloxPosition[0] > 800 || celluloyPosition[1] > 800) { - cellulox.resetrobot(); - celluloy.resetrobot(); - } - } + void animationRunner(progress) {} @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: [ 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(10.0), decoration: BoxDecoration( border: Border.all(color: Colors.blueAccent), borderRadius: new BorderRadius.circular(25.0), ), height: 230.0, child: Column(children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ 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", ), ), ), SizedBox(height: 10), Row(children: [ Container( width: 250, 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: [ 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: 8, ), Column( // mainAxisAlignment: MainAxisAlignment.center, children: [ 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", ), ), ), SizedBox(height: 10), Row(children: [ Container( width: 250, child: new TextFormField( controller: controllerYslope, 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: [ 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, ), Row(mainAxisAlignment: MainAxisAlignment.center, children: < Widget>[ FloatingActionButton( heroTag: "btn2", tooltip: 'Run the Robots', onPressed: () => { tapCounter = tapCounter + 1, // avgActivation= if (controllerinitialX.text != correctAnswer[currentTurn - 1]['initialPointX'] .toString() || controllerinitialY.text != correctAnswer[currentTurn - 1]['initialPointY'] .toString()) { mistakesInitialPosition[currentTurn - 1] = mistakesInitialPosition[currentTurn - 1] + 1, }, if (controllerYslope.text != correctAnswer[currentTurn - 1]['slope'].toString()) { mistakesSlope[currentTurn - 1] = mistakesSlope[currentTurn - 1] + 1, }, if (controllerinitialX.text == correctAnswer[currentTurn - 1] ['initialPointX'] .toString() && controllerinitialY.text == correctAnswer[currentTurn - 1]['initialPointY'] .toString() && controllerYslope.text == correctAnswer[currentTurn - 1]['slope'] .toString()) { progress[currentTurn - 1] = 1, }, onDataSend(), - controller.reset(), - animation = Tween(begin: 0.0, end: 1.0).animate( - controller) - ..addListener(() { - _progress = animation.value; - - if (_progress < 0.4) { - cellulox.setGoalPosition( - originCoordinates[0] + - 100 * int.parse(controllerinitialX.text), - 600); - celluloy.setGoalPosition( - 100, - originCoordinates[1] - - 100 * int.parse(controllerinitialY.text)); - } - if (_progress > 0.6) { - setState(() { - setRun = true; - }); - cellulox.setGoalPosition( - originCoordinates[0] + - 100 * int.parse(controllerinitialX.text) + - 300, - 600); - celluloy.setGoalPosition( - 100, - originCoordinates[1] - - 100 * int.parse(controllerinitialY.text) - - 150); - } - if (celluloxPosition[0] > 800 || - celluloyPosition[1] > 800) { - cellulox.resetrobot(); - celluloy.resetrobot(); - } - }), - controller.forward(), + controllerTrial.reset(), + controllerTrial.forward(), }, child: Icon(Icons.play_circle_outline), ), SizedBox(width: 20), FloatingActionButton( heroTag: "btn1", tooltip: 'Next Turn', onPressed: () => { setState(() { tapCounter = 0; currentTurn = currentTurn + 1; if (currentTurn == 2) { progressElpasedTime[0] = elapseTimer.elapsedMilliseconds; } else { progressElpasedTime[currentTurn - 2] = elapseTimer.elapsedMilliseconds - progressElpasedTime[currentTurn - 3]; } }), if (progress[currentTurn - 2] == 0) progress[currentTurn - 2] = -1, if (currentTurn < 4) { celluloxPositiontopaint = [0, 0], celluloyPositiontopaint = [0, 0], - controller.reset(), + // controller.reset(), + cellulox.setGoalPosition( + originCoordinates[0] + + 100 * int.parse(controllerinitialX.text), + 600), + celluloy.setGoalPosition( + 100, + originCoordinates[1] - + 100 * int.parse(controllerinitialY.text)), + setRun = false, progress[currentTurn - 1] = 0, onDataSend(), - } - // _ackAlert, - // showAlertDialog(context, '', 'Now its next player turn'), + }, }, child: Icon(Icons.navigate_next), ), ]), ])), SizedBox( height: 5, ), celluloMap(context), SizedBox( height: 15, ), MembersBar( curTurn: currentTurn, ), ]))); } 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: [ 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), ), ])); } } diff --git a/student/lib/model/Cellulo.dart b/student/lib/model/Cellulo.dart index af8beae..ab4e651 100644 --- a/student/lib/model/Cellulo.dart +++ b/student/lib/model/Cellulo.dart @@ -1,152 +1,152 @@ import 'dart:async'; import 'dart:ffi'; // For FFI import 'dart:io'; // For Platform.isX Cellulo cellulox = new Cellulo(0); Cellulo celluloy = new Cellulo(1); class Cellulo { int robotID = 0; bool colorset = false; bool velocityset = false; static var robots = []; int robot = -1; Cellulo(this.robotID); setup() async { print(totalRobots()); // print("thisis the current robot" + _robot.toString()); // robot = _robot; for (var i = 0; i < totalRobots(); i++) { int _robot = newRobotfromPool(); robots.add(_robot); } print(robots); } void remainingrobots() async { print("remaining" + robotsRemaining().toString()); print("total" + totalRobots().toString()); } void setColor() async { print(robots[robotID]); setVisualEffect(robots[robotID], 120, 0, 0, 0, 0); } void resetrobot() async { reset(robots[robotID]); } Future getrobotx() async { //print(robots[robotID]); return getX(robots[robotID]); } Future getroboty() async { //print(robots[robotID]); return getY(robots[robotID]); } Future getrobottetha() async { //print(robots[robotID]); return getTheta(robots[robotID]); } Future getrobotKidnapped() async { //print(robots[robotID]); return getKidnapped(robots[robotID]); } - Future setVelocity() async { - setGoalVelocity(robots[robotID], 100, 0, 0); + Future setVelocity(double vx, double vy) async { + setGoalVelocity(robots[robotID], vx, vy, 0); } Future setGoalPosition(double x, double y) async { setGoalPose(robots[robotID], x, y, 0, 150, 150); } } final DynamicLibrary nativeAddLib = Platform.isAndroid ? DynamicLibrary.open("libnative_add.so") : DynamicLibrary.process(); final DynamicLibrary nativeCellulolib = Platform.isAndroid ? DynamicLibrary.open("libcellulo-library.so") : DynamicLibrary.process(); final int Function(int x, int y) nativeAdd = nativeAddLib .lookup>("native_add") .asFunction(); final int Function(int x, int y) nativeAddCellulo = nativeCellulolib .lookup>("test_native_add") .asFunction(); final int Function() initialize = nativeCellulolib .lookup>("initialize") .asFunction(); final void Function(int robot) reset = nativeCellulolib .lookup>("reset") .asFunction(); final int Function() newRobotfromPool = nativeCellulolib .lookup>("newRobotFromPool") .asFunction(); final void Function() destroyRobot = nativeCellulolib .lookup>("destroyRobot") .asFunction(); final void Function(int robot, int effect, int r, int g, int b, int value) setVisualEffect = nativeCellulolib .lookup< NativeFunction< Void Function(Int64 robot, Int64 effect, Int64 r, Int64 g, Int64 b, Int64 value)>>("setVisualEffect") .asFunction(); //setGoalVelocity(int64_t robot, float vx, float vy, float w) final void Function(int robot, double vx, double vy, double w) setGoalVelocity = nativeCellulolib .lookup< NativeFunction< Void Function(Int64 robot, Float vx, Float vy, Float w)>>("setGoalVelocity") .asFunction(); final void Function( int robot, double x, double y, double theta, double v, double w) setGoalPose = nativeCellulolib .lookup< NativeFunction< Void Function(Int64 robot, Float x, Float y, Float theta, Float v, Float w)>>("setGoalPose") .asFunction(); final int Function() totalRobots = nativeCellulolib .lookup>("totalRobots") .asFunction(); final int Function() robotsRemaining = nativeCellulolib .lookup>("robotsRemaining") .asFunction(); final double Function(int robot) getX = nativeCellulolib .lookup>("getX") .asFunction(); final double Function(int robot) getY = nativeCellulolib .lookup>("getY") .asFunction(); final double Function(int robot) getTheta = nativeCellulolib .lookup>("getTheta") .asFunction(); final int Function(int robot) getKidnapped = nativeCellulolib .lookup>("getKidnapped") .asFunction();