Skip to content

Instantly share code, notes, and snippets.

@g123k
Created December 29, 2022 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g123k/e51443ffe1e7f3e1145b2bcfafb67e73 to your computer and use it in GitHub Desktop.
Save g123k/e51443ffe1e7f3e1145b2bcfafb67e73 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:unifiedpush/unifiedpush.dart';
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Page d\'accueil'),
),
body: Center(
child: Column(
children: [
ElevatedButton(
child: const Text('S\'enregistrer'),
onPressed: () {
UnifiedPush.registerAppWithDialog(
context,
);
},
),
ElevatedButton(
child: const Text('Se désinscrire'),
onPressed: () {
UnifiedPush.unregister();
},
),
],
),
),
);
}
}
import 'package:devcafe_stable/screens/homepage.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:unifiedpush/unifiedpush.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
UnifiedPush.initialize(
onNewEndpoint: onNewEndpoint,
onRegistrationFailed: onRegistrationFailed,
onUnregistered: onUnregistered,
onMessage: onMessage,
);
runApp(
const MyApp(
color: Colors.blue,
),
);
}
class MyApp extends StatelessWidget {
final MaterialColor color;
const MyApp({
required this.color,
super.key,
});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: color,
),
home: const MyHomePage(),
);
}
}
void onNewEndpoint(String endpoint, String instance) {
print('onNewEndpoint: $endpoint, $instance');
}
void onRegistrationFailed(String instance) {
print('onRegistrationFailed: $instance');
}
void onUnregistered(String instance) {
print('onUnregistered: $instance');
}
void onMessage(Uint8List message, String instance) {
print('onMessage: ${String.fromCharCodes(message)}, $instance');
}
dependencies:
flutter:
sdk: flutter
unifiedpush: ^4.0.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment