firebase_database 0.1.4

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

Firebase Realtime Database for Flutter

pub package

A Flutter plugin to use the Firebase Realtime Database API.

For Flutter plugins for other Firebase products, see FlutterFire.md.

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Usage

To use this plugin, add firebase_database as a dependency in your pubspec.yaml file.

Getting Started

See the example directory for a complete sample app using Firebase Realtime Database.

0.1.4

  • Add FLT prefix to iOS types
  • Avoid error when clearing FirebaseSortedList

0.1.3

  • Fix memory leak in FirebaseAnimatedList

0.1.2

  • Change GMS dependency to 11.+

0.1.1

  • Add RTDB transaction support.

0.1.0+1

  • Aligned author name with rest of repo.

0.1.0

  • Breaking Change: Added current list index to the type signature of itemBuilder for FirebaseAnimatedList.

0.0.14

  • Fix FirebaseSortedList to show data changes.

0.0.13

  • Fixed lingering value/child listeners.

0.0.12

  • Updated to Firebase SDK to always use latest patch version for 11.0.x builds

0.0.11

  • Fixes startAt/endAt on iOS when used without a key

0.0.10

  • Added workaround for inconsistent numeric types when using keepSynced on iOS
  • Bug fixes to Query handling

0.0.9

  • Updated to Firebase SDK Version 11.0.1

0.0.8

  • Added missing offline persistence and query functionality on Android
  • Fixed startAt query behavior on iOS
  • Persistence methods no longer throw errors on failure, return false instead
  • Updates to docs and tests

0.0.7

  • Fixed offline persistence on iOS

0.0.6

  • Various APIs added to FirebaseDatabase and Query
  • Added removal and priority to DatabaseReference
  • Improved documentation
  • Added unit tests

0.0.5

  • Fixed analyzer warnings

0.0.4

  • Removed stub code and replaced it with support for more event types, paths, auth
  • Improved example

0.0.3

  • Updated README.md
  • Bumped buildToolsVersion to 25.0.3
  • Added example app

0.0.2

  • Fix compilation error

0.0.1

  • Initial Release

example/lib/main.dart

// Copyright 2017, the Flutter project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_database/ui/firebase_animated_list.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Database Example',
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter;
  final DatabaseReference _counterRef =
      FirebaseDatabase.instance.reference().child('counter');
  final DatabaseReference _messagesRef =
      FirebaseDatabase.instance.reference().child('messages');
  StreamSubscription<Event> _counterSubscription;
  StreamSubscription<Event> _messagesSubscription;
  bool _anchorToBottom = false;

  String _kTestKey = 'Hello';
  String _kTestValue = 'world!';

  @override
  void initState() {
    super.initState();
    FirebaseDatabase.instance.setPersistenceEnabled(true);
    FirebaseDatabase.instance.setPersistenceCacheSizeBytes(10000000);
    _counterRef.keepSynced(true);
    _counterSubscription = _counterRef.onValue.listen((Event event) {
      setState(() {
        _counter = event.snapshot.value ?? 0;
      });
    });
    _messagesSubscription =
        _messagesRef.limitToLast(10).onChildAdded.listen((Event event) {
      print('Child added: ${event.snapshot.value}');
    });
  }

  @override
  void dispose() {
    super.dispose();
    _messagesSubscription.cancel();
    _counterSubscription.cancel();
  }

  Future<Null> _increment() async {
    await FirebaseAuth.instance.signInAnonymously();
    // Increment counter in transaction.
    final TransactionResult transactionResult =
        await _counterRef.runTransaction((MutableData mutableData) async {
      mutableData.value = (mutableData.value ?? 0) + 1;
      return mutableData;
    });

    if (transactionResult.committed) {
      _messagesRef.push().set(<String, String>{
        _kTestKey: '$_kTestValue ${transactionResult.dataSnapshot.value}'
      });
    } else {
      print('Transaction not committed.');
      if (transactionResult.error != null) {
        print(transactionResult.error.message);
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: const Text('Flutter Database Example'),
      ),
      body: new Column(
        children: <Widget>[
          new Flexible(
            child: new Center(
              // ignore: prefer_const_constructors
              child: new Text(
                'Button tapped $_counter time${ _counter == 1 ? '' : 's' }.\n\n'
                    'This includes all devices, ever.',
              ),
            ),
          ),
          new ListTile(
            leading: new Checkbox(
              onChanged: (bool value) {
                setState(() {
                  _anchorToBottom = value;
                });
              },
              value: _anchorToBottom,
            ),
            title: const Text('Anchor to bottom'),
          ),
          new Flexible(
            child: new FirebaseAnimatedList(
              key: new ValueKey<bool>(_anchorToBottom),
              query: _messagesRef,
              reverse: _anchorToBottom,
              sort: _anchorToBottom
                  ? (DataSnapshot a, DataSnapshot b) => b.key.compareTo(a.key)
                  : null,
              itemBuilder: (BuildContext context, DataSnapshot snapshot,
                  Animation<double> animation, int index) {
                return new SizeTransition(
                  sizeFactor: animation,
                  child: new Text("$index: ${snapshot.value.toString()}"),
                );
              },
            ),
          ),
        ],
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _increment,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ),
    );
  }
}

1. Depend on it

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


dependencies:
  firebase_database: "^0.1.4"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:firebase_database/firebase_database.dart';
        
Version Uploaded Documentation Archive
0.1.4 Dec 3, 2017 Go to the documentation of firebase_database 0.1.4 Download firebase_database 0.1.4 archive
0.1.3 Nov 28, 2017 Go to the documentation of firebase_database 0.1.3 Download firebase_database 0.1.3 archive
0.1.2 Oct 17, 2017 Go to the documentation of firebase_database 0.1.2 Download firebase_database 0.1.2 archive
0.1.1 Oct 17, 2017 Go to the documentation of firebase_database 0.1.1 Download firebase_database 0.1.1 archive
0.1.0 Aug 29, 2017 Go to the documentation of firebase_database 0.1.0 Download firebase_database 0.1.0 archive
0.0.14 Aug 3, 2017 Go to the documentation of firebase_database 0.0.14 Download firebase_database 0.0.14 archive
0.0.13 Jul 29, 2017 Go to the documentation of firebase_database 0.0.13 Download firebase_database 0.0.13 archive
0.0.12 Jul 7, 2017 Go to the documentation of firebase_database 0.0.12 Download firebase_database 0.0.12 archive
0.0.11 Jun 22, 2017 Go to the documentation of firebase_database 0.0.11 Download firebase_database 0.0.11 archive
0.0.10 Jun 22, 2017 Go to the documentation of firebase_database 0.0.10 Download firebase_database 0.0.10 archive

All 18 versions...

Analysis

This feature is new.
We welcome feedback.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Dec 6, 2017
  • Dart: 2.0.0-dev.8.0
  • pana: 0.7.3+1
  • Flutter: 0.0.19

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
99
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
99
Overall score:
Weighted score of the above. [more]
99

Platforms

Detected platforms: Flutter

pubspec reference with no conflicts

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.39
meta ^1.0.5 1.1.1 1.1.2
Transitive dependencies
async 1.13.3 2.0.1
charcode 1.1.1
collection 1.14.3
http 0.11.3+14 0.11.3+16
http_parser 3.1.1
path 1.5.1
sky_engine 0.0.99
source_span 1.4.0
stack_trace 1.9.1
string_scanner 1.0.2
typed_data 1.1.4 1.1.5
vector_math 2.0.5
Dev dependencies
flutter_test