main.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'dart:convert';
  2. import 'dart:core' ;
  3. import 'package:flutter/material.dart';
  4. import 'dart:async';
  5. import 'package:flutter/services.dart';
  6. import 'package:flutter_aliyun_push/flutter_aliyun_push.dart';
  7. void main() {
  8. runApp(MyApp());
  9. }
  10. class MyApp extends StatefulWidget {
  11. @override
  12. _MyAppState createState() => _MyAppState();
  13. }
  14. class _MyAppState extends State<MyApp> {
  15. String _platformVersion = 'Unknown';
  16. @override
  17. void initState() {
  18. super.initState();
  19. print("0000000000000000000000000000000");
  20. initPlatformState();
  21. }
  22. // Platform messages are asynchronous, so we initialize in an async method.
  23. Future<void> initPlatformState() async {
  24. String platformVersion;
  25. // Platform messages may fail, so we use a try/catch PlatformException.
  26. try {
  27. // platformVersion = await FlutterAliyunPush.platformVersion;
  28. // await FlutterAliyunPush.initPush;
  29. } on PlatformException {
  30. platformVersion = 'Failed to get platform version.';
  31. }
  32. FlutterAliyunPush.reigistOnRegistSuccess((msg){
  33. platformVersion = 'reigistOnRegistSuccess';
  34. setState(() {
  35. _platformVersion = platformVersion;
  36. });
  37. });
  38. FlutterAliyunPush.reigistOnReceiveNotification((msg){
  39. platformVersion = json.encode(msg.toJson());
  40. setState(() {
  41. _platformVersion = platformVersion;
  42. });
  43. });
  44. FlutterAliyunPush.reigistOnReceiveMessage((msg){
  45. platformVersion = json.encode(msg.toJson());
  46. setState(() {
  47. _platformVersion = platformVersion;
  48. });
  49. });
  50. // If the widget was removed from the tree while the asynchronous platform
  51. // message was in flight, we want to discard the reply rather than calling
  52. // setState to update our non-existent appearance.
  53. if (!mounted) return;
  54. setState(() {
  55. _platformVersion = platformVersion;
  56. });
  57. }
  58. @override
  59. Widget build(BuildContext context) {
  60. return MaterialApp(
  61. home: Scaffold(
  62. appBar: AppBar(
  63. title: const Text('Plugin example app'),
  64. ),
  65. body: Center(
  66. child: Text('Running on: $_platformVersion\n'),
  67. ),
  68. ),
  69. );
  70. }
  71. }