flutter_persistent_queue 0.1.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 68

persistent_queue #

Simple file-based non-volatile queue library for flutter.

Installation #

Add dependency to pubspec.yaml:

dependencies:
  ...
  flutter_persistent_queue: ^0.1.4

Run in your terminal:

flutter packages get

How it works #

Each JSON-encodable item to be queued goes to its own non-volatile file on the flutter-compatible devices. This particular design choice limits potential use cases requiring very long queues but otherwise provides high performance with very reduced resource usage, as it doesn't require serializing and deserializing contiguous or chunked dart:collections to the filesystem.

It's built on top of the also minimalistic Localstorage library. Concurrency-safety and sequential correctness is provided by the fantastic and easy to use Synchronized reentrant locks.

License #

MIT

[0.1.4] - 2019-02-27

[0.1.3] - 2019-02-27

  • silent flush/push error handling if user does not provide handlers
  • hard maxLength parameter added to enforce an absolute maximum queue length

[0.1.2] - 2019-02-26

  • fix error message and add stack trace to error handling

[0.1.1] - 2019-02-25

  • user-specified error handling behavior while flushing

[0.1.0] - 2019-02-21

  • minor source code readability improvements
  • no-reload feature added to setup method
  • improved example using FutureBuilder
  • no additional example dependencies

[0.0.1] - 2019-02-20

  • Initial release

example/lib/main.dart

import 'dart:math' show Random;
import 'package:flutter/foundation.dart' show debugPrint;
import 'package:flutter/material.dart';
import 'package:flutter_persistent_queue/flutter_persistent_queue.dart';

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

class _MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _runTests(),
      builder: (context, snapshot) {
        final txt = snapshot.data == null ? 'Wait!' : snapshot.data as String;
        return MaterialApp(
          home: Scaffold(
            body: Center(
              child: Text(txt),
            ),
          ),
        );
      },
    );
  }
}

Future<String> _runTests() async {
  try {
    await _basicTest();
    return 'Queue works! 😀';
  } catch (e, s) {
    _errHdlr(e, s);
    return 'Something went wrong 😤';
  }
}

Future<void> _basicTest() async {
  final pq = PersistentQueue(filename: 'pq', flushAt: 2000, errFunc: _errHdlr);
  await pq.setup(noReload: true);
  print('queue ready? ${pq.ready ? 'YES' : 'NO'}');

  final Set<int> sourceSet = Set(), targetSet = Set();
  for (int i = 1000; i > 0; --i) {
    final int val = Random().nextInt(4294967296);
    sourceSet.add(val);
    await pq.push(<String, dynamic>{'val': val});
  }
  print('queue loaded, ${pq.length} elements');

  await pq.flush((list) async {
    targetSet.addAll(list.map((val) => val['val'] as int));
  });
  print('queue flushed');

  final sourceList = sourceSet.toList(), targetList = targetSet.toList();
  sourceList.sort();
  targetList.sort();

  _assert(sourceList.length == targetList.length);
  for (int i = sourceList.length - 1; i >= 0; --i) {
    _assert(sourceList[i] == targetList[i]);
  }
}

void _assert(bool cta) => cta != true ? throw Exception('QueueFailed') : null;
void _errHdlr(dynamic err, [StackTrace stack]) => debugPrint('$err\n$stack');

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_persistent_queue: ^0.1.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_persistent_queue/flutter_persistent_queue.dart';
  
Version Uploaded Documentation Archive
0.1.4 Feb 27, 2019 Go to the documentation of flutter_persistent_queue 0.1.4 Download flutter_persistent_queue 0.1.4 archive
0.1.3 Feb 27, 2019 Go to the documentation of flutter_persistent_queue 0.1.3 Download flutter_persistent_queue 0.1.3 archive
0.1.2 Feb 26, 2019 Go to the documentation of flutter_persistent_queue 0.1.2 Download flutter_persistent_queue 0.1.2 archive
0.1.1 Feb 25, 2019 Go to the documentation of flutter_persistent_queue 0.1.1 Download flutter_persistent_queue 0.1.1 archive
0.1.0+2 Feb 21, 2019 Go to the documentation of flutter_persistent_queue 0.1.0+2 Download flutter_persistent_queue 0.1.0+2 archive
0.1.0+1 Feb 21, 2019 Go to the documentation of flutter_persistent_queue 0.1.0+1 Download flutter_persistent_queue 0.1.0+1 archive
0.1.0 Feb 21, 2019 Go to the documentation of flutter_persistent_queue 0.1.0 Download flutter_persistent_queue 0.1.0 archive
0.0.1 Feb 21, 2019 Go to the documentation of flutter_persistent_queue 0.0.1 Download flutter_persistent_queue 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Mar 6, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.3.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
localstorage ^1.2.0 1.2.0
meta ^1.1.6 1.1.6 1.1.7
synchronized ^2.1.0 2.1.0
Transitive dependencies
collection 1.14.11
path_provider 0.5.0+1
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8