cloud_firestore_api 0.0.11 copy "cloud_firestore_api: ^0.0.11" to clipboard
cloud_firestore_api: ^0.0.11 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();
    createDoc(
      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
0
pub points
65%
popularity

Publisher

verified publishercodaveto.com

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cloud_firestore, feedback_response, flutter

More

Packages that depend on cloud_firestore_api