Commit 55b2cbd6 authored by Michal Cikatricis's avatar Michal Cikatricis
Browse files

Feat (collections): sync

parent 7ff33df9
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
import 'package:firebase_auth/firebase_auth.dart';
import 'package:get_it/get_it.dart';
import 'package:stamped/data/mapper/mapper.dart';
import 'package:stamped/service/media_service.dart';
@@ -10,11 +11,17 @@ class IoCContainer {
  IoCContainer._();

  static void initialize() {
    get.registerSingleton(PostcardService());
    get.registerSingleton(UserService());
    get.registerSingleton(
      PostcardService(
        get<UserService>(),
      ),
    );
    get.registerSingleton(MediaService());
    get.registerSingleton(
      Mapper(get<UserService>()),
      Mapper(
        get<UserService>(),
      ),
    );
  }
}
+5 −5
Original line number Diff line number Diff line
@@ -26,11 +26,11 @@ class AppWrapper extends StatelessWidget {
            return Center(child: Text('Error: ${snapshot.error!}'));
          }

          if (snapshot.connectionState == ConnectionState.active) {
            if (snapshot.data == null) {
              return LoginPage();
            }
          }
          // if (snapshot.connectionState == ConnectionState.active) {
          //   if (snapshot.data == null) {
          //     return LoginPage();
          //   }
          // }
          return BottomNavBar();
        },
      ),
+0 −14
Original line number Diff line number Diff line
@@ -26,20 +26,6 @@ class PostcardTile extends StatelessWidget {
    ); // pass it to the existing constructor
  }

  // late Postcard _postcard;
  //
  // PostcardTile._(this._postcard, {Key? key}) : super(key: key);
  //
  // factory PostcardTile.fromEntityAsync(PostcardEntity entity) {
  //   return PostcardTile._createAsync(entity);
  // }
  //
  // static Future<PostcardTile> _createAsync(PostcardEntity entity) async {
  //   final postcard = await Mapper().entityToPostcard(entity);
  //   final tile = PostcardTile._(postcard);
  //   return tile;
  // }

  @override
  Widget build(BuildContext context) {
    final Mapper mapper = get<Mapper>();
+8 −3
Original line number Diff line number Diff line
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:stamped/data/entities/postcard_entity.dart';
import 'package:stamped/service/user_service.dart';

class PostcardService {
  final UserService _userService;
  final _postcardCollection =
      FirebaseFirestore.instance.collection('postcards').withConverter(
    fromFirestore: (snapshot, options) {
@@ -16,9 +18,12 @@ class PostcardService {
    },
  );

  Stream<List<PostcardEntity>> get postcardsStream => _postcardCollection
      .snapshots()
      .map((querySnapshot) => querySnapshot.docs.map((docSnapshot) => docSnapshot.data()).toList());
  PostcardService(this._userService);

  Stream<List<PostcardEntity>> get postcardsStream {
    return _postcardCollection.snapshots().map((querySnapshot) =>
        querySnapshot.docs.map((docSnapshot) => docSnapshot.data()).toList());
  }

  Future<void> create(PostcardEntity postcardEntity) {
    return _postcardCollection.add(postcardEntity);