cell_memory_firebase 1.0.2
cell_memory_firebase: ^1.0.2 copied to clipboard
Cloud Firestore MemoryStore for cell_memory: durable Cell records in Firestore with transactions and compare-and-swap revisions. Flutter only.
// Copyright (c) 2025-Present Lee Man Hoi Simon. See the AUTHORS file
// for details. Use of this source code is governed by a MIT or
// Apache-2.0 license that can be found in the LICENSE file.
//
// SPDX-License-Identifier: MIT OR Apache-2.0
/// The walk-through example for `cell_memory_firebase`: a
/// [FirebaseMemoryStore] over Cloud Firestore. The app constructs the
/// store for a demo uid and shows the store contract; a real deployment
/// adds the Firebase configuration files (google-services.json or the
/// web options) and a Firestore database.
library;
import 'package:cell_memory_firebase/cell_memory_firebase.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MemoryFirebaseExampleApp());
}
/// The walk-through app: constructs a [FirebaseMemoryStore] for a demo
/// uid and displays the store contract.
class MemoryFirebaseExampleApp extends StatelessWidget {
/// Creates the example app.
const MemoryFirebaseExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'cell_memory_firebase example',
home: Scaffold(
appBar: AppBar(title: const Text('cell_memory_firebase example')),
body: FutureBuilder<String>(
future: _openStore(),
builder: (context, snapshot) => Center(
child: snapshot.hasData
? Text(snapshot.data!)
: snapshot.hasError
? Text('Error: ${snapshot.error}')
: const CircularProgressIndicator(),
),
),
),
);
}
/// Initializes Firebase and constructs the Firestore-backed store.
///
/// Without platform configuration the initialization fails and the
/// failure is displayed; the store construction itself is synchronous
/// and exercises the same public surface a real app uses.
Future<String> _openStore() async {
await Firebase.initializeApp();
final store = FirebaseMemoryStore(
firestore: FirebaseFirestore.instance,
uid: 'demo-uid',
);
return '${store.name} ready\n'
'capabilities: crossProcessCas=${store.capabilities.crossProcessCas}, '
'nativeTtl=${store.capabilities.nativeTtl}';
}
}