Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ node_modules
**/.dart_tool/
example/build/
package/build/
package/proto/
package/lib/proto/
.flutter-plugins*
package/test/.env-test.json
/example/ios/_GoogleService-Info.plist
/build/
/example/lib/firebase_options.dart
/example/ios/Podfile.lock

# Lockfiles
pubspec.lock
example/pubspec.lock
package/pubspec.lock
2 changes: 0 additions & 2 deletions example/.env.example

This file was deleted.

29 changes: 29 additions & 0 deletions example/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "719280351201",
"project_id": "teste-dito-sdk",
"storage_bucket": "teste-dito-sdk.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:719280351201:android:9407ea403f310b34a854a0",
"android_client_info": {
"package_name": "com.example.flutter_sdk_test"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyCSJRyVepSWw3QopOI1kdsOQ-snsVMrPGY"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
199 changes: 177 additions & 22 deletions example/lib/app_form.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:dito_sdk/dito_sdk.dart';
import 'package:dito_sdk/event/event_entity.dart';
import 'package:dito_sdk/user/user_entity.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand All @@ -23,41 +21,174 @@ class AppFormState extends State<AppForm> {
String cpf = "33333333333";
String email = "teste.sdk-flutter@dito.com.br";

identify() async {
final user = UserEntity(
userID: "e400c65b1800bee5bf546c5b7bd37cd4f7452bb8",
identify() {
return dito.user.identify(
userID: "1575213826e164f73d28c4ed1b5fabaad4bd4a13",
cpf: cpf,
name: 'Teste SDK Flutter 33333333333',
name: 'Usuário SDK FLutter - Teste',
email: email);
}

await dito.user.identify(user);
await dito.notification
.registryToken(await dito.notification.getFirebaseToken());
login() {
return dito.user
.login(userID: '1575213826e164f73d28c4ed1b5fabaad4bd4a13');
}

handleIdentify() async {
if (_formKey.currentState!.validate()) {
await identify().then((response) => {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Usuário identificado')),
)
});
final bool response = await identify();

if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Usuário identificado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}
}

handleLogin() async {
if (_formKey.currentState!.validate()) {
final bool response = await login();

if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Usuário logado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}
}

handleNotification() async {
handleGenericTrack() async {
if (_formKey.currentState!.validate()) {
await dito.event.trackEvent(EventEntity(eventName: 'action-test'));
final bool response = await dito.event.track(action: 'action-test');

if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Evento de notificação solicitado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}
}

handleNavigation() async {
if (_formKey.currentState!.validate()) {
final bool response = await dito.event.navigate(name: 'home');

if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Evento de notificação solicitado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}
}

handleClickNotification() async {
if (_formKey.currentState!.validate()) {
final bool response = await dito.notification.click(
notification: 'notification-sdk-test',
);

if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Evento de notificação solicitado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}
}

handleReceivedNotification() async {
if (_formKey.currentState!.validate()) {
final bool response = await dito.notification.received(
notification: 'notification-sdk-test',
);

if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Evento de notificação solicitado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}
}

handleDeleteToken() async {
final bool response = await dito.user.token.removeToken(dito.user.data.token);
if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Evento de notificação solicitado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}

handleDeleteToken() async {
await dito.notification
.removeToken(await dito.notification.getFirebaseToken());
handleRegistryToken() async {
final bool response = await dito.user.token.registryToken(dito.user.data.token);
if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Evento de notificação solicitado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}

handlePingToken() async {
final bool response = await dito.user.token.pingToken(dito.user.data.token);
if (response) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Evento de notificação solicitado')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Ocorreu um erro!'),
backgroundColor: Colors.redAccent),
);
}
}

return Form(
Expand Down Expand Up @@ -95,16 +226,40 @@ class AppFormState extends State<AppForm> {
child: Column(children: [
FilledButton(
onPressed: handleIdentify,
child: const Text('Registrar Identify'),
child: const Text('Alterar cadastro'),
),
FilledButton(
onPressed: handleLogin,
child: const Text('Logar usuário'),
),
OutlinedButton(
onPressed: handleGenericTrack,
child: const Text('Registrar evento genérico'),
),
OutlinedButton(
onPressed: handleNavigation,
child: const Text('Registrar evento de navegação'),
),
OutlinedButton(
onPressed: handleNotification,
child: const Text('Receber Notification'),
onPressed: handleClickNotification,
child: const Text('Registrar evento de click'),
),
OutlinedButton(
onPressed: handleReceivedNotification,
child: const Text('Registrar evento de Entrega'),
),
FilledButton(
onPressed: handleRegistryToken,
child: const Text('Registrar token'),
),
FilledButton(
onPressed: handleDeleteToken,
child: const Text('Deletar token'),
),
FilledButton(
onPressed: handlePingToken,
child: const Text('Validar token'),
),
])))
],
),
Expand Down
41 changes: 0 additions & 41 deletions example/lib/constants.dart

This file was deleted.

19 changes: 13 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'app.dart';
import 'constants.dart';

const apiKey = String.fromEnvironment(
'API_KEY',
defaultValue: '',
);

const secretKey = String.fromEnvironment(
'SECRET_KEY',
defaultValue: '',
);

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
DitoSDK dito = DitoSDK();
dito.initialize(
apiKey: Constants.ditoApiKey, secretKey: Constants.ditoSecretKey);
dito.initialize(apiKey: apiKey, secretKey: secretKey);
dito.onBackgroundPushNotificationHandler(message: message);
}

Expand All @@ -22,15 +30,14 @@ void main() async {
await Firebase.initializeApp();

DitoSDK dito = DitoSDK();
dito.initialize(
apiKey: Constants.ditoApiKey, secretKey: Constants.ditoSecretKey);
dito.initialize(apiKey: apiKey, secretKey: secretKey);
await dito.initializePushNotificationService();

FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

dito.notification.onMessageClick = (data) {
if (kDebugMode) {
print(data.toJson());
print(data);
}
};

Expand Down
Loading