Skip to content

Commit

Permalink
added url_args file
Browse files Browse the repository at this point in the history
  • Loading branch information
florencelarkin committed Jan 10, 2022
1 parent acf3fb7 commit 54bc43e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 25 deletions.
64 changes: 43 additions & 21 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,78 @@ import 'startingScreen.dart';
import 'Maze.dart';
import 'userIDD.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'url_args.dart';

import 'package:just_audio/just_audio.dart';

//initialize new maze
maze maze1= new maze();
maze maze1 = new maze();
Color color1 = Colors.grey;
int lastMove = 0; //records last CORRECT move of user
bool lastMoveIncorrect = true; //true if user's last move was correct, false otherwise
bool lastMoveIncorrect =
true; //true if user's last move was correct, false otherwise
var icon = Icons.check;
var image="assets/greencheck.jpg";
Stopwatch clock = new Stopwatch(); //initialize new stopwatch that will be used to record times of user's moves
var image = "assets/greencheck.jpg";
Stopwatch clock =
new Stopwatch(); //initialize new stopwatch that will be used to record times of user's moves
List moves = [];
Set <int> correctMoves = {};
List<dynamic> times=[];
Set<int> correctMoves = {};
List<dynamic> times = [];
List errors = [];
//temporary test path - going to change to make dynamically generated
//List<dynamic> path=[0,10,20,30,40,50,60,70,80,90,91,92,93,94,95,96,97,98,99];
List<dynamic> path= genPath(mat);
bool timeOut = false; //when true, user is prohibited from entering new moves (so as not to overwhelm game)
List<dynamic> path = genPath(mat);
bool timeOut =
false; //when true, user is prohibited from entering new moves (so as not to overwhelm game)
var dateTime = DateTime.now();
int attemptNum = 1;
int consecErrors = 0;
int recentMove=0; //records last move of user regardless of corectness
int recentMove = 0; //records last move of user regardless of corectness
//final AudioCache audioCache = AudioCache(prefix: "audio/", fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP));

String subjectID = 'urlTest'; //subject ID that is in url
Map<String, String> urlArgs = {};

void main() {


//manually fill in maze
/*for(var i=0; i<19; i++)
{
maze1.button_grid[path[i]].onPath=1;
}*/

for(int j=0; j<27; j++) {
(maze1.button_grid[path[j]]).onPath=1;
for (int j = 0; j < 27; j++) {
(maze1.button_grid[path[j]]).onPath = 1;
}





return runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Memory Maker'),
backgroundColor: Colors.cyan,
),
backgroundColor: Colors.blue,
body: SubjectIDPage(),
)));
}
body: startingScreen(),
),
onGenerateRoute: (settings) {
print("settings.name " + settings.name);

urlArgs = getURLArgs(settings.name);
urlArgs.forEach((key, value) => print('${key}: ${value}'));

if (urlArgs.containsKey('id')) {
subjectID = urlArgs['id'];
}

// check for /?id=1234&time=2.0
switch (settings.name[1]) {
case '?':
return MaterialPageRoute(
builder: (context) => startingScreen(),
);
break;
default:
return MaterialPageRoute(
builder: (context) => startingScreen(),
);
}
}));
}
40 changes: 40 additions & 0 deletions lib/url_args.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';

Map<String, String> getURLArgs(String str) {
// return the URL arguments in a Map
Map<String, String> result = {};

// components of URL
List comp = [];
List pair = [];

// get index of first question mark
var firstQm = str.indexOf('?');
// get index of first &
var firstAmp = str.indexOf('&');

// check if there is a ?
if (firstQm > 0) {
comp = str.split('?');
//print(comp);
var newStr = comp[1]; // the portion after ?

if (firstAmp > 0) {
//split
comp = newStr.split('&');
//print(comp);
}

for (var i = 0; i < comp.length; i++) {
// extract out each section
//print(comp[i]);
pair = comp[i].split('=');
print(pair);
// insert into map
result[pair[0]] = pair[1];
}
/*result["id"] = 'abcd';
result["time"] = '3.0';*/
}
return result;
}
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.1"
audio_session:
dependency: transitive
description:
Expand Down Expand Up @@ -35,7 +35,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -218,7 +218,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -363,7 +363,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.2"
typed_data:
dependency: transitive
description:
Expand Down

0 comments on commit 54bc43e

Please sign in to comment.