firebase_dart 1.1.0-dev.11 copy "firebase_dart: ^1.1.0-dev.11" to clipboard
firebase_dart: ^1.1.0-dev.11 copied to clipboard

A port of the Firebase database, auth and storage client to pure Dart code, usable on different platforms

example/main.dart

import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:firebase_dart/auth.dart';
import 'package:firebase_dart/core.dart';
import 'package:firebase_dart/database.dart';
import 'package:firebase_dart/implementation/pure_dart.dart';
import 'package:firebase_dart/storage.dart';

void main() async {
  FirebaseDart.setup();

  var app = await Firebase.initializeApp(
      options: FirebaseOptions.fromMap(json
          .decode(File('example/firebase-config.json').readAsStringSync())));

  var auth = FirebaseAuth.instanceFor(app: app);

  var user = auth.currentUser;

  print('current user (from cache) = ${user?.uid}');

  await auth.signInAnonymously();

  user = auth.currentUser;
  print('current user (after sign in anonymously) = ${user!.uid}');

  await user.updateProfile(displayName: 'Jane Doe');

  print('display name = ${user.displayName}');

  var storage = FirebaseStorage.instanceFor(app: app);

  var ref = storage.ref().child('test.txt');

  await ref.putString('hello world!',
      metadata: SettableMetadata(contentType: 'text/plain'));

  var m = await ref.getMetadata();
  print('content type of file test.txt: ${m.contentType}');

  var v = utf8.decode((await ref.getData(m.size))!);
  print('content of file test.txt: $v');

  ref = storage.ref().child('test.bin');

  var task = await ref.putData(Uint8List(1024 * 1024));
  print('upladed ${task.bytesTransferred} to test.bin: state = ${task.state}');

  var l = await storage.ref().listAll();

  for (var i in l.prefixes) {
    print('root contains directory ${i.fullPath}');
  }
  for (var i in l.items) {
    print('root contains file ${i.fullPath}');
  }

  var database = FirebaseDatabase(app: app);

  var dbRef = database.reference().child('test');

  var snap = await dbRef.once();

  print('content of database /test: ${snap.value}');

  await user.delete();

  user = auth.currentUser;
  print('current user (after delete) = ${user?.uid}');

  await app.delete();
}
125
likes
0
points
5.05k
downloads

Publisher

verified publisherappsup.be

Weekly Downloads

A port of the Firebase database, auth and storage client to pure Dart code, usable on different platforms

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

_discoveryapis_commons, async, clock, collection, crypto, expressions, firebaseapis, hive, http, intl, jose, js, logging, meta, openid_client, quiver, rxdart, sortedmap, stream_channel, synchronized, uuid, web_socket_channel

More

Packages that depend on firebase_dart