pwa 0.2.0

  • Readme
  • Changelog
  • Installing
  • 78

Progressive Web App (PWA) for Dart #

Progressive web apps (PWA) are a hybrid of regular web pages (or websites) and a mobile application. This new application model attempts to combine features offered by most modern browsers with the benefits of mobile experience.

Warning: the API is experimental, and subject to change.

Background #

PWA is using ServiceWorkers:

Learn more about PWAs:

Articles about this packages:

Tutorial and Examples #

Getting started


This library requires webdev installed locally. Install it using the command:

pub global activate webdev

  • Getting started: pwa_defaults

    • Shows you how to use the pwa package and what it does.
    • Enables offline asset caching for you web app out-of-the-box.
  • Additional offline urls: additional_offline_urls

    • Show you how to create the entry point for customization.
    • Gives you the ability to add additional URLs for the offline cache.

Customize caching

  • Custom routes: custom_routes
    • Familiarize yourself with caching and routes.
    • Customize cache behavior for different parts of your app.

Push notification

  • Push notification: push_notification
    • Check and/or request Push permission.
    • Trigger and handle push event, show notification.

Planned features #

  • Typed Window <-> Worker communication, both Streams and request-reply patterns, something like:

    typedef Future<S> AsyncFunction<R, S>(R request);
    typedef S WireAdapter<R, S>(R input);
    abstract class MessageHub {
      AsyncFunction<R, S> getFunction<R, S>(String type,
          {WireAdapter<R, dynamic> encoder, WireAdapter<dynamic, S> decoder});
      void setHandler<R, S>(String type, AsyncFunction<R, S> handler,
          {WireAdapter<dynamic, R> decoder, WireAdapter<S, dynamic> encoder});
      Sink<T> getSink<T>(String type, {WireAdapter<T, dynamic> encoder});
      Stream<T> getStream<T>(String type, {WireAdapter<dynamic, T> decoder});
  • Push Notification

    • notification for the client app
    • one-method registration and/or status request

0.2.0 #

  • Using 'webdev' as new default build tool, replacing 'pub'.
  • As a consequence of the change above, the built files are placed directly inside build/ instead of build/web.
  • Fixed issues related to special characters inside Dart generated code.

0.1.12 #

  • Updated dependency.

0.1.11 #

  • Support Dart 2 stable.

0.1.10 #

  • Support the latest version of package:service_worker.

0.1.9+1 #

  • Support args: ">=0.13.7 <2.0.0".

0.1.9 #

  • Remove package:func dependency.

0.1.8 #

  • Better pub.exe detection on Windows.
  • Do not abort if project build fails.

0.1.7 #

  • Generate manifest.json.

0.1.6 #

  • Do not include .scss files in generated offline URLs.

0.1.5 #

  • Console logging to uncover install/activation issues. That also causes a behavior change: errors during install won't interrupt the setup of the SW.
  • Updated code generator:
    • Breaking change: --lib-dir will refer to the lib directory of the project, while its previous purpose will be handled by --pwa-lib-dir. Most users won't be affected (when using the defaults).
    • Invoke pub build not only on empty build/ directory, but also when changes were detected.

0.1.4 #

  • Expose clientKeys in PushPermission.

0.1.3 #

  • Workaround for a bug in Chrome: ServiceWorkerContainer.ready may not complete in certain cases (for no apparent reason). Added a timeout of two seconds and return the registered SW instance.

  • Added higher-level API helpers for checking Push permission and handling push events.

0.1.2 #

  • Filter offline URLs:
    • dart2js debug outputs (
    • package:test and package:package_resolver assets

0.1.1 #

  • Generating lastModified timestamp (in String) for offline URLs.
  • Encouraging (but not yet enforcing) to use a version String in
  • The generated pwa.dart uses offline.lastModified as the version.

0.1.0 #

Breaking changes:

  • Remove deprecated methods and classes (see changes in version 0.0.5).

  • Changed the initialization of the Service Worker:

    • pwa.g.dart -> pwa.dart (source code generation is one-time only)
    • Client unregisters old version (ANY ServiceWorker ending with /pwa.g.dart.js)
  • Worker.onInstall and Worker.onActicate became fields (instead of being methods).

0.0.5 #

API refactoring:

  • Remove Pwa class name prefix (not immediately breaking, added deprecated notes)

    • PwaClient -> Client
    • PwaWorker -> Worker
    • PwaCacheMixin -> FetchStrategy
  • Renamed ambiguous items related to the Fetch API (not immediately breaking, added deprecated notes)

    • Handler -> RequestHandler
    • Matcher -> RequestMatcher
    • Router -> FetchRouter
    • defaultFetchHandler -> defaultRequestHandler
    • noCacheNetworkFetch -> noCacheNetworkRequestHandler
  • Renamed DynamicCache's noNetworkCaching -> skipDiskCache (not immediately breaking, added deprecated notes).

  • Updated methods in FetchRouter (not immediately breaking, added deprecated notes)

    • add -> registerMatcher
    • new method: registerUrl (will make urlPrefixMatcher internal)
    • get -> registerGetUrl
    • post -> registerPostUrl

0.0.4 #

  • Fix path separators on Windows.
  • Updated examples:
    • Added pwa_defaults.
    • Moved example into examples/custom_routes.
  • Execute pub build when the project has no build/web directory yet.

0.0.3 #

Breaking changes:

  • (API) BlockCache and DynamicCache don't expose their initialization parameters. This is a minor change, it is unlikely to affect anybody.

  • (behavior) BlockCache and DynamicCache use path-specific cache prefixes, in order to prevent collision between apps that are installed on the same domain.

    This fixes unintended cache collisions, but also breaks if you were building on sharing the caches between apps. In this case, use the new prefix optional argument when instantiating caches.

    If you have used only a single application in the root of the domain, you are not affected by this change.

0.0.2 #

  • Fix default codegen.
  • Call skipWaiting() by default (can be disabled through flag).
  • The generated offline URLs and the SW registration is changed to relative URLS, we can put the application in any directory.
  • DynamicCache evicts older entries first (previously it was random).
  • DynamicCache doesn't evicts old entries on initialization, which enables offline-aware caches to outlive the set expiration until the next successful network event.
  • Support for caching common web fonts.

0.0.1 #

Experimental release, looking for feedback.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  pwa: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or 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:pwa/client.dart';
import 'package:pwa/worker.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix bin/pwa.dart. (-9.54 points)

Analysis of bin/pwa.dart reported 20 hints, including:

line 12 col 22: Unnecessary new keyword.

line 46 col 20: Unnecessary new keyword.

line 55 col 23: Unnecessary new keyword.

line 93 col 24: Unnecessary new keyword.

line 111 col 21: Unnecessary new keyword.

Fix lib/client.dart. (-2.96 points)

Analysis of lib/client.dart reported 6 hints, including:

line 9 col 35: Use = to separate a named parameter from its default value.

line 9 col 58: Unnecessary new keyword.

line 19 col 67: Use = to separate a named parameter from its default value.

line 87 col 30: Use = to separate a named parameter from its default value.

line 93 col 9: Unnecessary new keyword.

Fix lib/src/cache.dart. (-2.96 points)

Analysis of lib/src/cache.dart reported 6 hints, including:

line 85 col 25: Unnecessary new keyword.

line 155 col 20: Use = to separate a named parameter from its default value.

line 158 col 19: Use = to separate a named parameter from its default value.

line 161 col 23: Use = to separate a named parameter from its default value.

line 212 col 21: Unnecessary new keyword.

Fix additional 4 files with analysis or formatting issues. (-5.47 points)

Additional issues in the following files:

  • lib/worker.dart (5 hints)
  • lib/src/handler.dart (4 hints)
  • lib/src/push.dart (1 hint)
  • lib/src/router.dart (1 hint)

Maintenance suggestions

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.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and pwa.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
args ^1.4.0 1.6.0
dart_style >=0.2.16 <2.0.0 1.3.4
glob ^1.1.3 1.2.0
service_worker >=0.1.0 <0.3.0 0.2.4
yaml ^2.1.12 2.2.0
Transitive dependencies
_fe_analyzer_shared 2.1.0
analyzer 0.39.6
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
html 0.14.0+3
js 0.6.1+1
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.9.3
path 1.6.4
pedantic 1.9.0
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+14