Client SDK for echidna_server. Use this library to verify licenses and features unlocked by them.
To get started add the following dependency to your pubspec.yaml file:
dependencies:
echidna_flutter:
git:
url: https://github.com/necodeIT/echidna_flutter.gitCall the initializeEchidnaApi method in your main method before running the app.
import 'package:echidna_flutter/echidna_flutter.dart';
void main() {
initializeEchidnaApi(baseUrl: 'https://echidna.your.domain', clientKey: 'your-client-key'; clientId: your-client-id);
runApp(MyApp());
}<domain>: The domain of the Echidna server.<client-key>: The client key to authorize the client on the Echidna server.<client-id>: The client id to identify the client on the Echidna server.
For the SDK to work you need to implement a UserIdRepository that provides the current user id.
import 'package:echidna_flutter/echidna_flutter.dart';
class MyUserIdRepository extends UserIdRepository {}You're most likely going to connect this to your preexisting user management system.
import 'package:echidna_flutter/echidna_flutter.dart';
class MyUserIdRepository extends UserIdRepository {
final UserRepository _user;
MyUserIdRepository(this._user) {
watchAsync(_user);
}
@override
FutureOr<void> build(Type trigger){
data(_user.id);
}
}You also need to initialize the LicenseRepository with the UserIdRepository you just implemented (most likely in your auth module).
import 'package:echidna_flutter/echidna_flutter.dart';
class MyAuthModule extends Module {
@override
List<Module> get imports => [
EchidnaModule(),
];
@override
void binds(Injector i) {
// add your other bindings here
i.initializeLicenseRepo(MyUserIdRepository.new); // this should be called last
}
}Finally, you now can use the SDK to verify licenses and features unlocked by them.
import 'package:echidna_flutter/echidna_flutter.dart';
class MyFeature extends Module {}
class AppModule extends Module {
@override
void routes(RouteManager r){
r.module('/my-feature', module: MyFeature(), guards: [FeatureGuard(myFeatureId)]);
}
}