locality_social_cloud 1.9.0
locality_social_cloud: ^1.9.0 copied to clipboard
Write social apps with Flutter. This code connects to the backend of Locality Social Cloud to provide realtime state synchronization across devices.
example/locality_social_cloud_example.dart
import 'package:locality_core/locality_core.dart';
import 'package:locality_social_cloud/shared_space.dart';
class ClickCounter extends SharedSpace {
int count = 0;
@override
String getTopic() {
return "example";
}
@override
void onReceive(Broadcast localityEvent) {
switch ( localityEvent.event ) {
case 'click':
count++;
break;
}
notifyListeners();
}
void click() {
send("click", {});
}
}
Future<void> main() async {
ClickCounter exampleState = ClickCounter();
LocalitySocialCloud localitySocialCloud = await LocalitySocialCloud.startTest(
userCredentials: UserCredentials("userId", "password"),
developerCredentials: DeveloperCredentials(realmId: "realmId", realmSecret: "realmSecret"),
isRegistration: true,
);
await LocalitySocialCloud.supervise(pubSub: exampleState);
exampleState.click();
exampleState.click();
exampleState.click();
}