Skip to content

Commit

Permalink
Merge pull request #10 from antonschulz/planning_lab
Browse files Browse the repository at this point in the history
Planning lab first version
  • Loading branch information
DowLucas committed Mar 31, 2022
2 parents 51fab6f + 0e84a52 commit 8c7fb1b
Show file tree
Hide file tree
Showing 4 changed files with 320 additions and 17 deletions.
48 changes: 31 additions & 17 deletions lib/exhibition_map/map.dart
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:zero_city/zones/planning_lab/mission1a.dart';

class Mission {
final String name;
Expand All @@ -8,14 +9,12 @@ class Mission {
}

class MissionButton extends StatelessWidget {

MissionButton({
required this.mission,
required this.left,
required this.top,
required this.width,
required this.height,

}) : super(key: ObjectKey(mission));

final Mission mission;
Expand All @@ -24,7 +23,6 @@ class MissionButton extends StatelessWidget {
final double width;
final double height;


@override
Widget build(BuildContext context) {
return Positioned(
Expand All @@ -35,12 +33,12 @@ class MissionButton extends StatelessWidget {
height: height,
child: Text("Hello ${mission.name}"),
decoration: BoxDecoration(
color: const Color(0xff7c94b6),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.black,
width: 1
)
color: const Color(0xff7c94b6),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.black,
width: 1,
),
),
),
);
Expand All @@ -49,26 +47,42 @@ class MissionButton extends StatelessWidget {

List<Mission> missions = [
Mission("The High Street", 1),
Mission("Planning Lab", 1),
];

List<MissionButton> missionButtons = [
MissionButton(mission: missions[0], left: 100.0, top: 0, width: 100.0, height: 100.0)
MissionButton(
mission: missions[0], left: 100.0, top: 0, width: 100.0, height: 100.0),
MissionButton(
mission: missions[1], left: 200.0, top: 500, width: 100.0, height: 100.0)
];


Mission noMissionSelected = Mission("No mission selected", 0);

class ExhibitionMap extends StatelessWidget {
const ExhibitionMap({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: missionButtons,
)
return Column(
children: [
// TODO: Decide on how to create the map page
// With buttons or something else?
// Scaffold(
// body: Stack(
// children: missionButtons,
// ),
// ),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Mission1A()),
);
},
child: const Text("Planning Lab"),
)
],
);
}
}


131 changes: 131 additions & 0 deletions lib/zones/planning_lab/mission1a.dart
@@ -0,0 +1,131 @@
import 'package:flutter/material.dart';
import 'package:zero_city/zones/planning_lab/mission1b.dart';
// import 'package:zero_city/const text_types/mission_body.dart';
// import 'package:zero_city/const text_types/mission_title.dart';

class Mission1A extends StatefulWidget {
const Mission1A({Key? key}) : super(key: key);

@override
State<Mission1A> createState() => Mission1AState();
}

class Mission1AState extends State<Mission1A> {
// Strings for the boxes
final List<String> strs = [
"Egen bil som drivs med fossila bränslen",
"Att köpa nya kläder",
"Att äta kött",
"En ny smartphone",
"En ny dator",
"Flygresor",
"Nya möbler",
"Sociala medier",
"Nytt tv-spel",
"Julklappar",
"Stort boende",
"Husdjur, som katt eller hund",
"Att äga en egen bil",
"Varma bostäder (max 19 grader)",
"Shoppinggallerior",
"Swimmingpool",
"E-handel",
"Eget rum",
"Fotbollsplaner med konstgräs",
"Mat och godis som innehåller palmolja",
"Snabbmat",
"Sommarstuga",
"Avokado och exotiska frukter",
"Bubbelvatten och sportdrycker",
];

// List to keep answers
List<String> answers = [];

// Corresponding list of booleans to keep track if the button is clicked
List<bool> clicked = List.filled(24, false);

// Count number of buttos pressed
var _count = 0;

// Color for continue button
Color color = Colors.grey;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
// MissionTitle("Planning Lab 1a"),
// MissionBody(
// "Vad är ni beredda att avstå från? Välj fem olika alternativ."),
// Has to be flexible to avoid endless scroll error
Flexible(
child: GridView.count(
primary: false,
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 32),
crossAxisSpacing: 8,
mainAxisSpacing: 8,
crossAxisCount: 6,
// All option buttons are produced through this code
// Creates a list of length 24
// For every index of said list: creates a button with text from
// Corresponding index of list strs
children: List.generate(24, (index) {
return ElevatedButton(
onPressed: () => {
setState(() {
// If clicked is false <=> button isn't currently pressed
// Now set clicked to true and increment _counter
// If 5 options are already picked: do nothing
if (!clicked[index] && _count < 5) {
clicked[index] = !clicked[index];
answers.add(strs[index]);
_count++;
if (_count == 5) {
// Sets continue button colour for UI help
color = Colors.green;
}
// User can deselect an option
} else if (clicked[index]) {
clicked[index] = !clicked[index];
answers.remove(strs[index].toString());
_count--;
color = Colors.grey;
}
}),
},
child: Text(
strs[index],
),
// Different colour if clicked
style: ElevatedButton.styleFrom(
primary: clicked[index]
? const Color.fromRGBO(151, 144, 187, 1)
: Colors.grey[400],
onPrimary: Colors.black,
),
);
}),
),
),
// Navigator button to next mission page, mission 1b
ElevatedButton(
onPressed: () {
if (_count == 5) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Mission1B(answers)),
);
}
},
child: const Text("Fortsätt till uppdrag 1b"),
style: ElevatedButton.styleFrom(
primary: color,
),
),
],
),
);
}
}
87 changes: 87 additions & 0 deletions lib/zones/planning_lab/mission1b.dart
@@ -0,0 +1,87 @@
import 'package:flutter/material.dart';
import 'package:zero_city/zones/planning_lab/mission1c.dart';
// import 'package:zero_city/const text_types/mission_body.dart';
// import 'package:zero_city/const text_types/mission_title.dart';

class Mission1B extends StatefulWidget {
List<String> inputList;

Mission1B(this.inputList, {Key? key}) : super(key: key);

@override
State<Mission1B> createState() => _Mission1BState(inputList);
}

class _Mission1BState extends State<Mission1B> {
final List<String> inputList;

_Mission1BState(this.inputList);

int _group = 0;
Color color = Colors.grey;
bool correct = false;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
// MissionTitle("Planning Lab 1b"),
// MissionBody(
// "Välj ett av alternativen nedan som ni valde i fråga 1a
// att avstå ifrån.
// Försök att komma på något miljösmart det kan ersättas med.")

Column(
children: List.generate(
5,
(index) {
return RadioListTile(
title: Text(inputList[index]),
value: index,
groupValue: _group,
onChanged: (value) {
setState(() {
_group = index;
});
},
);
},
),
),
TextField(
decoration: const InputDecoration(
hintText: "Miljösmart ersättning",
),
onSubmitted: (String str) {
setState(() {
// Assign the typed str to inputStr
if (str != "") {
correct = true;
color = Colors.green;
}
});
},
),
Container(
margin: const EdgeInsets.only(top: 10.0),
child: ElevatedButton(
onPressed: () {
if (correct) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Mission1C()),
);
}
},
child: const Text("Fortsätt till uppdrag 1c"),
style: ElevatedButton.styleFrom(
primary: color,
),
),
),
],
),
);
}
}
71 changes: 71 additions & 0 deletions lib/zones/planning_lab/mission1c.dart
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:zero_city/exhibition_map/map.dart';
// import 'package:zero_city/const text_types/mission_body.dart';
// import 'package:zero_city/const text_types/mission_title.dart';

class Mission1C extends StatefulWidget {
const Mission1C({Key? key}) : super(key: key);

@override
State<Mission1C> createState() => _Mission1CState();
}

class _Mission1CState extends State<Mission1C> {
Color color = Colors.grey;
final TextEditingController textController = TextEditingController();
bool correct = false;
String correctProcent = "123";
String _hint = "Skriv 123";

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
// MissionTitle("Planning Lab 1c"),
// MissionBody("Hur många procent av tiden står en bil stilla?
//Svaret hittar ni i utställningen."),
TextField(
decoration: InputDecoration(
hintText: _hint,
),
onSubmitted: (String str) {
setState(() {
// Assign the typed str to inputStr
if (str == correctProcent) {
correct = true;
_hint = correctProcent + " är rätt svar!";
color = Colors.green;
} else {
_hint = "Försök igen";
}
});
// Set textController to ""
// In essence, removes the typed string from
// the input box when submitted
textController.text = "";
},
controller: textController,
keyboardType: TextInputType.number,
maxLength: 3,
),
ElevatedButton(
onPressed: () {
if (correct) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ExhibitionMap()),
);
}
},
child: const Text("Gå tillbaka till kartan"),
style: ElevatedButton.styleFrom(
primary: color,
),
),
],
),
);
}
}

0 comments on commit 8c7fb1b

Please sign in to comment.