When to use Spider Sdk
The **Spider SDK** brings the full power of the Spider transit platform directly into your Flutter applications. By wrapping the Spider REST endpoints in a type‑safe Dart client, the package lets you request route calculations, search for stops, and receive live vehicle positions without writing any HTTP boilerplate. The SDK returns strongly‑typed models, handles pagination, and offers built‑in error mapping, so developers can focus on UI and business logic instead of networking minutiae.
If you are building a public‑transport app, a city guide, a logistics dashboard, or any solution that needs reliable, up‑to‑date transit information, Spider SDK is a natural fit. Its design aligns with common Flutter architectures – you can inject the client into a repository layer, expose the data through a BLoC, Provider, or Riverpod state manager, and let the UI react to streams of live updates. Because the SDK is pure Dart, it works on Android, iOS, web, and desktop, making it a versatile choice for cross‑platform projects.
Setting up the SDK is straightforward. After adding the dependency, instantiate `SpiderClient` with your API key and optional configuration such as timeout or base URL overrides. The client exposes high‑level methods like `planTrip`, `searchStops`, and `subscribeRealtime`. Each method returns a `Future` or a `Stream`, enabling both one‑off requests and continuous data feeds. For example, a trip planning request returns a `TripPlan` object that contains legs, durations, and fare estimates, while the realtime subscription streams `VehiclePosition` updates that can be fed directly into a map widget.
When moving to production, consider a few best practices. Cache static data such as stop lists locally to reduce network churn and improve start‑up speed. Respect rate limits by debouncing rapid user input and handling `429 Too Many Requests` responses gracefully. The SDK also provides a built‑in retry mechanism for transient failures, but you should still implement global error handling to surface user‑friendly messages. For secure environments, store your API key using FlutterSecureStorage or a similar solution rather than hard‑coding it.
For beginners, the SDK offers a low barrier to entry. A simple Flutter screen can display a search bar, call `searchStops`, and render results in a `ListView`. Adding a map with live vehicle markers becomes a matter of subscribing to `subscribeRealtime` and feeding the stream into a `StreamBuilder`. The comprehensive documentation includes code snippets, model diagrams, and a quick‑start guide, making it easy to get a functional prototype up and running within an hour.
Overall, Spider SDK abstracts the complexities of a modern transit API while staying lightweight and idiomatic to Dart. Whether you are prototyping a campus shuttle tracker or building a nationwide multimodal journey planner, the SDK provides the building blocks you need to deliver accurate, real‑time transit experiences to your users.
Pros
- type‑safe Dart models
- built‑in pagination and error handling
- supports streaming realtime data
- cross‑platform compatibility
- minimal boilerplate
Watch outs
- relies on external Spider API availability
- no built‑in caching layer
- requires API key management
Setup notes
Add the dependency with the command: ``` flutter pub add spider_sdk ``` Then import the package and create a client instance: ```dart import 'package:spider_sdk/spider_sdk.dart'; final spider = SpiderClient(apiKey: 'YOUR_API_KEY'); ```
Requires Dart SDK >=2.19 and Flutter >=3.0. Works on Android, iOS, web, macOS, Linux, and Windows. Network permissions must be declared for mobile platforms (e.g., `INTERNET` permission on Android).
```dart
import 'package:flutter/material.dart';
import 'package:spider_sdk/spider_sdk.dart';
class TripPlannerScreen extends StatefulWidget {
const TripPlannerScreen({Key? key}) : super(key: key);
@override
State<TripPlannerScreen> createState() => _TripPlannerScreenState();
}
class _TripPlannerScreenState extends State<TripPlannerScreen> {
final SpiderClient _client = SpiderClient(apiKey: 'YOUR_API_KEY');
final TextEditingController _fromCtrl = TextEditingController();
final TextEditingController _toCtrl = TextEditingController();
TripPlan? _plan;
String? _error;
Future<void> _planTrip() async {
try {
final result = await _client.planTrip(
from: _fromCtrl.text,
to: _toCtrl.text,
dateTime: DateTime.now(),
);
setState(() {
_plan = result;
_error = null;
});
} catch (e) {
setState(() {
_error = e.toString();
_plan = null;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Spider Trip Planner')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
TextField(controller: _fromCtrl, decoration: const InputDecoration(labelText: 'From')),
TextField(controller: _toCtrl, decoration: const InputDecoration(labelText: 'To')),
const SizedBox(height: 12),
ElevatedButton(onPressed: _planTrip, child: const Text('Plan')),
const SizedBox(height: 20),
if (_error != null) Text(_error!, style: const TextStyle(color: Colors.red)),
if (_plan != null) Expanded(
child: ListView.builder(
itemCount: _plan!.legs.length,
itemBuilder: (context, i) {
final leg = _plan!.legs[i];
return ListTile(
title: Text('${leg.mode} – ${leg.duration.inMinutes} min'),
subtitle: Text('From ${leg.from.name} to ${leg.to.name}'),
);
},
),
),
],
),
),
);
}
}
```