update to 0.0.5

master
huangminlinux 6 years ago
parent 4e0cf44414
commit d0a80076a6

@ -1,8 +1,56 @@
# Generated by pub on 2018-09-29 10:15:14.625856. # Generated by pub on 2018-10-08 23:40:55.475551.
analyzer:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.33.0/lib/
args:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.5.0/lib/
async:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib/
boolean_selector:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.4/lib/
charcode:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.2/lib/
collection:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.14.11/lib/ collection:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.14.11/lib/
convert:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/convert-2.0.2/lib/
crypto:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.0.6/lib/
csslib:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/csslib-0.14.6/lib/
flutter:file:///Applications/flutter/packages/flutter/lib/ flutter:file:///Applications/flutter/packages/flutter/lib/
front_end:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.6/lib/
glob:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/glob-1.1.7/lib/
html:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/html-0.13.3+3/lib/
http:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0/lib/
http_multi_server:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.5/lib/
http_parser:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.3/lib/
io:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/io-0.3.3/lib/
js:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.1+1/lib/
json_rpc_2:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/json_rpc_2-2.0.9/lib/
kernel:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.6/lib/
logging:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/logging-0.11.3+2/lib/
matcher:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.3+1/lib/
meta:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.6/lib/ meta:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.6/lib/
mime:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/mime-0.9.6+2/lib/
mockito:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/mockito-3.0.0/lib/
multi_server_socket:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/multi_server_socket-1.0.2/lib/
node_preamble:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/node_preamble-1.4.4/lib/
package_config:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/package_config-1.0.5/lib/
package_resolver:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.6/lib/
path:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.6.2/lib/
platform:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/platform-2.2.0/lib/
plugin:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/plugin-0.2.0+3/lib/
pool:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/pool-1.3.6/lib/
pub_semver:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/pub_semver-1.4.2/lib/
shelf:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.3+3/lib/
shelf_packages_handler:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/shelf_packages_handler-1.0.4/lib/
shelf_static:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/shelf_static-0.2.8/lib/
shelf_web_socket:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.2+4/lib/
sky_engine:file:///Applications/flutter/bin/cache/pkg/sky_engine/lib/ sky_engine:file:///Applications/flutter/bin/cache/pkg/sky_engine/lib/
source_map_stack_trace:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/source_map_stack_trace-1.1.5/lib/
source_maps:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/source_maps-0.10.8/lib/
source_span:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.4.1/lib/
stack_trace:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib/
stream_channel:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.8/lib/
string_scanner:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.4/lib/
term_glyph:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.0.1/lib/
test:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/test-1.3.4/lib/
typed_data:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6/lib/ typed_data:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6/lib/
utf:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/utf-0.9.0+5/lib/
vector_math:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/ vector_math:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/
vm_service_client:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/vm_service_client-0.2.6/lib/
watcher:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+10/lib/
web_socket_channel:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.0.9/lib/
yaml:file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/yaml-2.1.15/lib/
jpush_flutter:lib/ jpush_flutter:lib/

@ -7,7 +7,7 @@
```yaml ```yaml
dependencies: dependencies:
jpush_flutter: 0.0.3 jpush_flutter: 0.0.5
``` ```
### 配置 ### 配置

@ -28,7 +28,8 @@
添加事件监听方法。 添加事件监听方法。
```dart ```dart
JPush.addEventHandler( JPush jpush = new JPush();
jpush.addEventHandler(
// 接收通知回调方法。 // 接收通知回调方法。
onReceiveNotification: (Map<String, dynamic> message) async { onReceiveNotification: (Map<String, dynamic> message) async {
print("flutter onReceiveNotification: $message"); print("flutter onReceiveNotification: $message");
@ -52,7 +53,8 @@ JPush.addEventHandler(
- 将缓存的事件下发到 dart 环境中。 - 将缓存的事件下发到 dart 环境中。
```dart ```dart
JPush.setup( JPush jpush = new JPush();
jpush.setup(
appKey: "替换成你自己的 appKey", appKey: "替换成你自己的 appKey",
channel: "theChannel", channel: "theChannel",
production: false production: false
@ -64,7 +66,8 @@ JPush.setup(
获取 registrationId这个 JPush 运行通过 registrationId 来进行推送. 获取 registrationId这个 JPush 运行通过 registrationId 来进行推送.
```dart ```dart
JPush.getRegistrationID().then((rid) { }); JPush jpush = new JPush();
jpush.getRegistrationID().then((rid) { });
``` ```
#### stopPush #### stopPush
@ -72,7 +75,8 @@ JPush.getRegistrationID().then((rid) { });
停止推送功能,调用该方法将不会接收到通知。 停止推送功能,调用该方法将不会接收到通知。
```dart ```dart
JPush.stopPush(); JPush jpush = new JPush();
jpush.stopPush();
``` ```
#### resumePush #### resumePush
@ -80,7 +84,8 @@ JPush.stopPush();
调用 stopPush 后,可以通过 resumePush 方法恢复推送。 调用 stopPush 后,可以通过 resumePush 方法恢复推送。
```dart ```dart
JPush.resumePush(); JPush jpush = new JPush();
jpush.resumePush();
``` ```
#### setAlias #### setAlias
@ -88,7 +93,8 @@ JPush.resumePush();
设置别名,极光后台可以通过别名来推送,一个 App 应用只有一个别名,一般用来存储用户 id。 设置别名,极光后台可以通过别名来推送,一个 App 应用只有一个别名,一般用来存储用户 id。
``` ```
JPush.setAlias("your alias").then((map) { }); JPush jpush = new JPush();
jpush.setAlias("your alias").then((map) { });
``` ```
#### deleteAlias #### deleteAlias
@ -96,7 +102,8 @@ JPush.setAlias("your alias").then((map) { });
可以通过 deleteAlias 方法来删除已经设置的 alias。 可以通过 deleteAlias 方法来删除已经设置的 alias。
```dart ```dart
JPush.deleteAlias().then((map) {}) JPush jpush = new JPush();
jpush.deleteAlias().then((map) {})
``` ```
#### addTags #### addTags
@ -104,7 +111,8 @@ JPush.deleteAlias().then((map) {})
在原来的 Tags 列表上添加指定 tags。 在原来的 Tags 列表上添加指定 tags。
``` ```
JPush.addTags(["tag1","tag2"]).then((map) {}); JPush jpush = new JPush();
jpush.addTags(["tag1","tag2"]).then((map) {});
``` ```
#### deleteTags #### deleteTags
@ -112,15 +120,17 @@ JPush.addTags(["tag1","tag2"]).then((map) {});
在原来的 Tags 列表上删除指定 tags。 在原来的 Tags 列表上删除指定 tags。
``` ```
JPush.deleteTags(["tag1","tag2"]).then((map) {}); JPush jpush = new JPush();
jpush.deleteTags(["tag1","tag2"]).then((map) {});
``` ```
#### setTags #### setTags
重置 tags。 重置 tags。
``` ```dart
JPush.setTags(["tag1","tag2"]).then((map) {}); JPush jpush = new JPush();
jpush.setTags(["tag1","tag2"]).then((map) {});
``` ```
#### cleanTags #### cleanTags
@ -128,15 +138,16 @@ JPush.setTags(["tag1","tag2"]).then((map) {});
清空所有 tags 清空所有 tags
```dart ```dart
JPush.setTags().then((map) {}); jpush.setTags().then((map) {});
``` ```
#### getAllTags #### getAllTags
获取当前 tags 列表。 获取当前 tags 列表。
``` ```dart
JPush.getAllTags().then((map) {}); JPush jpush = new JPush();
jpush.getAllTags().then((map) {});
``` ```
#### sendLocalNotification #### sendLocalNotification
@ -145,6 +156,7 @@ JPush.getAllTags().then((map) {});
```dart ```dart
// 延时 3 秒后触发本地通知。 // 延时 3 秒后触发本地通知。
JPush jpush = new JPush();
var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000); var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000);
var localNotification = LocalNotification( var localNotification = LocalNotification(
id: 234, id: 234,
@ -156,7 +168,7 @@ var localNotification = LocalNotification(
badge: 5, // 该参数只有在 iOS 有效 badge: 5, // 该参数只有在 iOS 有效
extras: {"fa": "0"} // 设置 extras extras 需要是 Map<String, String> extras: {"fa": "0"} // 设置 extras extras 需要是 Map<String, String>
); );
JPush.sendLocalNotification(localNotification).then((res) {}); jpush.sendLocalNotification(localNotification).then((res) {});
``` ```
#### clearAllNotifications #### clearAllNotifications
@ -164,7 +176,8 @@ JPush.sendLocalNotification(localNotification).then((res) {});
清楚通知栏上所有通知。 清楚通知栏上所有通知。
```dart ```dart
JPush.clearAllNotifications(); JPush jpush = new JPush();
jpush.clearAllNotifications();
``` ```
#### applyPushAuthority #### applyPushAuthority
@ -174,7 +187,8 @@ JPush.clearAllNotifications();
**注意: iOS10+ 可以通过该方法来设置推送是否前台展示,是否触发声音,是否设置应用角标 badge** **注意: iOS10+ 可以通过该方法来设置推送是否前台展示,是否触发声音,是否设置应用角标 badge**
```dart ```dart
JPush.applyPushAuthority(new NotificationSettingsIOS( JPush jpush = new JPush();
jpush.applyPushAuthority(new NotificationSettingsIOS(
sound: true, sound: true,
alert: true, alert: true,
badge: true)); badge: true));
@ -187,7 +201,8 @@ JPush.applyPushAuthority(new NotificationSettingsIOS(
设置应用 badge 值,该方法还会同步 JPush 服务器的的 badge 值JPush 服务器的 badge 值用于推送 badge 自动 +1 时会用到。 设置应用 badge 值,该方法还会同步 JPush 服务器的的 badge 值JPush 服务器的 badge 值用于推送 badge 自动 +1 时会用到。
```dart ```dart
JPush.setBadge(66).then((map) {}); JPush jpush = new JPush();
jpush.setBadge(66).then((map) {});
``` ```
### getLaunchAppNotification ### getLaunchAppNotification
@ -195,6 +210,7 @@ JPush.setBadge(66).then((map) {});
获取 iOS 点击推送启动应用的那条通知。 获取 iOS 点击推送启动应用的那条通知。
```dart ```dart
JPush.getLaunchAppNotification().then((map) {}); JPush jpush = new JPush();
jpush.getLaunchAppNotification().then((map) {});
``` ```

@ -13,7 +13,7 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
String debugLable = 'Unknown'; String debugLable = 'Unknown';
final JPush jpush = new JPush();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -23,26 +23,28 @@ class _MyAppState extends State<MyApp> {
// Platform messages are asynchronous, so we initialize in an async method. // Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async { Future<void> initPlatformState() async {
String platformVersion; String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException. // Platform messages may fail, so we use a try/catch PlatformException.
JPush.getRegistrationID().then((rid) { jpush.getRegistrationID().then((rid) {
setState(() { setState(() {
debugLable = "flutter getRegistrationID: $rid"; debugLable = "flutter getRegistrationID: $rid";
}); });
}); });
JPush.setup( jpush.setup(
appKey: "a1703c14b186a68a66ef86c1", appKey: "a1703c14b186a68a66ef86c1",
channel: "theChannel", channel: "theChannel",
production: false production: false
); );
JPush.applyPushAuthority(new NotificationSettingsIOS( jpush.applyPushAuthority(new NotificationSettingsIOS(
sound: false, sound: false,
alert: false, alert: false,
badge: false)); badge: false));
try { try {
JPush.addEventHandler( jpush.addEventHandler(
onReceiveNotification: (Map<String, dynamic> message) async { onReceiveNotification: (Map<String, dynamic> message) async {
// print("flutter onReceiveNotification: $message"); // print("flutter onReceiveNotification: $message");
// setState(() { // setState(() {
@ -102,9 +104,9 @@ class _MyAppState extends State<MyApp> {
fireTime: fireDate, fireTime: fireDate,
subtitle: 'fasf', subtitle: 'fasf',
badge: 5, badge: 5,
extras: {"fa": 0} extras: {"fa": "0"}
); );
JPush.sendLocalNotification(localNotification).then((res) { jpush.sendLocalNotification(localNotification).then((res) {
setState(() { setState(() {
debugLable = res; debugLable = res;
}); });
@ -115,12 +117,12 @@ class _MyAppState extends State<MyApp> {
new FlatButton( new FlatButton(
child: new Text('applyPushAuthority\n'), child: new Text('applyPushAuthority\n'),
onPressed: () { onPressed: () {
JPush.applyPushAuthority(NotificationSettingsIOS(badge: true, alert: true, sound: true)); jpush.applyPushAuthority(NotificationSettingsIOS(badge: true, alert: true, sound: true));
}), }),
new FlatButton( new FlatButton(
child: new Text('setTags\n'), child: new Text('setTags\n'),
onPressed: () { onPressed: () {
JPush.setTags(["lala","haha"]).then((map) { jpush.setTags(["lala","haha"]).then((map) {
var tags = map['tags']; var tags = map['tags'];
setState(() { setState(() {
debugLable = "set tags success: $map $tags"; debugLable = "set tags success: $map $tags";
@ -135,7 +137,7 @@ class _MyAppState extends State<MyApp> {
new FlatButton( new FlatButton(
child: new Text('cleanTags\n'), child: new Text('cleanTags\n'),
onPressed: () { onPressed: () {
JPush.cleanTags().then((map) { jpush.cleanTags().then((map) {
var tags = map['tags']; var tags = map['tags'];
setState(() { setState(() {
debugLable = "cleanTags success: $map $tags"; debugLable = "cleanTags success: $map $tags";
@ -151,7 +153,7 @@ class _MyAppState extends State<MyApp> {
child: new Text('addTags\n'), child: new Text('addTags\n'),
onPressed: () { onPressed: () {
JPush.addTags(["lala","haha"]).then((map) { jpush.addTags(["lala","haha"]).then((map) {
var tags = map['tags']; var tags = map['tags'];
setState(() { setState(() {
debugLable = "addTags success: $map $tags"; debugLable = "addTags success: $map $tags";
@ -168,7 +170,7 @@ class _MyAppState extends State<MyApp> {
child: new Text('deleteTags\n'), child: new Text('deleteTags\n'),
onPressed: () { onPressed: () {
JPush.deleteTags(["lala","haha"]).then((map) { jpush.deleteTags(["lala","haha"]).then((map) {
var tags = map['tags']; var tags = map['tags'];
setState(() { setState(() {
debugLable = "deleteTags success: $map $tags"; debugLable = "deleteTags success: $map $tags";
@ -185,7 +187,7 @@ class _MyAppState extends State<MyApp> {
child: new Text('getAllTags\n'), child: new Text('getAllTags\n'),
onPressed: () { onPressed: () {
JPush.getAllTags().then((map) { jpush.getAllTags().then((map) {
setState(() { setState(() {
debugLable = "getAllTags success: $map"; debugLable = "getAllTags success: $map";
}); });
@ -201,7 +203,7 @@ class _MyAppState extends State<MyApp> {
child: new Text('setAlias\n'), child: new Text('setAlias\n'),
onPressed: () { onPressed: () {
JPush.setAlias("thealias11").then((map) { jpush.setAlias("thealias11").then((map) {
setState(() { setState(() {
debugLable = "setAlias success: $map"; debugLable = "setAlias success: $map";
}); });
@ -217,7 +219,7 @@ class _MyAppState extends State<MyApp> {
child: new Text('deleteAlias\n'), child: new Text('deleteAlias\n'),
onPressed: () { onPressed: () {
JPush.deleteAlias().then((map) { jpush.deleteAlias().then((map) {
setState(() { setState(() {
debugLable = "deleteAlias success: $map"; debugLable = "deleteAlias success: $map";
}); });
@ -233,7 +235,7 @@ class _MyAppState extends State<MyApp> {
child: new Text('setBadge\n'), child: new Text('setBadge\n'),
onPressed: () { onPressed: () {
JPush.setBadge(66).then((map) { jpush.setBadge(66).then((map) {
setState(() { setState(() {
debugLable = "setBadge success: $map"; debugLable = "setBadge success: $map";
}); });
@ -249,28 +251,28 @@ class _MyAppState extends State<MyApp> {
child: new Text('stopPush\n'), child: new Text('stopPush\n'),
onPressed: () { onPressed: () {
JPush.stopPush(); jpush.stopPush();
}), }),
new FlatButton( new FlatButton(
child: new Text('resumePush\n'), child: new Text('resumePush\n'),
onPressed: () { onPressed: () {
JPush.resumePush(); jpush.resumePush();
}), }),
new FlatButton( new FlatButton(
child: new Text('clearAllNotifications\n'), child: new Text('clearAllNotifications\n'),
onPressed: () { onPressed: () {
JPush.clearAllNotifications(); jpush.clearAllNotifications();
}), }),
new FlatButton( new FlatButton(
child: new Text('getLaunchAppNotification\n'), child: new Text('getLaunchAppNotification\n'),
onPressed: () { onPressed: () {
JPush.getLaunchAppNotification().then((map) { jpush.getLaunchAppNotification().then((map) {
setState(() { setState(() {
debugLable = "getLaunchAppNotification success: $map"; debugLable = "getLaunchAppNotification success: $map";
}); });

@ -136,7 +136,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "0.0.3" version: "0.0.5"
js: js:
dependency: transitive dependency: transitive
description: description:
@ -186,6 +186,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.6+2" version: "0.9.6+2"
mockito:
dependency: "direct dev"
description:
name: mockito
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
multi_server_socket: multi_server_socket:
dependency: transitive dependency: transitive
description: description:
@ -221,6 +228,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.6.2" version: "1.6.2"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
plugin: plugin:
dependency: transitive dependency: transitive
description: description:
@ -332,7 +346,7 @@ packages:
source: hosted source: hosted
version: "1.0.1" version: "1.0.1"
test: test:
dependency: transitive dependency: "direct dev"
description: description:
name: test name: test
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

@ -21,6 +21,8 @@ dependencies:
cupertino_icons: ^0.1.2 cupertino_icons: ^0.1.2
dev_dependencies: dev_dependencies:
test: ^1.3.0
mockito: ^3.0.0
flutter_test: flutter_test:
sdk: flutter sdk: flutter

@ -6,8 +6,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:jpush_example/main.dart'; import 'package:jpush_example/main.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:test/test.dart';
void main() { void main() {
testWidgets('Verify Platform version', (WidgetTester tester) async { testWidgets('Verify Platform version', (WidgetTester tester) async {
@ -15,11 +19,35 @@ void main() {
await tester.pumpWidget(new MyApp()); await tester.pumpWidget(new MyApp());
// Verify that platform version is retrieved. // Verify that platform version is retrieved.
expect(
find.byWidgetPredicate( // expect(
(Widget widget) => // find.byWidgetPredicate(
widget is Text && widget.data.startsWith('Running on:'), // (Widget widget) =>
), // widget is Text && widget.data.startsWith('Running on:'),
findsOneWidget); // ),
// findsOneWidget);
});
MockMethodChannel mockChannel;
JPush.setup(
appKey: "a1703c14b186a68a66ef86c1",
channel: "theChannel",
production: false
);
test('requestNotificationPermissions on ios with custom permissions', () {
JPush.applyPushAuthority(new NotificationSettingsIOS(
sound: false,
alert: false,
badge: false));
// firebaseMessaging.requestNotificationPermissions(
// const IosNotificationSettings(sound: false));
verify(mockChannel.invokeMethod('requestNotificationPermissions',
<String, bool>{'sound': false, 'badge': true, 'alert': true}));
}); });
} }

@ -1,25 +1,31 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'dart:io' show Platform; import 'package:platform/platform.dart';
typedef Future<dynamic> EventHandler(Map<String, dynamic> event); typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
class JPush { class JPush {
static const MethodChannel _channel = factory JPush() => _instance;
const MethodChannel('jpush');
static Future<String> get platformVersion async { final MethodChannel _channel;
final String version = await _channel.invokeMethod('getPlatformVersion'); final Platform _platform;
return version;
} @visibleForTesting
JPush.private(MethodChannel channel, Platform platform)
: _channel = channel,
_platform = platform;
static final JPush _instance = new JPush.private(
const MethodChannel('jpush'),
const LocalPlatform());
static EventHandler _onReceiveNotification; EventHandler _onReceiveNotification;
static EventHandler _onOpenNotification; EventHandler _onOpenNotification;
static EventHandler _onReceiveMessage; EventHandler _onReceiveMessage;
static void setup({ void setup({
String appKey, String appKey,
String channel, String channel,
bool production, bool production,
@ -29,7 +35,7 @@ class JPush {
/// ///
/// JPush () /// JPush ()
/// ///
static void addEventHandler({ void addEventHandler({
EventHandler onReceiveNotification, EventHandler onReceiveNotification,
EventHandler onOpenNotification, EventHandler onOpenNotification,
EventHandler onReceiveMessage, EventHandler onReceiveMessage,
@ -40,7 +46,7 @@ class JPush {
_channel.setMethodCallHandler(_handleMethod); _channel.setMethodCallHandler(_handleMethod);
} }
static Future<Null> _handleMethod(MethodCall call) async { Future<Null> _handleMethod(MethodCall call) async {
switch (call.method) { switch (call.method) {
case "onReceiveNotification": case "onReceiveNotification":
return _onReceiveNotification(call.arguments.cast<String, dynamic>()); return _onReceiveNotification(call.arguments.cast<String, dynamic>());
@ -56,9 +62,9 @@ class JPush {
/// ///
/// ///
/// ///
static void applyPushAuthority([NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) { void applyPushAuthority([NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) {
if (!Platform.isIOS) { if (!_platform.isIOS) {
return; return;
} }
@ -72,7 +78,7 @@ class JPush {
/// @param {Function} success = ({"tags":[String]}) => { } /// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { } /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
static Future<Map<dynamic, dynamic>> setTags(List<String> tags) async { Future<Map<dynamic, dynamic>> setTags(List<String> tags) async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setTags', tags); final Map<dynamic, dynamic> result = await _channel.invokeMethod('setTags', tags);
return result; return result;
} }
@ -83,7 +89,7 @@ class JPush {
/// @param {Function} success = ({"tags":[String]}) => { } /// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { } /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
static Future<Map<dynamic, dynamic>> cleanTags() async { Future<Map<dynamic, dynamic>> cleanTags() async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('cleanTags'); final Map<dynamic, dynamic> result = await _channel.invokeMethod('cleanTags');
return result; return result;
} }
@ -96,7 +102,7 @@ class JPush {
/// @param {Function} fail = ({"errorCode":int}) => { } /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
static Future<Map<dynamic, dynamic>> addTags(List<String> tags) async { Future<Map<dynamic, dynamic>> addTags(List<String> tags) async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('addTags', tags); final Map<dynamic, dynamic> result = await _channel.invokeMethod('addTags', tags);
return result; return result;
} }
@ -108,7 +114,7 @@ class JPush {
/// @param {Function} success = ({"tags":[String]}) => { } /// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { } /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
static Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async { Future<Map<dynamic, dynamic>> deleteTags(List<String> tags) async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteTags', tags); final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteTags', tags);
return result; return result;
} }
@ -119,7 +125,7 @@ class JPush {
/// @param {Function} success = ({"tags":[String]}) => { } /// @param {Function} success = ({"tags":[String]}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { } /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
static Future<Map<dynamic, dynamic>> getAllTags() async { Future<Map<dynamic, dynamic>> getAllTags() async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getAllTags'); final Map<dynamic, dynamic> result = await _channel.invokeMethod('getAllTags');
return result; return result;
} }
@ -132,7 +138,7 @@ class JPush {
/// @param {Function} success = ({"alias":String}) => { } /// @param {Function} success = ({"alias":String}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { } /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
static Future<Map<dynamic, dynamic>> setAlias(String alias) async { Future<Map<dynamic, dynamic>> setAlias(String alias) async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('setAlias', alias); final Map<dynamic, dynamic> result = await _channel.invokeMethod('setAlias', alias);
return result; return result;
} }
@ -143,7 +149,7 @@ class JPush {
/// @param {Function} success = ({"alias":String}) => { } /// @param {Function} success = ({"alias":String}) => { }
/// @param {Function} fail = ({"errorCode":int}) => { } /// @param {Function} fail = ({"errorCode":int}) => { }
/// ///
static Future<Map<dynamic, dynamic>> deleteAlias() async { Future<Map<dynamic, dynamic>> deleteAlias() async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteAlias'); final Map<dynamic, dynamic> result = await _channel.invokeMethod('deleteAlias');
return result; return result;
} }
@ -154,28 +160,28 @@ class JPush {
/// ///
/// @param {Int} badge /// @param {Int} badge
/// ///
static Future setBadge(int badge) async { Future setBadge(int badge) async {
await _channel.invokeMethod('setBadge', badge); await _channel.invokeMethod('setBadge', badge);
} }
/// ///
/// resumePush /// resumePush
/// ///
static Future stopPush() async { Future stopPush() async {
await _channel.invokeMethod('stopPush'); await _channel.invokeMethod('stopPush');
} }
/// ///
/// ///
/// ///
static Future resumePush() async { Future resumePush() async {
await _channel.invokeMethod('resumePush'); await _channel.invokeMethod('resumePush');
} }
/// ///
/// ///
/// ///
static Future clearAllNotifications() async { Future clearAllNotifications() async {
await _channel.invokeMethod('clearAllNotifications'); await _channel.invokeMethod('clearAllNotifications');
} }
@ -186,7 +192,7 @@ class JPush {
/// icon notification @{} /// icon notification @{}
/// @param {Function} callback = (Object) => {} /// @param {Function} callback = (Object) => {}
/// ///
static Future<Map<dynamic, dynamic>> getLaunchAppNotification() async { Future<Map<dynamic, dynamic>> getLaunchAppNotification() async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod('getLaunchAppNotification'); final Map<dynamic, dynamic> result = await _channel.invokeMethod('getLaunchAppNotification');
return result; return result;
} }
@ -196,7 +202,7 @@ class JPush {
/// ///
/// @param {Function} callback = (String) => {} /// @param {Function} callback = (String) => {}
/// ///
static Future<String> getRegistrationID() async { Future<String> getRegistrationID() async {
final String rid = await _channel.invokeMethod('getRegistrationID'); final String rid = await _channel.invokeMethod('getRegistrationID');
return rid; return rid;
} }
@ -205,7 +211,7 @@ class JPush {
/// ///
/// @param {Notification} notification /// @param {Notification} notification
/// ///
static Future<String> sendLocalNotification(LocalNotification notification) async { Future<String> sendLocalNotification(LocalNotification notification) async {
await _channel.invokeMethod('sendLocalNotification', notification.toMap()); await _channel.invokeMethod('sendLocalNotification', notification.toMap());
return notification.toMap().toString(); return notification.toMap().toString();

@ -1,6 +1,41 @@
# Generated by pub # Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile # See https://www.dartlang.org/tools/pub/glossary#lockfile
packages: packages:
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.33.0"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
collection: collection:
dependency: transitive dependency: transitive
description: description:
@ -8,11 +43,116 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.14.11" version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.6"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
front_end:
dependency: transitive
description:
name: front_end
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.6"
glob:
dependency: transitive
description:
name: glob
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.7"
html:
dependency: transitive
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.3+3"
http:
dependency: transitive
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0"
http_multi_server:
dependency: transitive
description:
name: http_multi_server
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
io:
dependency: transitive
description:
name: io
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1+1"
json_rpc_2:
dependency: transitive
description:
name: json_rpc_2
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.9"
kernel:
dependency: transitive
description:
name: kernel
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.6"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.3+2"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.3+1"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -20,11 +160,172 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.6" version: "1.1.6"
mime:
dependency: transitive
description:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.6+2"
mockito:
dependency: "direct dev"
description:
name: mockito
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
multi_server_socket:
dependency: transitive
description:
name: multi_server_socket
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
node_preamble:
dependency: transitive
description:
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.4"
package_config:
dependency: transitive
description:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
package_resolver:
dependency: transitive
description:
name: package_resolver
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.6"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
platform:
dependency: "direct main"
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
plugin:
dependency: transitive
description:
name: plugin
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+3"
pool:
dependency: transitive
description:
name: pool
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.6"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.2"
shelf:
dependency: transitive
description:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.3+3"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
shelf_static:
dependency: transitive
description:
name: shelf_static
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.8"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.2+4"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.99" version: "0.0.99"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.5"
source_maps:
dependency: transitive
description:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.8"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.8"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
test:
dependency: "direct dev"
description:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.4"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -32,6 +333,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.6" version: "1.1.6"
utf:
dependency: transitive
description:
name: utf
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.0+5"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
@ -39,5 +347,33 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.8" version: "2.0.8"
vm_service_client:
dependency: transitive
description:
name: vm_service_client
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.6"
watcher:
dependency: transitive
description:
name: watcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.7+10"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.9"
yaml:
dependency: transitive
description:
name: yaml
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.15"
sdks: sdks:
dart: ">=2.0.0-dev.68.0 <3.0.0" dart: ">=2.0.0 <3.0.0"

@ -1,6 +1,6 @@
name: jpush_flutter name: jpush_flutter
description: Offically supported JPush Flutter plugin. description: Offically supported JPush Flutter plugin.
version: 0.0.3 version: 0.0.5
author: huminios <h380108184@gmail.com> author: huminios <h380108184@gmail.com>
homepage: https://www.jiguang.cn homepage: https://www.jiguang.cn
@ -8,9 +8,13 @@ environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies: dependencies:
platform: ^2.0.0
flutter: flutter:
sdk: flutter sdk: flutter
dev_dependencies:
test: ^1.3.0
mockito: ^3.0.0
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec # following page: https://www.dartlang.org/tools/pub/pubspec

@ -0,0 +1,88 @@
import 'package:flutter/services.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import 'package:test/test.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
void main() {
MockMethodChannel mockChannel;
JPush jpush;
setUp(() {
mockChannel = new MockMethodChannel();
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
});
jpush.setup(
appKey: "a1703c14b186a68a66ef86c1",
channel: "theChannel",
production: false
);
test('applyPushAuthority on ios with params', () {
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
jpush.applyPushAuthority(new NotificationSettingsIOS(
sound: true,
alert: true,
badge: true));
verify(mockChannel.invokeMethod('applyPushAuthority',
<String, bool>{'sound': true, 'badge': true, 'alert': true}));
});
test('addEventHandler', () {
// TODO:
});
test('setAlias', () {
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
jpush.setAlias('alias').then((map) {
expect(map, contains('alias'));
}).catchError((error) {});
});
test('deleteAlias', () {
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
jpush.deleteAlias().then((map) {
expect(map, contains('alias'));
}).catchError((error) {});
});
test('deleteAlias', () {
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
jpush.deleteAlias().then((map) {
expect(map, contains('alias'));
}).catchError((error) {});
});
test('addTags', () {
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
jpush.addTags(["tag1","tag2"]).then((map) {
expect(map, contains('tags'));
}).catchError((error) {});
});
test('deleteTags', () {
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
jpush.deleteTags(["tag1","tag2"]).then((map) {
expect(map, contains('tags'));
}).catchError((error) {});
});
test('setTags', () {
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
jpush.setTags(["tag1","tag2"]).then((map) {
expect(map, contains('tags'));
}).catchError((error) {});
});
test('getAllTags', () {
jpush = new JPush.private(mockChannel, FakePlatform(operatingSystem: 'ios'));
jpush.getAllTags().then((map) {
expect(map, contains('tags'));
}).catchError((error) {});
});
}
class MockMethodChannel extends Mock implements MethodChannel {}
Loading…
Cancel
Save