pushy_flutter 1.0.3
pushy-flutter #
The official Pushy SDK for Flutter apps.
Pushy is the most reliable push notification gateway, perfect for real-time, mission-critical applications.
Usage #
Please refer to our detailed documentation to get started.
License #
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:io' show Platform;
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:pushy_flutter/pushy_flutter.dart';
void main() => runApp(Main());
class Main extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Pushy',
debugShowCheckedModeBanner: false,
theme: ThemeData(
// Light theme with dark action bar
brightness: Brightness.light,
primaryColor: Colors.grey[900],
accentColor: Colors.redAccent,
),
home: PushyDemo(),
);
}
}
class PushyDemo extends StatefulWidget {
@override
_PushyDemoState createState() => _PushyDemoState();
}
class _PushyDemoState extends State<PushyDemo> {
String _deviceToken = 'Loading...';
String _instruction = '(please wait)';
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method
Future<void> initPlatformState() async {
// Start the Pushy service
Pushy.listen();
// Request the WRITE_EXTERNAL_STORAGE permission on Android so that the Pushy SDK will be able to persist the device token in the external storage
Pushy.requestStoragePermission();
// Set custom notification icon (Android)
Pushy.setNotificationIcon('ic_notify');
try {
// Register the device for push notifications
String deviceToken = await Pushy.register();
// Print token to console/logcat
print('Device token: $deviceToken');
// Send the token to your backend server
// ...
// Update UI with token
setState(() {
_deviceToken = deviceToken;
_instruction =
Platform.isAndroid ? '(copy from logcat)' : '(copy from console)';
});
} on PlatformException catch (error) {
// Print to console/logcat
print('Error: ${error.message}');
// Show error
setState(() {
_deviceToken = 'Registration failed';
_instruction = '(restart app to try again)';
});
}
// Listen for push notifications
Pushy.setNotificationListener((Map<String, dynamic> data) {
// Print notification payload data
print('Received notifications: $data');
// Clear iOS app badge number
Pushy.clearBadge();
// Extract notification messsage
String message = data['message'] ?? 'Hello World!';
// Display an alert with the "message" payload value
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Pushy'),
content: Text(message),
actions: [
FlatButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop('dialog');
},
)
]);
},
);
});
}
@override
Widget build(BuildContext context) {
// Demo app UI
return Scaffold(
appBar: AppBar(
title: const Text('Pushy'),
),
body: Builder(
builder: (context) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset('assets/ic_logo.png', width: 90),
Padding(
padding: const EdgeInsets.all(10),
child: Text(_deviceToken,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: Colors.grey[700])),
),
Text(_instruction,
style: TextStyle(fontSize: 13, color: Colors.grey[600])),
])),
),
);
}
}
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
pushy_flutter: ^1.0.3
2. Install it
You can install packages from the command line:
with Flutter:
$ flutter pub get
Alternatively, your editor might support flutter pub get
.
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
import 'package:pushy_flutter/pushy_flutter.dart';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
75
|
Health:
Code health derived from static analysis.
[more]
|
99
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
40
|
Overall:
Weighted score of the above.
[more]
|
75
|
We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.7.0
- pana: 0.13.1+4
- Flutter: 1.12.13+hotfix.4
Health issues and suggestions
Document public APIs. (-1 points)
14 out of 14 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.
Maintenance issues and suggestions
Provide a file named CHANGELOG.md
. (-20 points)
Changelog entries help developers follow the progress of your package. See the example generated by stagehand
.
Homepage URL doesn't exist. (-20 points)
At the time of the analysis the homepage
field https://pushy.me/
was unreachable.
The package description is too short. (-20 points)
Add more detail to the description
field of pubspec.yaml
. Use 60 to 180 characters to describe the package, what it does, and its target use case.
Dependencies
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.1.0 <3.0.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | 1.14.12 | |
meta | 1.1.8 | ||
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |