Skip to content

Commit

Permalink
try to set size for desktop and web to prevent overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinlim committed Feb 8, 2021
1 parent 5938846 commit f1c1097
Showing 1 changed file with 92 additions and 24 deletions.
116 changes: 92 additions & 24 deletions lib/MazeTest.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//import necessary packages
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:convert';
Expand All @@ -26,6 +27,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 @@ -303,6 +305,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 @@ -317,27 +350,31 @@ 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];

}
),
]
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];

}
),
]
),
),
),
);
Expand All @@ -353,15 +390,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,

0 comments on commit f1c1097

Please sign in to comment.