Skip to content

Commit

Permalink
Merge pull request #155 from Nesteo/mapping-enums-to-strings
Browse files Browse the repository at this point in the history
Mapping enums to strings
  • Loading branch information
SimonOyen authored Nov 24, 2019
2 parents 7e56927 + 46b30ba commit 5bfccec
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 50 deletions.
22 changes: 21 additions & 1 deletion lib/generated/locale_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class LocaleboxNew {
final Map<String, String> _data;
LocaleboxNew(this._data);

String get id => _data["id"];
String get ids => _data["ids"];
String get oldid => _data["oldid"];
String get addBox => _data["addBox"];
String get hangDate => _data["hangDate"];
Expand All @@ -112,6 +112,22 @@ class LocaleboxNew {
String get veryLarge => _data["veryLarge"];
String get oval => _data["oval"];
String get openFronted => _data["openFronted"];
String get idOptional => _data["idOptional"];
String get oldIdOptional => _data["oldIdOptional"];
String get foreignIdOptional => _data["foreignIdOptional"];
String get date => _data["date"];
String get selectDate => _data["selectDate"];
String get box => _data["box"];
String get region => _data["region"];
String get newRegionIdPrefix => _data["newRegionIdPrefix"];
String get newRegionName => _data["newRegionName"];
String get position => _data["position"];
String get longitude => _data["longitude"];
String get latitude => _data["latitude"];
String get addGpsData => _data["addGpsData"];
String get owner => _data["owner"];
String get newOwnerName => _data["newOwnerName"];
String get comment => _data["comment"];
}
class LocaleholeSizeMapping {
final Map<String, String> _data;
Expand Down Expand Up @@ -150,6 +166,10 @@ class LocaleinspectionList {
String get numberOfEggs => _data["numberOfEggs"];
String get repaired => _data["repaired"];
String get numberOfChicks => _data["numberOfChicks"];
String get eggs => _data["eggs"];
String get birds => _data["birds"];
String get newSpecies => _data["newSpecies"];
String get addInspection => _data["addInspection"];
}
class Localelogin {
final Map<String, String> _data;
Expand Down
70 changes: 47 additions & 23 deletions lib/screens/newbox_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _NewBoxDataState extends State<NewBoxData> {
Icon(FontAwesomeIcons.hashtag),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Text("IDs"))
child: Text(loc.boxNew.ids))
],
),
subtitle: Column(
Expand All @@ -92,7 +92,7 @@ class _NewBoxDataState extends State<NewBoxData> {
child: TextFormField(
textAlign: TextAlign.left,
decoration: InputDecoration(
labelText: "ID - optional",
labelText: loc.boxNew.idOptional,
filled: true,
fillColor: Colors.white,
),
Expand All @@ -111,7 +111,7 @@ class _NewBoxDataState extends State<NewBoxData> {
child: TextFormField(
textAlign: TextAlign.left,
decoration: InputDecoration(
labelText: "old ID - optional",
labelText: loc.boxNew.oldIdOptional,
filled: true,
fillColor: Colors.white,
),
Expand All @@ -130,7 +130,7 @@ class _NewBoxDataState extends State<NewBoxData> {
child: TextFormField(
textAlign: TextAlign.left,
decoration: InputDecoration(
labelText: "foreign ID - optional",
labelText: loc.boxNew.foreignIdOptional,
filled: true,
fillColor: Colors.white,
),
Expand All @@ -152,13 +152,13 @@ class _NewBoxDataState extends State<NewBoxData> {
Icon(FontAwesomeIcons.calendarAlt),
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 10, 10)),
Text("Date"),
Text(loc.boxNew.date),
]),
subtitle: Padding(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: DateTimePickerFormField(
decoration: InputDecoration(
labelText: "select Day",
labelText: loc.boxNew.selectDate,
filled: true,
fillColor: Colors.white,
),
Expand All @@ -178,7 +178,7 @@ class _NewBoxDataState extends State<NewBoxData> {
Icon(FontAwesomeIcons.box),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Text("Box"))
child: Text(loc.boxNew.box))
],
),
subtitle: Column(
Expand All @@ -187,14 +187,14 @@ class _NewBoxDataState extends State<NewBoxData> {
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Row(
children: <Widget>[
Expanded(child: Text("Material:")),
Expanded(child: Text(loc.boxNew.material)),
_createMaterialSelection(context),
],
)),
Row(
children: <Widget>[
Expanded(
child: Text("Hole size:"),
child: Text(loc.boxNew.holeSize),
),
_createHoleSizeSlider()
],
Expand All @@ -210,7 +210,7 @@ class _NewBoxDataState extends State<NewBoxData> {
Icon(FontAwesomeIcons.globe),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Text("Region")),
child: Text(loc.boxNew.region)),
],
),
subtitle: Column(
Expand Down Expand Up @@ -259,7 +259,7 @@ class _NewBoxDataState extends State<NewBoxData> {
maxLength: 1,
textAlign: TextAlign.left,
decoration: InputDecoration(
labelText: "New Region ID Prefix",
labelText: loc.boxNew.newRegionIdPrefix,
filled: true,
fillColor: Colors.white,
),
Expand All @@ -273,7 +273,7 @@ class _NewBoxDataState extends State<NewBoxData> {
maxLines: 1,
textAlign: TextAlign.left,
decoration: InputDecoration(
labelText: "New Region Name",
labelText: loc.boxNew.newRegionName,
filled: true,
fillColor: Colors.white,
),
Expand All @@ -294,7 +294,7 @@ class _NewBoxDataState extends State<NewBoxData> {
Icon(FontAwesomeIcons.globeAmericas),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Text("Position")),
child: Text(loc.boxNew.position)),
],
),
subtitle: Column(
Expand All @@ -306,7 +306,7 @@ class _NewBoxDataState extends State<NewBoxData> {
readOnly: true,
decoration: InputDecoration(
labelText:
"Latitude ${(_position == null) ? "" : _position.latitude}",
"${loc.boxNew.latitude} ${(_position == null) ? "" : _position.latitude}",
filled: true,
fillColor: Colors.white,
),
Expand All @@ -318,7 +318,7 @@ class _NewBoxDataState extends State<NewBoxData> {
textAlign: TextAlign.left,
decoration: InputDecoration(
labelText:
"Longitude ${(_position == null) ? "" : _position.longitude}",
"${loc.boxNew.longitude} ${(_position == null) ? "" : _position.longitude}",
filled: true,
fillColor: Colors.white,
),
Expand All @@ -330,7 +330,7 @@ class _NewBoxDataState extends State<NewBoxData> {
Padding(
padding:
EdgeInsets.fromLTRB(10, 10, 10, 10),
child: (Text("Add GPS Data"))),
child: (Text(loc.boxNew.addGpsData))),
IconButton(
icon: Icon(Icons.gps_fixed),
onPressed: () async {
Expand Down Expand Up @@ -364,7 +364,7 @@ class _NewBoxDataState extends State<NewBoxData> {
Icon(FontAwesomeIcons.userAlt),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Text("Owner")),
child: Text(loc.boxNew.owner)),
],
),
subtitle: Column(
Expand Down Expand Up @@ -411,7 +411,7 @@ class _NewBoxDataState extends State<NewBoxData> {
maxLines: 1,
textAlign: TextAlign.left,
decoration: InputDecoration(
labelText: "New Owner Name",
labelText: loc.boxNew.newOwnerName,
filled: true,
fillColor: Colors.white,
),
Expand All @@ -432,7 +432,7 @@ class _NewBoxDataState extends State<NewBoxData> {
Icon(FontAwesomeIcons.comment),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Text("Comment"))
child: Text(loc.boxNew.comment))
],
),
subtitle: TextFormField(
Expand Down Expand Up @@ -473,7 +473,7 @@ class _NewBoxDataState extends State<NewBoxData> {
);
},
child: Text(
"Create new Nesting Box",
loc.boxNew.addBox,
style: TextStyle(
fontSize: 20,
color: Colors.white,
Expand Down Expand Up @@ -507,7 +507,7 @@ class _NewBoxDataState extends State<NewBoxData> {
child: DropdownButton<String>(
value:
(_dropDownMaterial != null) ? _dropDownMaterial : "UntreatedWood",
icon: Icon(Icons.arrow_downward),
icon: Icon(Icons.arrow_drop_down),
iconSize: 24,
onChanged: (String newValue) {
setState(() {
Expand All @@ -522,7 +522,7 @@ class _NewBoxDataState extends State<NewBoxData> {
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
child: Text(getDropDownTexts(value)),
);
}).toList(),
),
Expand All @@ -536,7 +536,7 @@ class _NewBoxDataState extends State<NewBoxData> {
min: 0,
max: 5,
divisions: 5,
label: getSliderLabel(_slideHoleSize),
label: getLocalizedSliderLabel(_slideHoleSize),
onChanged: (double newValue) {
setState(() {
_slideHoleSize = newValue;
Expand All @@ -546,6 +546,17 @@ class _NewBoxDataState extends State<NewBoxData> {
);
}

String getDropDownTexts(String value) {
final loc = Localizations.of<LocaleBase>(context, LocaleBase);
var map = {
"UntreatedWood": loc.boxNew.untreatedWood,
"TreatedWood": loc.boxNew.treatedWood,
"WoodConcrete": loc.boxNew.concrete,
"Other": loc.boxNew.otherMaterial,
};
return map[value];
}

String getSliderLabel(double value) {
final loc = Localizations.of<LocaleBase>(context, LocaleBase);
var sizeMap = {
Expand All @@ -558,4 +569,17 @@ class _NewBoxDataState extends State<NewBoxData> {
};
return sizeMap[value];
}

String getLocalizedSliderLabel(double value) {
final loc = Localizations.of<LocaleBase>(context, LocaleBase);
var sizeMap = {
0: loc.boxNew.small,
1: loc.boxNew.medium,
2: loc.boxNew.large,
3: loc.boxNew.veryLarge,
4: loc.boxNew.oval,
5: loc.boxNew.openFronted,
};
return sizeMap[value];
}
}
Loading

0 comments on commit 5bfccec

Please sign in to comment.