@pluskode/client-flutter
v0.1.2
Published
Pluskode Client SDK for Flutter - Dart client with HTTP, WebSocket, SSE, gRPC, MQTT, and Binary Stream support
Maintainers
Readme
Pluskode Flutter Client SDK
Dart/Flutter client SDK for Pluskode Backend Framework.
Status
✅ Core Implementation Complete - HTTP and WebSocket ready
Features
- ✅ HTTP client (http package)
- ✅ WebSocket client (web_socket_channel)
- 🚧 SSE client - Basic structure
- ✅ gRPC client (HTTP-based)
- ✅ MQTT client (WebSocket-based)
- ✅ Binary stream support
- ✅ Authentication (Bearer, Basic)
- ✅ Retry logic
Installation
Add to your pubspec.yaml:
dependencies:
pluskode_client:
git:
url: https://github.com/pluskode/client-flutter.git
ref: mainOr from pub.dev (when published):
dependencies:
pluskode_client: ^0.1.0Then run:
flutter pub getUsage
Basic Setup
import 'package:pluskode_client/pluskode_client.dart';
final client = PluskodeClient(
PluskodeClientOptions(
baseURL: 'http://localhost:3000',
timeout: Duration(seconds: 30),
retries: 3,
),
);
// Set authentication
client.setAuth('Bearer', 'your-jwt-token');HTTP Requests
// GET request
final users = await client.get<List<Map<String, dynamic>>>('/api/users');
// POST request
final newUser = await client.post<Map<String, dynamic>>(
'/api/users',
{
'name': 'John',
'email': '[email protected]',
},
);
// PUT, PATCH, DELETE
await client.put('/api/users/123', {'name': 'Jane'});
await client.patch('/api/users/123', {'email': '[email protected]'});
await client.delete('/api/users/123');WebSocket
// Subscribe to channel
final unsubscribe = client.subscribe('chat/room1', (data) {
print('Message: $data');
});
// Send message
client.send('chat/room1', {'text': 'Hello!'});
// Unsubscribe
unsubscribe();gRPC
final user = await client.rpc<Map<String, dynamic>>(
'UserService',
'GetUser',
{'id': '123'},
);MQTT
// Subscribe
final unsubscribe = client.subscribeMQTT(
'sensors/temperature',
(topic, message, qos) {
print('$topic: $message (QoS: $qos)');
},
options: MQTTOptions(qos: 1),
);
// Publish
await client.publishMQTT(
'sensors/temperature',
'25.5',
options: MQTTOptions(qos: 1),
);Flutter Widget Example
import 'package:flutter/material.dart';
import 'package:pluskode_client/pluskode_client.dart';
class UsersPage extends StatefulWidget {
@override
_UsersPageState createState() => _UsersPageState();
}
class _UsersPageState extends State<UsersPage> {
final client = PluskodeClient(
PluskodeClientOptions(baseURL: 'http://localhost:3000'),
);
List<Map<String, dynamic>> users = [];
bool isLoading = true;
@override
void initState() {
super.initState();
_loadUsers();
}
Future<void> _loadUsers() async {
try {
final response = await client.get<List<Map<String, dynamic>>>('/api/users');
setState(() {
users = response.data;
isLoading = false;
});
} catch (e) {
print('Error: $e');
setState(() => isLoading = false);
}
}
@override
Widget build(BuildContext context) {
if (isLoading) {
return CircularProgressIndicator();
}
return ListView.builder(
itemCount: users.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(users[index]['name'] ?? ''),
);
},
);
}
@override
void dispose() {
client.destroy();
super.dispose();
}
}Dependencies
http: ^1.1.0- HTTP clientweb_socket_channel: ^2.4.0- WebSocket support
Requirements
- Dart 2.17.0+
- Flutter 3.0.0+
License
MIT
Note: This is a working implementation with core features. Native Android/iOS SDKs can be integrated via platform channels for better performance.
