1+ import 'dart:typed_data' ;
2+
13import 'package:cloud_firestore/cloud_firestore.dart' ;
24import 'package:firebase_core/firebase_core.dart' ;
35import 'package:flutter/material.dart' ;
@@ -12,7 +14,6 @@ Future<void> main() async {
1214 WidgetsFlutterBinding .ensureInitialized ();
1315 await Firebase .initializeApp (options: DefaultFirebaseOptions .currentPlatform);
1416 if (shouldUseFirestoreEmulator) {
15- print ('Using Firestore emulator' );
1617 FirebaseFirestore .instance.useFirestoreEmulator ('localhost' , 8080 );
1718 }
1819 runApp (const PipelineExampleApp ());
@@ -66,7 +67,7 @@ class _PipelineExamplePageState extends State<PipelineExamplePage> {
6667
6768 try {
6869 final col = _firestore.collection (_collectionId);
69-
70+
7071 final batch = _firestore.batch ();
7172 _seedDocRefs = [];
7273
@@ -224,6 +225,22 @@ class _PipelineExamplePageState extends State<PipelineExamplePage> {
224225 .execute (),
225226 );
226227
228+ // 1b: execute with ExecuteOptions (indexMode: recommended)
229+ Future <void > _runPipelineExecuteOptions () => _runPipeline (
230+ 'Pipeline 1b: same as 1 but execute(options: ExecuteOptions(indexMode: recommended))' ,
231+ () => _firestore
232+ .pipeline ()
233+ .collection (_collectionId)
234+ .where (
235+ Expression .field ('score' ).greaterThan (Expression .constant (10 )))
236+ .limit (3 )
237+ .execute (
238+ options: const ExecuteOptions (
239+ indexMode: IndexMode .recommended,
240+ ),
241+ ),
242+ );
243+
227244 // 2: select
228245 Future <void > _runPipeline2 () => _runPipeline (
229246 'Pipeline 2: collection → where(year > 2022) → select(title, score, year) → limit(4)' ,
@@ -464,8 +481,8 @@ class _PipelineExamplePageState extends State<PipelineExamplePage> {
464481 Constant (const GeoPoint (37.7749 , - 122.4194 )).as ('c_geo_point' ),
465482 // List<int> (raw bytes)
466483 Constant (< int > [72 , 101 , 108 , 108 , 111 ]).as ('c_bytes' ),
467- // Blob
468- Constant (Blob (Uint8List .fromList ([1 , 2 , 3 , 4 , 5 ]))).as ('c_blob' ),
484+ // // Blob
485+ // Constant(Blob(Uint8List.fromList([1, 2, 3, 4, 5]))).as('c_blob'),
469486 // DocumentReference
470487 Constant (docRef).as ('c_doc_ref' ),
471488 )
@@ -521,7 +538,7 @@ class _PipelineExamplePageState extends State<PipelineExamplePage> {
521538 'Pipeline 21: collection → where(tags arrayContainsAny [x, z]) → select(title, tags) → limit(5)' ,
522539 () => _firestore
523540 .pipeline ()
524- .collection (_collectionId)
541+ .collection (_collectionId)
525542 .where (
526543 Expression .field ('tags' ).arrayContainsAny (['x' , 'z' ]),
527544 )
@@ -963,6 +980,7 @@ class _PipelineExamplePageState extends State<PipelineExamplePage> {
963980 runSpacing: 8 ,
964981 children: [
965982 _btn ('1: where+limit' , _runPipeline1),
983+ _btn ('1b: execute(options)' , _runPipelineExecuteOptions),
966984 _btn ('2: select' , _runPipeline2),
967985 _btn ('3: aggregate' , _runPipeline3),
968986 _btn ('4: addFields' , _runPipeline4),
@@ -1057,4 +1075,4 @@ class PipelineExamplePage extends StatefulWidget {
10571075
10581076 @override
10591077 State <PipelineExamplePage > createState () => _PipelineExamplePageState ();
1060- }
1078+ }
0 commit comments