Last updated:
0 purchases
edmax realtime mongo lite
Edmax Realtime Mongo Lite | WARNING [UNSTABLE VERSION] #
A lightweight Dart package designed to facilitate real-time data synchronization.
What Does the Package Do? #
Connects to a WebSocket server to receive real-time updates.
Listens for changes in the database and triggers corresponding actions in the application.
Parses incoming JSON messages into structured Dart objects (DataSnapshot).
Provides a simple API for developers to interact with real-time data, ensuring smooth and efficient updates in their Flutter or Dart applications.
Key Features #
Singleton Pattern: Ensures only one instance of the WebSocket connection is active.
Listener Management: Allows developers to register listeners to handle different events (e.g., data changes, disconnections, errors).
JSON Parsing: Automatically parses JSON data into structured Dart objects for easier manipulation and use within the application.
Error Handling: Includes built-in error handling to manage connection issues and unexpected data formats.
Websocket Channel Subsription Support: Optionally support websockets that need clients to subscribe to a specific channel.
Why Should Developers Use It? #
Ease of Use: Provides a straightforward API for setting up real-time data synchronization with minimal boilerplate code.
Real-time Data: Perfect for applications that require instant updates from the server, such as chat apps, live feeds, or collaborative tools.
Customizable: The package is designed to be flexible, allowing developers to customize their listeners and handle different types of data operations.
Example Usage #
//[Your App Entry Point main.dart]
//set your websocket url
void main() {
EdmaxRealtimeMongo(wsUrl: "ws://localhost:8080/");
runApp(const MAIN());
}
//[Your Class]
import 'package:edmax_realtime_mongo_lite/edmax_realtime_mongo_lite.dart';
import 'package:edmax_realtime_mongo_lite/tools/snapshot.dart';
import 'package:flutter/material.dart';
class HelloWorld extends StatefulWidget {
const HelloWorld({super.key});
@override
State<HelloWorld> createState() => _HelloWorldState();
}
class _HelloWorldState extends State<HelloWorld> with EdmaxRealtimeMongoListener {
@override
void initState() {
super.initState();
//Additionally pass url and snapshot
//[EdmaxRealtimeMongo.initialize(listener: this,endpoint: "http://xxxxx/load_users",snapshot: "users");]
//or pass them as empty strings if not needed if needed more info check ChangeLog 0.0.3
EdmaxRealtimeMongo.initialize(listener: this,endpoint: "",snapshot: "");
}
@override
void dispose() {
super.dispose();
//ALWAYS null and empty for both endpoint and snapshot
EdmaxRealtimeMongo.initialize(listener: null,endpoint: "",snapshot: "");
}
@override
Widget build(BuildContext context) {
return const Placeholder();
}
@override
void onDataChange(DataSnapshot dataSnapshot) {
print('Data changed: ${dataSnapshot.snapshot}');
}
@override
void onDataRemoved() {
print('Data removed Reload');
}
@override
void onDisconnected() {
print('Disconnected from the server');
}
@override
void onError(String error) {
print('Error: $error');
}
}
copied to clipboard
JSON Structure Requirements #
For this package to work correctly, your server must return JSON in the following structure:
{
"snapshot": "contents",
"operation": "update",
"data": {
"_id": "66b8b265d47bdeb08e7a8581",
"leading": "<img src=\"https://example.com/image.jpg\"/>",
"content": "Your content here",
"createdAt": "2024-08-10T14:30:00Z", // ISO 8601 date-time string
"updatedAt": "2024-08-11T09:15:00Z", // ISO 8601 date-time string
"tag": "_community"
}
}
copied to clipboard
JSON Keys #
snapshot: A string that identifies the type of data snapshot.
operation: A string that describes the operation performed (e.g., update, delete).
data: A map containing the actual data. It should include the following keys:
_id: A string representing the unique identifier of the data.
leading: A string that may contain HTML or other leading content.
content: A string containing the main content.
createdAt: A string representing the creation date and time in ISO 8601 format (e.g., "2024-08-10T14:30:00Z").
updatedAt: A string representing the last updated date and time in ISO 8601 format (e.g., "2024-08-11T09:15:00Z").
tag: A string that tags or categorizes the data.
Support #
If you encounter any issues or have suggestions for improvement, feel free to contact the package author at [email protected].
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.