cloud_firestore_api 0.0.2 icon indicating copy to clipboard operation
cloud_firestore_api: ^0.0.2 copied to clipboard

A clean and efficient approach to dealing with data from Firestore.

example/lib/main.dart

import 'dart:math';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore_api/abstracts/writeable.dart';
import 'package:cloud_firestore_api/api/firestore_api.dart';
import 'package:example/cloud_firestore_api/views/cloud_firestore_api/cloud_firestore_api_view.dart';
import 'package:flutter/material.dart';

import 'cloud_firestore_api/data/dtos/example_dto.dart';

void main() async {
  runApp(const MyApp());
}

class CreateExampleRequest extends Writeable {
  CreateExampleRequest({
    required this.exampleDTO,
  });

  final ExampleDTO exampleDTO;

  @override
  Map<String, dynamic> toJson() => exampleDTO.toJson();
}

class ExampleAPI extends FirestoreAPI<ExampleDTO> {
  ExampleAPI()
      : super(
          collectionPath: () => 'Examples',
          firebaseFirestore: FirebaseFirestore.instance,
          fromJson: ExampleDTO.fromJson,
        );

  void createExample() {
    final random = Random();
    create(
      writeable: CreateExampleRequest(
        exampleDTO: ExampleDTO(
          thisIsABoolean: random.nextBool(),
          thisIsANumber: random.nextDouble(),
          thisIsAString: ['yes', 'maybe'][random.nextInt(2)],
        ),
      ),
    );
  }

  static ExampleAPI get locate => ExampleAPI();
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const CloudFirestoreApiView(),
    );
  }
}
2
likes
140
pub points
45%
popularity

Publisher

verified publisher iconcodaveto.com

A clean and efficient approach to dealing with data from Firestore.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.BSD-3-Clause (LICENSE)

Dependencies

cloud_firestore, feedback_response, flutter

More

Packages that depend on cloud_firestore_api