Skip to content

Commit 97687ac

Browse files
authored
feat: Enhance configuration documentation and integrate OTP routing in HomeScreen and TransportList (#810)
1 parent 707cc04 commit 97687ac

20 files changed

Lines changed: 182 additions & 65 deletions

File tree

apps/example/README.md

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,76 @@ flutter run
8686

8787
## Configuration
8888

89-
The app is configured to use:
90-
- **OTP Endpoint**: `https://otp-240.trufi-core.trufi.dev`
89+
All configuration is at the top of [lib/main.dart](lib/main.dart). Modify these values for your deployment:
90+
91+
### Required Parameters
92+
93+
| Parameter | Description |
94+
|-----------|-------------|
95+
| `_otpConfiguration` | OTP server endpoint and version for route planning |
96+
| `_photonUrl` | Geocoding service URL for location search |
97+
| `_defaultCenter` | Initial map coordinates (latitude, longitude) |
98+
99+
### OTP Version
100+
101+
**IMPORTANT:** The `OtpVersion` must match your OTP server exactly:
102+
103+
| Version | API Type | Notes |
104+
|---------|----------|-------|
105+
| `OtpVersion.v1_5` | REST | Legacy servers |
106+
| `OtpVersion.v2_4` | GraphQL | Most common |
107+
| `OtpVersion.v2_8` | GraphQL | Latest, with emissions support |
108+
109+
Using the wrong version will cause routing errors.
110+
111+
### App Identity
112+
113+
| Parameter | Description |
114+
|-----------|-------------|
115+
| `_appName` | Display name in UI and shared routes |
116+
| `_deepLinkScheme` | URL scheme for deep links (e.g., `trufiapp://route/...`) |
117+
| `_cityName` | City name for About screen |
118+
| `_countryName` | Country name for About screen |
119+
| `_emailContact` | Support email |
120+
121+
### URLs
122+
123+
| Parameter | Description |
124+
|-----------|-------------|
125+
| `_feedbackUrl` | User feedback form URL |
126+
| `_facebookUrl` | Facebook page URL |
127+
| `_xTwitterUrl` | X (Twitter) profile URL |
128+
| `_instagramUrl` | Instagram profile URL |
129+
130+
### Geocoding Services
131+
132+
Two geocoding services are available:
133+
134+
**PhotonSearchService** (default):
135+
```dart
136+
PhotonSearchService(
137+
baseUrl: 'https://photon.komoot.io', // Required
138+
biasLatitude: -17.39, // Optional: prioritize nearby results
139+
biasLongitude: -66.16,
140+
)
141+
```
142+
143+
**NominatimSearchService** (alternative):
144+
```dart
145+
NominatimSearchService(
146+
baseUrl: 'https://nominatim.openstreetmap.org', // Required
147+
userAgent: 'MyApp/1.0', // Required
148+
countryCodes: ['bo'], // Optional: filter by country
149+
)
150+
```
151+
152+
### Current Values
153+
154+
- **OTP Endpoint**: `https://otp-240.trufi-core.trufi.dev` (v2.4)
91155
- **Default Location**: Cochabamba, Bolivia (-17.3988354, -66.1626903)
92-
- **Map Engines**: MapLibre GL and Flutter Map
156+
- **Map Engines**: MapLibre (Liberty and Dark styles)
93157
- **Deep Link Scheme**: `trufiapp://`
94158
- **POI Layers**: Tourism, Food, and Transport categories enabled by default
95-
- **POI Data**: Sample GeoJSON data for Cochabamba included in `assets/pois/`
96159

97160
## Dependencies
98161

apps/example/lib/main.dart

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,37 @@ import 'package:trufi_core_home_screen/trufi_core_home_screen.dart';
99
import 'package:trufi_core_maps/trufi_core_maps.dart';
1010
import 'package:trufi_core_navigation/trufi_core_navigation.dart';
1111
import 'package:trufi_core_poi_layers/trufi_core_poi_layers.dart';
12+
import 'package:trufi_core_routing/trufi_core_routing.dart'
13+
show OtpConfiguration, OtpVersion;
1214
import 'package:trufi_core_saved_places/trufi_core_saved_places.dart';
1315
import 'package:trufi_core_search_locations/trufi_core_search_locations.dart';
1416
import 'package:trufi_core_settings/trufi_core_settings.dart';
1517
import 'package:trufi_core_transport_list/trufi_core_transport_list.dart';
1618
import 'package:trufi_core_ui/trufi_core_ui.dart';
1719

20+
// ============ CONFIGURATION ============
21+
const _otpConfiguration = OtpConfiguration(
22+
endpoint: 'https://otp-240.trufi-core.trufi.dev',
23+
version: OtpVersion.v2_4,
24+
);
25+
const _photonUrl = 'https://photon.komoot.io';
1826
const _defaultCenter = LatLng(-17.3988354, -66.1626903);
27+
const _appName = 'Trufi App';
28+
const _deepLinkScheme = 'trufiapp';
29+
const _cityName = 'Cochabamba';
30+
const _countryName = 'Bolivia';
31+
const _emailContact = 'info@trufi-association.org';
32+
const _feedbackUrl = 'https://www.trufi-association.org/feedback/';
33+
const _facebookUrl = 'https://facebook.com/trufiapp';
34+
const _xTwitterUrl = 'https://x.com/trufiapp';
35+
const _instagramUrl = 'https://instagram.com/trufiapp';
36+
// ========================================
1937

2038
void main() {
2139
runTrufiApp(
2240
AppConfiguration(
23-
appName: 'Trufi App',
24-
deepLinkScheme: 'trufiapp',
41+
appName: _appName,
42+
deepLinkScheme: _deepLinkScheme,
2543
defaultLocale: Locale('es'),
2644
appOverlayManagers: [
2745
OnboardingManager(
@@ -35,17 +53,17 @@ void main() {
3553
],
3654
socialMediaLinks: const [
3755
SocialMediaLink(
38-
url: 'https://facebook.com/trufiapp',
56+
url: _facebookUrl,
3957
icon: Icons.facebook,
4058
label: 'Facebook',
4159
),
4260
SocialMediaLink(
43-
url: 'https://x.com/trufiapp',
61+
url: _xTwitterUrl,
4462
icon: Icons.close,
4563
label: 'X (Twitter)',
4664
),
4765
SocialMediaLink(
48-
url: 'https://instagram.com/trufiapp',
66+
url: _instagramUrl,
4967
icon: Icons.camera_alt_outlined,
5068
label: 'Instagram',
5169
),
@@ -60,6 +78,7 @@ void main() {
6078
BlocProvider(
6179
create: (_) => SearchLocationsCubit(
6280
searchLocationService: PhotonSearchService(
81+
baseUrl: _photonUrl,
6382
biasLatitude: _defaultCenter.latitude,
6483
biasLongitude: _defaultCenter.longitude,
6584
),
@@ -69,9 +88,9 @@ void main() {
6988
screens: [
7089
HomeScreenTrufiScreen(
7190
config: HomeScreenConfig(
72-
otpEndpoint: 'https://otp-240.trufi-core.trufi.dev',
73-
appName: 'Trufi App',
74-
deepLinkScheme: 'trufiapp',
91+
otpConfiguration: _otpConfiguration,
92+
appName: _appName,
93+
deepLinkScheme: _deepLinkScheme,
7594
poiLayersManager: POILayersManager(assetsBasePath: 'assets/pois'),
7695
),
7796
onStartNavigation: (context, itinerary, locationService) {
@@ -85,9 +104,7 @@ void main() {
85104
),
86105
SavedPlacesTrufiScreen(),
87106
TransportListTrufiScreen(
88-
config: TransportListOtpConfig(
89-
otpEndpoint: 'https://otp-240.trufi-core.trufi.dev',
90-
),
107+
otpConfiguration: _otpConfiguration,
91108
),
92109
FaresTrufiScreen(
93110
config: FaresConfig(
@@ -119,16 +136,16 @@ void main() {
119136
),
120137
FeedbackTrufiScreen(
121138
config: FeedbackConfig(
122-
feedbackUrl: 'https://www.trufi-association.org/feedback/',
139+
feedbackUrl: _feedbackUrl,
123140
),
124141
),
125142
SettingsTrufiScreen(),
126143
AboutTrufiScreen(
127144
config: AboutScreenConfig(
128-
appName: 'Trufi App',
129-
cityName: 'Cochabamba',
130-
countryName: 'Bolivia',
131-
emailContact: 'info@trufi-association.org',
145+
appName: _appName,
146+
cityName: _cityName,
147+
countryName: _countryName,
148+
emailContact: _emailContact,
132149
),
133150
),
134151
],

packages/screens/trufi_core_home_screen/example/lib/main.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'package:provider/provider.dart';
66
import 'package:trufi_core_home_screen/trufi_core_home_screen.dart';
77
import 'package:trufi_core_maps/trufi_core_maps.dart';
88
import 'package:trufi_core_poi_layers/trufi_core_poi_layers.dart';
9+
import 'package:trufi_core_routing/trufi_core_routing.dart'
10+
show OtpConfiguration, OtpVersion;
911
import 'package:trufi_core_search_locations/trufi_core_search_locations.dart';
1012

1113
void main() async {
@@ -17,14 +19,19 @@ void main() async {
1719
class MyApp extends StatelessWidget {
1820
static const _defaultCenter = LatLng(-17.3988354, -66.1626903);
1921
static const _otpEndpoint = 'https://otp-240.trufi-core.trufi.dev';
22+
static const _otpVersion = OtpVersion.v2_4;
23+
static const _photonUrl = 'https://photon.komoot.io';
2024

2125
const MyApp({super.key});
2226

2327
@override
2428
Widget build(BuildContext context) {
2529
final screen = HomeScreenTrufiScreen(
2630
config: HomeScreenConfig(
27-
otpEndpoint: _otpEndpoint,
31+
otpConfiguration: OtpConfiguration(
32+
endpoint: _otpEndpoint,
33+
version: _otpVersion,
34+
),
2835
poiLayersManager: POILayersManager(
2936
assetsBasePath: 'assets/pois',
3037
),
@@ -42,6 +49,7 @@ class MyApp extends StatelessWidget {
4249
BlocProvider(
4350
create: (_) => SearchLocationsCubit(
4451
searchLocationService: PhotonSearchService(
52+
baseUrl: _photonUrl,
4553
biasLatitude: _defaultCenter.latitude,
4654
biasLongitude: _defaultCenter.longitude,
4755
),

packages/screens/trufi_core_home_screen/example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ packages:
976976
source: path
977977
version: "1.0.0"
978978
trufi_core_routing:
979-
dependency: "direct overridden"
979+
dependency: "direct main"
980980
description:
981981
path: "../../../trufi_core_routing"
982982
relative: true

packages/screens/trufi_core_home_screen/example/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ dependencies:
1919
path: ../../../trufi_core_search_locations
2020
trufi_core_poi_layers:
2121
path: ../../../trufi_core_poi_layers
22+
trufi_core_routing:
23+
path: ../../../trufi_core_routing
2224
flutter_bloc: ^9.1.1
2325
latlong2: ^0.9.1
2426
provider: ^6.0.0

packages/screens/trufi_core_home_screen/lib/src/config/home_screen_config.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import 'package:trufi_core_maps/trufi_core_maps.dart';
22
import 'package:trufi_core_poi_layers/trufi_core_poi_layers.dart';
3+
import 'package:trufi_core_routing/trufi_core_routing.dart' show OtpConfiguration;
34
import 'package:trufi_core_search_locations/trufi_core_search_locations.dart';
45

56
/// Configuration for the Home Screen module.
67
class HomeScreenConfig {
7-
/// OTP server endpoint for route planning
8-
final String otpEndpoint;
8+
/// OTP configuration for route planning
9+
final OtpConfiguration otpConfiguration;
910

1011
/// Zoom level when choosing a location
1112
final double chooseLocationZoom;
1213

1314
/// Search service for location search (defaults to Photon)
1415
final SearchLocationService? searchService;
1516

16-
/// Photon server URL for search (used if searchService is not provided)
17-
final String photonUrl;
18-
1917
/// List of saved places to show in search (Home, Work, etc.)
2018
/// Only used if SavedPlacesCubit is not available in context.
2119
final List<SearchLocation> myPlaces;
@@ -59,10 +57,9 @@ class HomeScreenConfig {
5957
final POILayersManager? poiLayersManager;
6058

6159
const HomeScreenConfig({
62-
required this.otpEndpoint,
60+
required this.otpConfiguration,
6361
this.chooseLocationZoom = 16.0,
6462
this.searchService,
65-
this.photonUrl = 'https://photon.komoot.io/api/',
6663
this.myPlaces = const [],
6764
this.appName,
6865
this.deepLinkScheme,

packages/screens/trufi_core_home_screen/lib/src/home_screen_trufi_screen.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ class HomeScreenTrufiScreen extends TrufiScreen {
5252
_repository = repository ?? HomeScreenRepositoryImpl();
5353
_requestService =
5454
requestService ??
55-
RoutingRequestPlanService(
56-
routing.OtpConfiguration(endpoint: config.otpEndpoint),
57-
);
55+
RoutingRequestPlanService(config.otpConfiguration);
5856
_routingPreferencesManager = routing.RoutingPreferencesManager();
5957
}
6058

packages/screens/trufi_core_home_screen/test/trufi_core_home_screen_test.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter_test/flutter_test.dart';
22
import 'package:trufi_core_home_screen/trufi_core_home_screen.dart';
3+
import 'package:trufi_core_routing/trufi_core_routing.dart'
4+
show OtpConfiguration, OtpVersion;
35

46
void main() {
57
group('RoutePlannerState', () {
@@ -49,21 +51,28 @@ void main() {
4951

5052
group('HomeScreenConfig', () {
5153
test('has correct defaults', () {
52-
const config = HomeScreenConfig(otpEndpoint: 'https://example.com');
54+
const config = HomeScreenConfig(
55+
otpConfiguration: OtpConfiguration(
56+
endpoint: 'https://example.com',
57+
version: OtpVersion.v2_4,
58+
),
59+
);
5360

5461
expect(config.chooseLocationZoom, equals(16.0));
5562
expect(config.myPlaces, isEmpty);
5663
});
5764

5865
test('can set custom values', () {
5966
const config = HomeScreenConfig(
60-
otpEndpoint: 'https://example.com',
67+
otpConfiguration: OtpConfiguration(
68+
endpoint: 'https://example.com',
69+
version: OtpVersion.v2_8,
70+
),
6171
chooseLocationZoom: 18.0,
62-
photonUrl: 'https://custom.photon.url/api/',
6372
);
6473

6574
expect(config.chooseLocationZoom, equals(18.0));
66-
expect(config.photonUrl, equals('https://custom.photon.url/api/'));
75+
expect(config.otpConfiguration.version, equals(OtpVersion.v2_8));
6776
});
6877
});
6978
}

packages/screens/trufi_core_transport_list/example/lib/main.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'package:flutter_localizations/flutter_localizations.dart';
33
import 'package:latlong2/latlong.dart';
44
import 'package:provider/provider.dart';
55
import 'package:trufi_core_maps/trufi_core_maps.dart';
6+
import 'package:trufi_core_routing/trufi_core_routing.dart'
7+
show OtpConfiguration, OtpVersion;
68
import 'package:trufi_core_transport_list/trufi_core_transport_list.dart';
79

810
void main() {
@@ -12,13 +14,17 @@ void main() {
1214
class MyApp extends StatelessWidget {
1315
static const _defaultCenter = LatLng(-17.3988354, -66.1626903);
1416
static const _otpEndpoint = 'https://otp-240.trufi-core.trufi.dev';
17+
static const _otpVersion = OtpVersion.v2_4;
1518

1619
const MyApp({super.key});
1720

1821
@override
1922
Widget build(BuildContext context) {
2023
final screen = TransportListTrufiScreen(
21-
config: TransportListOtpConfig(otpEndpoint: _otpEndpoint),
24+
otpConfiguration: OtpConfiguration(
25+
endpoint: _otpEndpoint,
26+
version: _otpVersion,
27+
),
2228
);
2329

2430
return MultiProvider(

packages/screens/trufi_core_transport_list/example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ packages:
10071007
source: path
10081008
version: "1.0.0"
10091009
trufi_core_routing:
1010-
dependency: "direct overridden"
1010+
dependency: "direct main"
10111011
description:
10121012
path: "../../../trufi_core_routing"
10131013
relative: true

0 commit comments

Comments
 (0)