main.dart 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. FlutterAliyunPush.bindAccount("test11111", (success,result) => {
  38. setState(() {
  39. _platformVersion = success as String;
  40. })
  41. });
  42. });
  43. FlutterAliyunPush.reigistOnReceiveNotification((msg){
  44. platformVersion = json.encode(msg.toJson());
  45. setState(() {
  46. _platformVersion = platformVersion;
  47. });
  48. });
  49. FlutterAliyunPush.reigistOnReceiveMessage((msg){
  50. platformVersion = json.encode(msg.toJson());
  51. setState(() {
  52. _platformVersion = platformVersion;
  53. });
  54. });
  55. // If the widget was removed from the tree while the asynchronous platform
  56. // message was in flight, we want to discard the reply rather than calling
  57. // setState to update our non-existent appearance.
  58. if (!mounted) return;
  59. setState(() {
  60. _platformVersion = platformVersion;
  61. });
  62. }
  63. @override
  64. Widget build(BuildContext context) {
  65. return MaterialApp(
  66. home: Scaffold(
  67. appBar: AppBar(
  68. title: const Text('Plugin example app'),
  69. ),
  70. body: Center(
  71. child: Text('Running on: $_platformVersion\n'),
  72. ),
  73. ),
  74. );
  75. }
  76. }