objectdb_flutter 0.0.3

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

objectdb_flutter

Reactive ObjectDB helper.

CAUTION This plugin is still in development. Use at your own risk. If you notice any bugs you can create an issue on GitHub. You're also welcome to contribute using pull requests. Please open an issue before spending time on any pull request.

Subscribe to store inside widget to keep the view up-to-date.

See example for implementation and ObjectDB for general db API.

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:io';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart' as path;
import 'package:objectdb_flutter/objectdb_flutter.dart';

// declare db object
ObjectDB db;

void main() async {
  // get document directory using path_provider plugin
  Directory appDocDir = await path.getApplicationDocumentsDirectory();

  String dbFilePath = [appDocDir.path, 'user.db'].join('/');

  // delete old database file if exists
  File dbFile = File(dbFilePath);

  // check if database already exists
  var isNew = !await dbFile.exists();
  if (!isNew) dbFile.deleteSync();
  // initialize and open database
  db = ObjectDB(dbFilePath);
  db.open();

  // insert sample data
  db.insertMany([
    {
      'name': {'first': 'Alex', 'last': 'Boyle'},
      'message': 'abc',
      'active': true,
      'count': 0,
    },
    {
      'name': {'first': 'Maia', 'last': 'Herzog'},
      'message': 'def',
      'active': true,
      'count': 0,
    },
    {
      'name': {'first': 'Curtis', 'last': 'Smith'},
      'message': 'ghi',
      'active': true,
      'count': 0,
    },
    {
      'name': {'first': 'Jaquelin', 'last': 'Renner'},
      'message': 'jkl',
      'active': false,
      'count': 0,
    },
    {
      'name': {'first': 'Denis', 'last': 'Swift'},
      'message': 'mno',
      'active': true,
      'count': 0,
    },
    {
      'name': {'first': 'Anna', 'last': 'Metz'},
      'message': 'pqr',
      'active': true,
      'count': 0,
    },
    {
      'name': {'first': 'Malinda', 'last': 'Reynolds'},
      'message': 'stu',
      'active': false
    },
  ]);

  // simulate insert/update/delete
  int i = 0;
  new Timer.periodic(Duration(seconds: 2), (Timer t) {
    db.insert({
      'name': {'first': 'Malinda', 'last': 'Reynolds'},
      'message': 'hoho ' + i.toString(),
      'active': i % 2 == 0,
      'count': i++
    });

    if (i > 10) i = 0;
  });

  new Timer.periodic(Duration(seconds: 10), (Timer t) {
    db.update({
      Op.gte: {'count': 5}
    }, {
      Op.set: {'message': 'updated'}
    });
  });

  new Timer.periodic(Duration(seconds: 15), (Timer t) {
    db.remove({'message': 'updated'});
  });

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ObjectDB Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'ObjectDB Demo Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with StoreWatcherMixin<MyHomePage> {
  Store contacts;

  void initState() {
    super.initState();

    init();
  }

  void init() async {
    contacts = await listenToStore(db, {'active': true});
  }

  @override
  void dispose() async {
    await db.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: contacts == null // check if _contacts has been initialized
          ? Center(
              child: Text('loading...'),
            )
          : ListView(
              children:
                  contacts.map((contact) => contactItem(contact)).toList(),
            ),
    );
  }
}

// creates list tile with contact info
Widget contactItem(Map contact) {
  return ListTile(
    title: Text(contact['name']['first'] + ' ' + contact['name']['last']),
    subtitle: Text(contact['message']),
  );
}

Use this package as a library

1. Depend on it

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


dependencies:
  objectdb_flutter: ^0.0.3

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:objectdb_flutter/objectdb_flutter.dart';
  
Version Uploaded Documentation Archive
0.0.3 Sep 20, 2018 Go to the documentation of objectdb_flutter 0.0.3 Download objectdb_flutter 0.0.3 archive
0.0.1 Aug 30, 2018 Go to the documentation of objectdb_flutter 0.0.1 Download objectdb_flutter 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Sep 20, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3
  • Flutter: 0.8.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release.

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.0.0 <3.0.0
flutter 0.0.0
objectdb ^1.0.5 1.0.5
Transitive dependencies
collection 1.14.11
deeply 1.0.1
execution_queue 1.0.2
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test