Created
December 29, 2022 20:04
-
-
Save g123k/e51443ffe1e7f3e1145b2bcfafb67e73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}, | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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