Skip to content

Commit

Permalink
Merging pull
Browse files Browse the repository at this point in the history
  • Loading branch information
KhalidIshani committed Feb 16, 2021
2 parents 4d2d620 + 74fd5ba commit 040f595
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 40 deletions.
7 changes: 5 additions & 2 deletions lib/Maze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'PathGeneration.dart';
import 'server.dart';
import 'main.dart';
import 'instructions.dart';
import 'package:uuid/uuid.dart';

var uuid = Uuid();

class gameButton extends StatefulWidget {
int id;
Expand Down Expand Up @@ -157,7 +160,7 @@ class gameButtonState extends State<gameButton> {
if(widget.id==99) {
var dict = {"path":path, "moves": moves, "errors": errors, "times": times};
String data = json.encode(dict);
createData("GMLT-10x10", "KI", data, "1.0");
createData("GMLT-10x10", uuid.v1().toString(), data, "1.0");
attemptNum++;
showDialog(
context: context,
Expand Down Expand Up @@ -337,4 +340,4 @@ class _MyHomePageState extends State<MyHomePage> {
),
);
}
}
}
148 changes: 110 additions & 38 deletions lib/MazeTest.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
//import necessary packages
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:convert';
import 'main.dart';
import 'server.dart';
import 'instructions.dart';
import 'package:uuid/uuid.dart';

var uuid = Uuid();

//initialize new maze
maze maze2= new maze();
Color color1 = Colors.grey;
Expand All @@ -23,6 +28,7 @@ int attemptNum2 = 1;
int consecErrors2 = 0;
int recentMove2; //records last move of user regardless of corectness


void main() {
runApp(MyApp());
//manually fill in maze
Expand Down Expand Up @@ -189,7 +195,7 @@ class gameButtonState extends State<gameButton> {
if(widget.id==35) {
var dict2 = {"path":path2, "moves": moves2, "errors": errors2, "times": times2};
String data = json.encode(dict2);
createData("GMLT-5x5", "KI", data, "1.0");
createData("GMLT-5x5", uuid.v1().toString(), data, "1.0");

showDialog(
context: context,
Expand Down Expand Up @@ -250,6 +256,7 @@ class gameButtonState extends State<gameButton> {
}
@override
//build actual GUI of "gamebutton" - a flatbutton with an icon hidden within it (either check or X)
//todo - How to create the grid based on the shortest dimension of the rectangle? This is to avoid the error bars.
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(border: Border.all(color: Colors.black)),
Expand Down Expand Up @@ -299,6 +306,37 @@ class mazeState extends State<maze> {
return true;
}

double getSmallestDimension() {
double width = MediaQuery
.of(context)
.size
.width;
double height = MediaQuery
.of(context)
.size
.height;
double result;

var deviceOrientation = MediaQuery.of(context).orientation;

if (deviceOrientation == Orientation.landscape) {
print("orientation: landscape");
} else {
print("orientation: portrait");
}

// return the lesser of the two
// var result = (height > width) ? width : height;
if (height>width) {
result = width;
} else {
result = height;
}

print("w: " + width.toString() + " h: " + height.toString() +
" result: " + result.toString());
return result;
}
//initialize state + start clock2 once
void initState()
{
Expand All @@ -313,41 +351,44 @@ class mazeState extends State<maze> {
return NotificationListener<PressNotification>(
onNotification: updateButton,
child:
Scaffold(
backgroundColor:Colors.cyan,
body: Column(
children: <Widget>[
GridView.builder(
//uniqueKey utilized so buttons that need to change color can dynamically rebuild
key: UniqueKey(),
itemCount: 36,
//squares kept in 10x10 gridview
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 6,
crossAxisSpacing: 0,
mainAxisSpacing: 0
),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return maze2.button_grid[index];

}
),

Align(
alignment: Alignment.bottomRight,
child: IconButton(
icon: Icon(Icons.help),
onPressed:() {
Navigator.push(
context,
new MaterialPageRoute(builder: (ctxt) => new SecondScreen()),
);
},
),
)

]
SizedBox(
width: null,
height: getSmallestDimension(),
child: Scaffold(
backgroundColor:Colors.cyan,
body: Column(
children: <Widget>[
GridView.builder(
//uniqueKey utilized so buttons that need to change color can dynamically rebuild
key: UniqueKey(),
itemCount: 36,
//squares kept in 10x10 gridview
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 6,
crossAxisSpacing: 0,
mainAxisSpacing: 0
),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return maze2.button_grid[index];

}
),
Align(
alignment: Alignment.bottomRight,
child: IconButton(
icon: Icon(Icons.help),
onPressed:() {
Navigator.push(
context,
new MaterialPageRoute(builder: (ctxt) => new SecondScreen()),
);
},
),
)
]
),
),
),
);
Expand All @@ -363,15 +404,46 @@ class MyHomePage extends StatefulWidget {
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {

double getSmallestDimension() {
double width = MediaQuery
.of(context)
.size
.width;
double height = MediaQuery
.of(context)
.size
.height;

print("w: " + width.toString() + " h: " + height.toString());
// return the lesser of the two
// var result = (height > width) ? width : height;
if (height>width) {
return width;
} else {
return height;
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(child: Text("GMT")),
),
body: Center(
child: maze2,
)
body: ConstrainedBox(
// // trying to constrain the dimensions on web and desktop
constraints: BoxConstraints(
maxHeight: getSmallestDimension(),
maxWidth: getSmallestDimension(),
),
child: Center(
child: maze2,
)
),
);
}
}

//width: MediaQuery.of(context).size.width,
//height: MediaQuery.of(context).size.height,
1 change: 1 addition & 0 deletions lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Future<Data> createData(

final http.Response response = await http.post(
'https://x0-29.psych.umn.edu/dend/posts',
//'https://160.94.0.29/dend/posts',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies:
rflutter_alert: ^1.0.3
http: ^0.12.2
json_annotation: ^3.1.1
uuid: ^2.2.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
Expand Down

0 comments on commit 040f595

Please sign in to comment.