firestorm 0.2.4 copy "firestorm: ^0.2.4" to clipboard
firestorm: ^0.2.4 copied to clipboard

A data access API and ODM tool for Firebase's Firestore and Realtime Database

example/example.dart

/// This example shows basic usage of Firestorm:
/// - Defining a data entity annotated with @FirestormObject (see commented code below).
/// - Generating code using the Firestorm code generator.
/// - Initializing Firestorm with Firebase.
/// - Registering classes
/// - Using Firestorm to perform CRUD operations on the data entity.

/*

import 'package:firestorm/firestorm.dart';

@FirestormObject()
class Person {

  String id;
  String firstname;
  String lastname;
  int age;
  double height;
  bool isEmployed;
  List<String> friends;

  Person(this.id, this.firstname, this.lastname, this.age, this.height,
      this.isEmployed, this.friends);

}

 */

import 'package:firestorm/annotations/firestorm_object.dart';
import 'package:firestorm/firestorm.dart';
import 'package:firestorm/fs/fs.dart';
import 'package:firestorm/rdb/rdb.dart';
import 'package:flutter/material.dart';

// Sample data class - typically declared in a separate file.
@FirestormObject() // This annotation is used to mark the class for Firestorm code generation.
class Person {

  String id; // Necessary ID field for Firestorm objects.
  String firstname;
  String lastname;
  int age;

  Person(this.id, this.firstname, this.lastname, this.age);

}

main() async {
  WidgetsFlutterBinding.ensureInitialized(); // Initialize Flutter first

  await FS.init(); // Initialize Firestore if used.
  await RDB.init(); // Initialize Realtime database if used.

  // TODO - Uncomment when generated:
  //registerClasses(); // To be generated by running `dart pub run build_runner build`

  runApp(MyApp()); //Run your Flutter app here...
}

// App widget - typically defined in a separate file.
class MyApp extends StatelessWidget {

  // Example object
  Person person = Person(Firestorm.randomID(), "John", "Doe", 23);

  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      title: 'Firestorm Example',
      home: Scaffold(
        appBar: AppBar(title: Text('Firestorm Example')),
        body: Center(
          child: ElevatedButton(
            onPressed: () {

              // Example button to trigger Firestorm operation
              FS.create.one(person).then((_) {
                print("Person created successfully!");
              }).catchError((error) {
                print("Error creating person: $error");
              });

            },
            child: Text('Create Person'),
          ),
        ),
      ),
    );
  }
}
2
likes
140
points
64
downloads

Publisher

verified publisherraylabz.com

Weekly Downloads

A data access API and ODM tool for Firebase's Firestore and Realtime Database

Homepage
Repository (GitHub)
View/report issues

Topics

#firebase #orm #odm #firestore #database

Documentation

Documentation
API reference

Funding

Consider supporting this project:

buymeacoffee.com

License

Apache-2.0 (license)

Dependencies

analyzer, build, cloud_firestore, firebase_core, firebase_database, flutter, glob, logger, source_gen, uuid

More

Packages that depend on firestorm