0

They're trying to get the fix and their positions from flutter but what I get is a string with all the data and not with their positions, i'm using BLoC

Firebase: As you can see in firebase I have a data array enter image description here

cloud_firestore_api.dart:

 Future<QuerySnapshot> getCites() async {
return await _db
    .collection('type_cites').getDocuments();
 }

cloud_firestore_repository.dart:

 Future<QuerySnapshot>getCites() => _cloudfireStoreAPI.getCites();

user_bloc.dart:

Future<QuerySnapshot>getCites()=> _cloudFirestoreRepository.getCites();

and here's where I send to call my function and what I get instead of an array is a string:

 import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:generic_bloc_provider/generic_bloc_provider.dart';
import 'package:/User/bloc/userbloc.dart';

class DatePickerScreen extends StatefulWidget {
  UserBloc userBloc;
  QuerySnapshot snapshot;

  @override
  State<StatefulWidget> createState() {
    return _DatePickerScreen();
  }
}

class _DatePickerScreen extends State<DatePickerScreen> {

  @override
  Widget build(BuildContext context) {
    widget.userBloc = BlocProvider.of<UserBloc>(context);
    widget.userBloc.getCites().then((result) {
      widget.snapshot = result;
      
    });
    return  RaisedButton(
          onPressed: () {
            print( widget.snapshot.documents[0].data);
          },
        );
     
   
  }
}

output:

enter image description here

and if I print the size of what it brings:

enter image description here

when I actually have it in an arrangement that has 3 positions and its size devernial of being 3 and not 1, Any way to get the fix right from firebase?

0

1 Answer 1

5

Use following to print length of cites.

var documents =
    (await Firestore.instance.collection('collection').getDocuments())
        .documents;
print(documents[0].data['cites'].length);

Replace collection with your collection's name.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks so much, I thought I was doing something wrong with my request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.