-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable accessing INT ROKAS data (#54)
* feat: SBBRokasMapStyler has int switch * chore: document access to INT data
- Loading branch information
1 parent
08e7f7a
commit 5aedf40
Showing
7 changed files
with
239 additions
and
52 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
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
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,107 @@ | ||
import 'package:design_system_flutter/design_system_flutter.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:sbb_maps_example/env.dart'; | ||
import 'package:sbb_maps_example/theme_provider.dart'; | ||
import 'package:sbb_maps_flutter/sbb_maps_flutter.dart'; | ||
|
||
class IntegrationDataRoute extends StatefulWidget { | ||
const IntegrationDataRoute({super.key}); | ||
|
||
@override | ||
State<IntegrationDataRoute> createState() => _IntegrationDataRouteState(); | ||
} | ||
|
||
class _IntegrationDataRouteState extends State<IntegrationDataRoute> { | ||
bool useIntegration = false; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final mapStyler = SBBRokasMapStyler.full( | ||
apiKey: useIntegration ? Env.journeyMapsTilesIntApiKey : Env.journeyMapsTilesApiKey, | ||
isDarkMode: Provider.of<ThemeProvider>(context).isDark, | ||
useIntegrationData: useIntegration, | ||
); | ||
|
||
return Scaffold( | ||
appBar: const SBBHeader(title: 'Integration Data'), | ||
body: SBBMap( | ||
mapStyler: mapStyler, | ||
isMyLocationEnabled: false, | ||
isFloorSwitchingEnabled: true, | ||
builder: (context) => Align( | ||
alignment: Alignment.topRight, | ||
child: Padding( | ||
padding: const EdgeInsets.all(sbbDefaultSpacing), | ||
child: SBBMapIconButton( | ||
onPressed: () { | ||
showSBBModalSheet<bool>( | ||
context: context, | ||
title: 'Integration Data', | ||
child: _IntegrationDataModalBody(useIntegration: useIntegration), | ||
).then(_setStateWithProperties); | ||
}, | ||
icon: SBBIcons.gears_small, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
void _setStateWithProperties(bool? useIntegration) { | ||
setState( | ||
() { | ||
if (useIntegration != null) { | ||
this.useIntegration = useIntegration; | ||
} | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class _IntegrationDataModalBody extends StatefulWidget { | ||
const _IntegrationDataModalBody({required this.useIntegration}); | ||
|
||
final bool useIntegration; | ||
|
||
@override | ||
State<_IntegrationDataModalBody> createState() => _IntegrationDataModalBodyState(); | ||
} | ||
|
||
class _IntegrationDataModalBodyState extends State<_IntegrationDataModalBody> { | ||
late bool _useIntegration; | ||
|
||
@override | ||
void initState() { | ||
_useIntegration = widget.useIntegration; | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric( | ||
vertical: sbbDefaultSpacing, | ||
horizontal: sbbDefaultSpacing, | ||
), | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
SBBCheckboxListItem( | ||
value: _useIntegration, | ||
label: 'Use INT Data', | ||
secondaryLabel: 'Accesses developer-int.sbb.ch data.', | ||
onChanged: (v) => setState(() { | ||
_useIntegration = v ?? false; | ||
}), | ||
isLastElement: true, | ||
), | ||
const SizedBox(height: sbbDefaultSpacing), | ||
SBBPrimaryButton(label: 'Apply Changes', onPressed: () => Navigator.pop(context, _useIntegration)), | ||
const SizedBox(height: sbbDefaultSpacing), | ||
], | ||
), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,49 +1,67 @@ | ||
import 'package:sbb_maps_flutter/sbb_maps_flutter.dart'; | ||
import 'package:sbb_maps_flutter/src/sbb_map_style/api_key_missing_exception.dart'; | ||
import 'package:test/expect.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('Unit Test SBBRokasMapStyler', () { | ||
group('initalization', () { | ||
test('whenFull_shouldReturnCustomMapStylerWithAllStyleIds', () { | ||
// act | ||
final actual = SBBRokasMapStyler.full(apiKey: 'key'); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(true)); | ||
expect(actual.getStyleIds().contains('journey_maps_bright_v1'), equals(true)); | ||
}); | ||
|
||
test('whenFull_shouldReturnInBrightMode', () { | ||
// act | ||
final actual = SBBRokasMapStyler.full(apiKey: 'key'); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.isDarkMode, equals(false)); | ||
}); | ||
|
||
test('whenFull_shouldReturnStyleUriInBrightMode', () { | ||
// arrange | ||
const expectedUri = 'https://journey-maps-tiles.geocdn.sbb.ch' | ||
'/styles/journey_maps_bright_v1/style.json?api_key=key'; | ||
|
||
// act | ||
final actual = SBBRokasMapStyler.full(apiKey: 'key'); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.currentStyleURI, equals(expectedUri)); | ||
}); | ||
|
||
test('whenNoAerial_shouldNotHaveAerial', () { | ||
// act | ||
final actual = SBBRokasMapStyler.noAerial(apiKey: 'key'); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(false)); | ||
}); | ||
test('whenFull_shouldReturnCustomMapStylerWithAllStyleIds', () { | ||
// act | ||
final actual = SBBRokasMapStyler.full(apiKey: 'key'); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(true)); | ||
expect(actual.getStyleIds().contains('journey_maps_bright_v1'), equals(true)); | ||
}); | ||
|
||
test('whenFull_shouldReturnInBrightMode', () { | ||
// act | ||
final actual = SBBRokasMapStyler.full(apiKey: 'key'); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.isDarkMode, equals(false)); | ||
}); | ||
|
||
test('whenFull_shouldReturnStyleUriInBrightMode', () { | ||
// arrange | ||
const expectedUri = 'https://journey-maps-tiles.geocdn.sbb.ch' | ||
'/styles/journey_maps_bright_v1/style.json?api_key=key'; | ||
|
||
// act | ||
final actual = SBBRokasMapStyler.full(apiKey: 'key'); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.currentStyleURI, equals(expectedUri)); | ||
}); | ||
|
||
test('whenNoAerial_shouldNotHaveAerial', () { | ||
// act | ||
final actual = SBBRokasMapStyler.noAerial(apiKey: 'key'); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.getStyleIds().contains('journey_maps_aerial_v1'), equals(false)); | ||
}); | ||
|
||
test('whenNoApiKey_shouldThrowApiKeyMissingException', () { | ||
// act + expect | ||
expect(() => SBBRokasMapStyler.full(), throwsA(const TypeMatcher<ApiKeyMissing>())); | ||
}); | ||
|
||
test('whenUseIntegrationDataIsTrue_uriShouldBeIntPointing', () { | ||
// arrange | ||
const expectedUri = 'https://journey-maps-tiles.geocdn-int.sbb.ch' | ||
'/styles/journey_maps_bright_v1/style.json?api_key=key'; | ||
|
||
// act | ||
final actual = SBBRokasMapStyler.full(apiKey: 'key', useIntegrationData: true); | ||
|
||
// expect | ||
expect(actual, isA<SBBCustomMapStyler>()); | ||
expect(actual.currentStyleURI, equals(expectedUri)); | ||
}); | ||
}); | ||
} |