lszpushsdk 1.0.0 icon indicating copy to clipboard operation
lszpushsdk: ^1.0.0 copied to clipboard

A new flutter plugin project.

example/lib/main.dart

import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:lszpushsdk/lszpushsdk.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _registerId = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
    if (Platform.isIOS) {
      Lszpushsdk.setCustomNotification();
    }
    Lszpushsdk.addPushReceiver(_onEvent, _onError);
  }

  void _onEvent(Object event) {
    print('>>>>>>>>>>>>>>>>>>>>>>>>>>>onEvent:' + event.toString());
    setState(() {
      Map<String, dynamic> eventMap = json.decode(event);
      String result = eventMap['result'];
      int action = eventMap['action'];
      print('>>>>>>>>>>action: ' + action.toString());
      print('>>>>>>>>>>result:' + result);
    });
  }
  
  void _onError(Object event) {
    setState(() {
      print('>>>>>>>>>>>>>>>>>>>>>>>>>>>onError:' + event.toString());
    });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    String registerId;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Lszpushsdk.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    try {
      registerId = await Lszpushsdk.getRegistrationId();
    } catch (e) {
      print('>>>>>>registerId Error: ' + e.toString());
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
      _registerId = registerId;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\nregisterId: $_registerId'),
        ),
      ),
    );
  }
}
0
likes
80
pub points
0%
popularity

Publisher

unverified uploader

A new flutter plugin project.

Homepage

Documentation

API reference

License

Icon for licenses.unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on lszpushsdk