locality_social_cloud 2.3.0
locality_social_cloud: ^2.3.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/cache.dart';
import 'package:locality_social_cloud/cache/repository/message_repository.dart';
import 'package:locality_social_cloud/locality_social_cloud_interface.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,
persistence: Cache(await MessageRepository.getInstance()));
await LocalitySocialCloud.supervise(pubSub: exampleState);
exampleState.click();
exampleState.click();
exampleState.click();
LocalitySocialCloudInterface.getFriendListOfUser(
localitySocialCloud.getLoggedInUser().publicUser);
}