Skip to content

Commit 5b9f667

Browse files
Initial commit
0 parents  commit 5b9f667

14 files changed

+913
-0
lines changed

.gitignore

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# Visual Studio Code related
19+
.vscode/
20+
21+
# Flutter/Dart/Pub related
22+
**/doc/api/
23+
.dart_tool/
24+
.flutter-plugins
25+
.packages
26+
.pub-cache/
27+
.pub/
28+
build/
29+
30+
# Android related
31+
**/android/**/gradle-wrapper.jar
32+
**/android/.gradle
33+
**/android/captures/
34+
**/android/gradlew
35+
**/android/gradlew.bat
36+
**/android/local.properties
37+
**/android/**/GeneratedPluginRegistrant.java
38+
39+
# iOS/XCode related
40+
**/ios/**/*.mode1v3
41+
**/ios/**/*.mode2v3
42+
**/ios/**/*.moved-aside
43+
**/ios/**/*.pbxuser
44+
**/ios/**/*.perspectivev3
45+
**/ios/**/*sync/
46+
**/ios/**/.sconsign.dblite
47+
**/ios/**/.tags*
48+
**/ios/**/.vagrant/
49+
**/ios/**/DerivedData/
50+
**/ios/**/Icon?
51+
**/ios/**/Pods/
52+
**/ios/**/.symlinks/
53+
**/ios/**/profile
54+
**/ios/**/xcuserdata
55+
**/ios/.generated/
56+
**/ios/Flutter/App.framework
57+
**/ios/Flutter/Flutter.framework
58+
**/ios/Flutter/Generated.xcconfig
59+
**/ios/Flutter/app.flx
60+
**/ios/Flutter/app.zip
61+
**/ios/Flutter/flutter_assets/
62+
**/ios/ServiceDefinitions.json
63+
**/ios/Runner/GeneratedPluginRegistrant.*
64+
65+
# Exceptions to above rules.
66+
!**/ios/**/default.mode1v3
67+
!**/ios/**/default.mode2v3
68+
!**/ios/**/default.pbxuser
69+
!**/ios/**/default.perspectivev3
70+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 8b0243f413294e5079a39c73a5812eb7ec1c9a93
8+
channel: master
9+
10+
project_type: package

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [0.0.1] - TODO: Add release date.
2+
3+
* TODO: Describe initial release.

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: Add your license here.

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# flutter_firestore_visual_query
2+
3+
A visual way to query your firestore database for testing
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Dart
8+
[package](https://flutter.dev/developing-packages/),
9+
a library module containing code that can be shared easily across
10+
multiple Flutter or Dart projects.
11+
12+
For help getting started with Flutter, view our
13+
[online documentation](https://flutter.dev/docs), which offers tutorials,
14+
samples, guidance on mobile development, and a full API reference.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
library flutter_firestore_visual_query;
2+
3+
export 'package:flutter_firestore_visual_query/src/firestore_query_widget.dart';

lib/src/bloc/bloc.dart

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export 'query_bloc.dart';
2+
export 'query_event.dart';
3+
export 'query_state.dart';

lib/src/bloc/query_bloc.dart

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'dart:async';
2+
3+
import 'package:bloc/bloc.dart';
4+
import 'package:cloud_firestore/cloud_firestore.dart';
5+
import 'package:flutter/foundation.dart';
6+
import 'package:flutter_firestore_visual_query/src/bloc/bloc.dart';
7+
8+
class QueryBloc extends Bloc<QueryEvent, QueryState> {
9+
final Firestore firestore;
10+
11+
QueryBloc({@required this.firestore});
12+
13+
@override
14+
QueryState get initialState => InitialQueryState();
15+
16+
@override
17+
Stream<QueryState> mapEventToState(
18+
QueryEvent event,
19+
) async* {
20+
if (event is NewQueryEvent) {
21+
var querySnapshot = await firestore
22+
.collection(event.collection)
23+
.where(event.field,
24+
isEqualTo: event.isEqualTo,
25+
isLessThan: event.isLessThan,
26+
isLessThanOrEqualTo: event.isLessThanOrEqualTo,
27+
isGreaterThan: event.isGreaterThan,
28+
isGreaterThanOrEqualTo: event.isGreaterThanOrEqualTo,
29+
arrayContains: event.arrayContains,
30+
isNull: event.isNull)
31+
.getDocuments();
32+
List<DocumentSnapshot> documents = querySnapshot.documents;
33+
34+
yield QueryResult(results: documents);
35+
}
36+
yield this.currentState;
37+
}
38+
}
39+
40+
class LoggingDelegate extends BlocDelegate {
41+
@override
42+
void onTransition(Bloc bloc, Transition transition) {
43+
super.onTransition(bloc, transition);
44+
debugPrintSynchronously("Event: ${transition.event}\n"
45+
"${transition.nextState}");
46+
}
47+
}

lib/src/bloc/query_event.dart

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:meta/meta.dart';
2+
3+
@immutable
4+
abstract class QueryEvent {}
5+
6+
class NewQueryEvent extends QueryEvent {
7+
final String collection;
8+
final String field;
9+
final dynamic isEqualTo;
10+
final dynamic isLessThan;
11+
final dynamic isLessThanOrEqualTo;
12+
final dynamic isGreaterThan;
13+
final dynamic isGreaterThanOrEqualTo;
14+
final dynamic arrayContains;
15+
final bool isNull;
16+
17+
NewQueryEvent({
18+
this.collection,
19+
this.field,
20+
this.isEqualTo,
21+
this.isLessThan,
22+
this.isLessThanOrEqualTo,
23+
this.isGreaterThan,
24+
this.isGreaterThanOrEqualTo,
25+
this.arrayContains,
26+
this.isNull,
27+
}) {
28+
assert(
29+
[
30+
this.isEqualTo,
31+
this.isLessThan,
32+
this.isLessThanOrEqualTo,
33+
this.isGreaterThan,
34+
this.isGreaterThanOrEqualTo,
35+
this.arrayContains,
36+
this.isNull
37+
].where((element) => element != null).length ==
38+
1,
39+
"only one of these can be selected for any given query."
40+
"isEqualTo: $isEqualTo,"
41+
"isLessThan: $isLessThan,"
42+
"isLessThanOrEqualTo: $isLessThanOrEqualTo,"
43+
"isGreaterThan: $isGreaterThan,"
44+
"isGreaterThanOrEqualTo: $isGreaterThanOrEqualTo,"
45+
"arrayContains: $arrayContains,"
46+
"isNull: $isNull");
47+
}
48+
}

lib/src/bloc/query_state.dart

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:cloud_firestore/cloud_firestore.dart';
2+
import 'package:flutter/widgets.dart';
3+
import 'package:meta/meta.dart';
4+
5+
@immutable
6+
abstract class QueryState {
7+
final List<DocumentSnapshot> results;
8+
9+
QueryState({@required this.results});
10+
}
11+
12+
class InitialQueryState extends QueryState {
13+
InitialQueryState() : super(results: []);
14+
}
15+
16+
class QueryResult extends QueryState {
17+
QueryResult({@required results}) : super(results: results);
18+
}

lib/src/enums.dart

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class WhereCondition {
2+
static const String isEqualTo = "isEqualTo";
3+
static const String isLessThan = "isLessThan";
4+
static const String isLessThanOrEqualTo = "isLessThanOrEqualTo";
5+
static const String isGreaterThan = "isGreaterThan";
6+
static const String isGreaterThanOrEqualTo = "isGreaterThanOrEqualTo";
7+
static const String arrayContains = "arrayContains";
8+
static const String isNull = "isNull";
9+
10+
static const List<String> values = [
11+
isEqualTo,
12+
isLessThan,
13+
isLessThanOrEqualTo,
14+
isGreaterThan,
15+
isGreaterThanOrEqualTo,
16+
arrayContains,
17+
isNull
18+
];
19+
}
20+
21+
class Types {
22+
static const String string = "string";
23+
static const String number = "number";
24+
static const String boolean = "boolean";
25+
26+
static const List<String> values = [string, number, boolean];
27+
}

0 commit comments

Comments
 (0)