Skip to content

Commit

Permalink
fix: indoor key property
Browse files Browse the repository at this point in the history
  • Loading branch information
matisiekpl committed Dec 11, 2024
1 parent a866c9e commit 15da053
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 49 deletions.
2 changes: 1 addition & 1 deletion assets/aed_poland.geojson

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/world.geojson

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions lib/bloc/edit/edit_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class EditCubit extends Cubit<EditState> {
cursor: state.cursor,
aed: aed,
access: aed.access ?? 'yes',
indoor: aed.indoor,
indoor: aed.indoor ?? 'no',
description: aed.description ?? ''));
}

Expand All @@ -61,7 +61,7 @@ class EditCubit extends Cubit<EditState> {
cursor: state.cursor,
aed: aed,
access: aed.access ?? 'yes',
indoor: aed.indoor,
indoor: aed.indoor ?? 'no',
description: aed.description ?? ''));
}

Expand Down Expand Up @@ -100,8 +100,9 @@ class EditCubit extends Cubit<EditState> {
editIndoor(bool value) {
var s = state;
if (s is EditInProgress) {
s.aed.indoor = value;
emit(s.copyWith(aed: s.aed, indoor: value));
var contents = value ? 'yes' : 'no';
s.aed.indoor = contents;
emit(s.copyWith(aed: s.aed, indoor: contents));
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/bloc/edit/edit_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class EditInProgress extends EditState {
{required super.enabled,
required super.cursor,
required this.aed,
this.indoor = false,
this.indoor = 'no',
this.access = 'public',
this.description = ''});

final AED aed;
final bool indoor;
final String indoor;
final String access;

final String description;
Expand All @@ -59,7 +59,7 @@ class EditInProgress extends EditState {
AED? aed,
bool? enabled,
LatLng? cursor,
bool? indoor,
String? indoor,
String? access,
String? description,
}) {
Expand Down
16 changes: 11 additions & 5 deletions lib/models/aed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AED {
LatLng location;
String? description;
int id;
bool indoor;
String? indoor;
String? operator;
String? phone;
int? distance = 0;
Expand All @@ -19,7 +19,7 @@ class AED {
{required this.location,
required this.id,
this.description,
this.indoor = false,
this.indoor,
this.operator,
this.phone,
this.openingHours,
Expand All @@ -45,6 +45,12 @@ class AED {
return colors[access];
}

String getIndoorText(AppLocalizations appLocalizations) {
if (indoor == 'yes') return appLocalizations.yes;
if (indoor == 'no') return appLocalizations.no;
return indoor ?? 'unknown';
}

String getIconFilename() {
if (access == null) return 'green_aed.svg';
Map filenames = {
Expand Down Expand Up @@ -91,8 +97,8 @@ class AED {
if (image != null && image.toString().isNotEmpty) {
builder.element('tag', attributes: {'k': 'image', 'v': image ?? ''});
}
builder.element('tag',
attributes: {'k': 'indoor', 'v': indoor ? 'yes' : 'no'});
builder
.element('tag', attributes: {'k': 'indoor', 'v': indoor ?? 'no'});
if (openingHours != null && openingHours.toString().isNotEmpty) {
builder.element('tag',
attributes: {'k': 'opening_hours', 'v': openingHours ?? ''});
Expand Down Expand Up @@ -128,7 +134,7 @@ class AED {
LatLng? location,
String? description,
int? id,
bool? indoor,
String? indoor,
String? operator,
String? phone,
int? distance,
Expand Down
2 changes: 1 addition & 1 deletion lib/repositories/points_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PointsRepository {
id: row['properties'][idLabel],
description: row['properties']['defibrillator:location'] ??
row['properties']['defibrillator:location:pl'],
indoor: row['properties']['indoor'] == 'yes',
indoor: row['properties']['indoor'],
operator: row['properties']['operator'],
phone: row['properties']['phone'],
openingHours: row['properties']['opening_hours'],
Expand Down
65 changes: 48 additions & 17 deletions lib/screens/edit/edit_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class EditForm extends StatelessWidget {
middle: Text(appLocalizations.editDefibrillator),
),
child: Theme(
data: MediaQuery.of(context).platformBrightness == Brightness.dark ? ThemeData.dark() : ThemeData.light(),
data: MediaQuery.of(context).platformBrightness == Brightness.dark
? ThemeData.dark()
: ThemeData.light(),
child: BlocBuilder<EditCubit, EditState>(builder: (context, state) {
if (state is EditInProgress) {
return SafeArea(
Expand All @@ -37,7 +39,8 @@ class EditForm extends StatelessWidget {
);
}

List<AbstractSettingsSection> _buildSections(BuildContext context, EditInProgress state) {
List<AbstractSettingsSection> _buildSections(
BuildContext context, EditInProgress state) {
var appLocalizations = AppLocalizations.of(context)!;
return [
SettingsSection(
Expand All @@ -48,20 +51,22 @@ class EditForm extends StatelessWidget {
title: TextFormField(
initialValue: state.aed.description,
onChanged: context.read<EditCubit>().editDescription,
decoration: InputDecoration.collapsed(hintText: appLocalizations.enterDescription),
decoration: InputDecoration.collapsed(
hintText: appLocalizations.enterDescription),
),
),
SettingsTile.navigation(
leading: const Icon(CupertinoIcons.arrow_clockwise_circle),
title: Text(appLocalizations.access),
value: Text(translateAccessComment(state.access, appLocalizations)),
onPressed: (_) {
_selectAccess(context, appLocalizations, context.read<EditCubit>());
_selectAccess(
context, appLocalizations, context.read<EditCubit>());
},
),
SettingsTile.switchTile(
onToggle: context.read<EditCubit>().editIndoor,
initialValue: state.aed.indoor,
initialValue: state.aed.indoor == 'yes',
leading: const Icon(CupertinoIcons.home),
title: Text(appLocalizations.insideBuilding),
),
Expand All @@ -70,15 +75,17 @@ class EditForm extends StatelessWidget {
title: TextFormField(
initialValue: state.aed.operator,
onChanged: context.read<EditCubit>().editOperator,
decoration: InputDecoration.collapsed(hintText: appLocalizations.enterOperator),
decoration: InputDecoration.collapsed(
hintText: appLocalizations.enterOperator),
),
),
SettingsTile(
leading: const Icon(CupertinoIcons.phone),
title: TextFormField(
initialValue: state.aed.phone,
onChanged: context.read<EditCubit>().editPhone,
decoration: InputDecoration.collapsed(hintText: appLocalizations.enterPhone),
decoration: InputDecoration.collapsed(
hintText: appLocalizations.enterPhone),
),
),
],
Expand All @@ -89,17 +96,31 @@ class EditForm extends StatelessWidget {
SettingsTile(
leading: const Icon(CupertinoIcons.globe),
title: Text(appLocalizations.longitude),
trailing: Text(state.aed.location.longitude.toString().characters.take(10).string,
trailing: Text(
state.aed.location.longitude
.toString()
.characters
.take(10)
.string,
style: TextStyle(
color:
MediaQuery.of(context).platformBrightness == Brightness.dark ? Colors.white : Colors.black))),
color: MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.white
: Colors.black))),
SettingsTile(
leading: const Icon(CupertinoIcons.globe),
title: Text(appLocalizations.latitude),
trailing: Text(state.aed.location.latitude.toString().characters.take(10).string,
trailing: Text(
state.aed.location.latitude
.toString()
.characters
.take(10)
.string,
style: TextStyle(
color:
MediaQuery.of(context).platformBrightness == Brightness.dark ? Colors.white : Colors.black))),
color: MediaQuery.of(context).platformBrightness ==
Brightness.dark
? Colors.white
: Colors.black))),
],
),
CustomSettingsSection(
Expand Down Expand Up @@ -129,17 +150,26 @@ class EditForm extends StatelessWidget {
];
}

void _selectAccess(BuildContext context, AppLocalizations appLocalizations, EditCubit editCubit) {
void _selectAccess(BuildContext context, AppLocalizations appLocalizations,
EditCubit editCubit) {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
var actions = ['yes', 'customers', 'private', 'permissive', 'no', 'unknown']
var actions = [
'yes',
'customers',
'private',
'permissive',
'no',
'unknown'
]
.map((label) => CupertinoActionSheetAction(
onPressed: () async {
editCubit.editAccess(label);
Navigator.of(context).pop();
},
child: Text(translateAccessComment(label, appLocalizations)),
child:
Text(translateAccessComment(label, appLocalizations)),
))
.toList();
actions.add(CupertinoActionSheetAction(
Expand All @@ -148,7 +178,8 @@ class EditForm extends StatelessWidget {
},
child: Text(appLocalizations.cancel),
));
return CupertinoActionSheet(title: Text(appLocalizations.chooseAccess), actions: actions);
return CupertinoActionSheet(
title: Text(appLocalizations.chooseAccess), actions: actions);
});
}
}
9 changes: 3 additions & 6 deletions lib/screens/map/bottom_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,16 @@ class BottomPanel extends StatelessWidget {
);
}),
const SizedBox(height: 4),
CrossFade<bool>(
CrossFade<String>(
duration: const Duration(milliseconds: 200),
value: state.selected.indoor,
value: state.selected.getIndoorText(appLocalizations),
builder: (context, v) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text('${appLocalizations.insideBuilding}: ',
style: const TextStyle(fontSize: 16)),
Text(
v
? appLocalizations.yes
: appLocalizations.no,
Text(v,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold)),
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/map/map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class _MapScreenState extends State<MapScreen> {
context: context,
builder: (BuildContext context) {
return AlertDialog(
surfaceTintColor: Colors.red.shade400,
surfaceTintColor: Colors.green.shade400,
title: Text(appLocalizations.dataSource),
content: Text(appLocalizations.dataSourceDescription),
actions: <Widget>[
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.37+37
version: 1.0.38+38

environment:
sdk: ^3.5.3
Expand Down
18 changes: 9 additions & 9 deletions test/edit_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void main() {
expect(editCubit.state.enabled, false);
expect((editCubit.state as EditInProgress).aed, isA<AED>());
expect((editCubit.state as EditInProgress).aed.id, 0);
expect((editCubit.state as EditInProgress).indoor, false);
expect((editCubit.state as EditInProgress).indoor, 'no');
});

test('edit', () async {
Expand All @@ -59,7 +59,7 @@ void main() {
id: 7,
location: warsaw,
description: 'test_description',
indoor: false,
indoor: 'no',
access: 'yes',
operator: 'test_operator',
phone: 'test_phone'));
Expand All @@ -69,7 +69,7 @@ void main() {
expect((editCubit.state as EditInProgress).aed.id, 7);
expect((editCubit.state as EditInProgress).aed.description,
'test_description');
expect((editCubit.state as EditInProgress).indoor, false);
expect((editCubit.state as EditInProgress).indoor, 'no');
expect((editCubit.state as EditInProgress).access, 'yes');
expect((editCubit.state as EditInProgress).aed.operator, 'test_operator');
expect((editCubit.state as EditInProgress).aed.phone, 'test_phone');
Expand All @@ -81,7 +81,7 @@ void main() {
id: 7,
location: warsaw,
description: 'test_description',
indoor: false,
indoor: 'no',
access: 'yes',
operator: 'test_operator',
phone: 'test_phone'));
Expand All @@ -99,14 +99,14 @@ void main() {
id: 7,
location: warsaw,
description: 'test_description',
indoor: false,
indoor: 'yes',
access: 'yes',
operator: 'test_operator',
phone: 'test_phone'));
editCubit.editIndoor(true);
expect(editCubit.state, isA<EditInProgress>());
expect((editCubit.state as EditInProgress).aed.indoor, true);
expect((editCubit.state as EditInProgress).indoor, true);
expect((editCubit.state as EditInProgress).aed.indoor, 'yes');
expect((editCubit.state as EditInProgress).indoor, 'yes');
});

test('editAccess', () async {
Expand All @@ -115,7 +115,7 @@ void main() {
id: 7,
location: warsaw,
description: 'test_description',
indoor: false,
indoor: 'no',
access: 'yes',
operator: 'test_operator',
phone: 'test_phone'));
Expand All @@ -131,7 +131,7 @@ void main() {
id: 7,
location: warsaw,
description: 'test_description',
indoor: false,
indoor: 'no',
access: 'yes',
operator: 'test_operator',
phone: 'test_phone'));
Expand Down

0 comments on commit 15da053

Please sign in to comment.