Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from antonschulz/planning_lab
Planning lab first version
- Loading branch information
Showing
4 changed files
with
320 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |