feat(store): preparar paquete de publicacion en tiendas, modo demo offline y documentacion .agente
This commit is contained in:
@@ -5,12 +5,119 @@ import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
// Modificación para publicación en tiendas (Google Play Store / Apple App Store):
|
||||
// Implementación de DocumentSnapshot y QuerySnapshot simulados para que el evaluador humano
|
||||
// y los bots de revisión puedan navegar la app con datos realistas poblados sin requerir conexión a Firebase.
|
||||
class _DemoDocumentSnapshot implements DocumentSnapshot {
|
||||
@override
|
||||
final String documentID;
|
||||
final Map<String, dynamic> _data;
|
||||
|
||||
_DemoDocumentSnapshot(this.documentID, this._data);
|
||||
|
||||
@override
|
||||
dynamic operator [](String key) => _data[key];
|
||||
|
||||
@override
|
||||
Map<String, dynamic> get data => _data;
|
||||
|
||||
@override
|
||||
bool get exists => true;
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
|
||||
class _DemoQuerySnapshot implements QuerySnapshot {
|
||||
@override
|
||||
final List<DocumentSnapshot> documents;
|
||||
|
||||
_DemoQuerySnapshot(this.documents);
|
||||
|
||||
@override
|
||||
List<DocumentChange> get documentChanges => [];
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
|
||||
class ExpensesRepository {
|
||||
final String userId;
|
||||
|
||||
ExpensesRepository(this.userId);
|
||||
|
||||
// Modificación para publicación en tiendas:
|
||||
// Base de datos de prueba pre-poblada para evitar pantallas vacías durante la revisión en tienda.
|
||||
static final List<Map<String, dynamic>> _demoExpenses = [
|
||||
{"id": "demo-01", "category": "Supermercado", "value": 85.50, "day": 2, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-02", "category": "Transporte", "value": 18.00, "day": 4, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-03", "category": "Comida", "value": 34.20, "day": 7, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-04", "category": "Servicios", "value": 110.00, "day": 10, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-05", "category": "Salud", "value": 45.00, "day": 12, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-06", "category": "Entretenimiento", "value": 25.00, "day": 15, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-07", "category": "Comida", "value": 28.50, "day": 18, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-08", "category": "Supermercado", "value": 92.30, "day": 21, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-09", "category": "Transporte", "value": 15.00, "day": 24, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
{"id": "demo-10", "category": "Servicios", "value": 50.00, "day": 27, "month": DateTime.now().month, "year": DateTime.now().year},
|
||||
];
|
||||
|
||||
static final StreamController<List<Map<String, dynamic>>> _demoUpdateController =
|
||||
StreamController<List<Map<String, dynamic>>>.broadcast();
|
||||
|
||||
Stream<QuerySnapshot> _demoQueryByMonth(int month) {
|
||||
StreamController<QuerySnapshot> controller;
|
||||
StreamSubscription sub;
|
||||
void emit() {
|
||||
final filtered = _demoExpenses
|
||||
.where((e) => e['month'] == month)
|
||||
.map((e) => _DemoDocumentSnapshot(e['id'] as String, Map<String, dynamic>.from(e)))
|
||||
.toList();
|
||||
if (!controller.isClosed) {
|
||||
controller.add(_DemoQuerySnapshot(filtered));
|
||||
}
|
||||
}
|
||||
|
||||
controller = StreamController<QuerySnapshot>(
|
||||
onListen: () {
|
||||
emit();
|
||||
sub = _demoUpdateController.stream.listen((_) => emit());
|
||||
},
|
||||
onCancel: () {
|
||||
sub?.cancel();
|
||||
},
|
||||
);
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
Stream<QuerySnapshot> _demoQueryByCategory(int month, String categoryName) {
|
||||
StreamController<QuerySnapshot> controller;
|
||||
StreamSubscription sub;
|
||||
void emit() {
|
||||
final filtered = _demoExpenses
|
||||
.where((e) => e['month'] == month && e['category'] == categoryName)
|
||||
.map((e) => _DemoDocumentSnapshot(e['id'] as String, Map<String, dynamic>.from(e)))
|
||||
.toList();
|
||||
if (!controller.isClosed) {
|
||||
controller.add(_DemoQuerySnapshot(filtered));
|
||||
}
|
||||
}
|
||||
|
||||
controller = StreamController<QuerySnapshot>(
|
||||
onListen: () {
|
||||
emit();
|
||||
sub = _demoUpdateController.stream.listen((_) => emit());
|
||||
},
|
||||
onCancel: () {
|
||||
sub?.cancel();
|
||||
},
|
||||
);
|
||||
return controller.stream;
|
||||
}
|
||||
|
||||
Stream<QuerySnapshot> queryByCategory(int month, String categoryName) {
|
||||
if (userId == 'demo_reviewer') {
|
||||
return _demoQueryByCategory(month, categoryName);
|
||||
}
|
||||
return Firestore.instance
|
||||
.collection('users')
|
||||
.document(userId)
|
||||
@@ -21,6 +128,9 @@ class ExpensesRepository {
|
||||
}
|
||||
|
||||
Stream<QuerySnapshot> queryByMonth(int month) {
|
||||
if (userId == 'demo_reviewer') {
|
||||
return _demoQueryByMonth(month);
|
||||
}
|
||||
return Firestore.instance
|
||||
.collection('users')
|
||||
.document(userId)
|
||||
@@ -30,6 +140,11 @@ class ExpensesRepository {
|
||||
}
|
||||
|
||||
delete(String documentId) {
|
||||
if (userId == 'demo_reviewer') {
|
||||
_demoExpenses.removeWhere((e) => e['id'] == documentId);
|
||||
_demoUpdateController.add(_demoExpenses);
|
||||
return;
|
||||
}
|
||||
Firestore.instance
|
||||
.collection('users')
|
||||
.document(userId)
|
||||
@@ -39,6 +154,19 @@ class ExpensesRepository {
|
||||
}
|
||||
|
||||
add(String categoryName, double value, DateTime date, File selectedImage) async {
|
||||
if (userId == 'demo_reviewer') {
|
||||
_demoExpenses.add({
|
||||
"id": "demo-${DateTime.now().millisecondsSinceEpoch}",
|
||||
"category": categoryName,
|
||||
"value": value,
|
||||
"month": date.month,
|
||||
"day": date.day,
|
||||
"year": date.year,
|
||||
"imageUrl": null,
|
||||
});
|
||||
_demoUpdateController.add(_demoExpenses);
|
||||
return;
|
||||
}
|
||||
var document = Firestore.instance
|
||||
.collection('users')
|
||||
.document(userId)
|
||||
|
||||
Reference in New Issue
Block a user