Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erro codigo flutter #947

Open
heitortorrezani opened this issue Mar 26, 2024 · 1 comment
Open

erro codigo flutter #947

heitortorrezani opened this issue Mar 26, 2024 · 1 comment
Labels
new New issue request attention question Questions about using some feature or general working of the package

Comments

@heitortorrezani
Copy link

Ola estou programando em flutter ja tem um tempinha e estou com um problema esta dando este erro
══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
js_primitives.dart:30 The following StateError was thrown while handling a gesture:
js_primitives.dart:30 Bad state: field "voto" does not exist within the DocumentSnapshotPlatform
js_primitives.dart:30
js_primitives.dart:30 When the exception was thrown, this was the stack:
js_primitives.dart:30 dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 297:3 throw
js_primitives.dart:30 packages/cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart 92:7 _findKeyValueInMap
js_primitives.dart:30 packages/cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart 110:23 _findComponent
js_primitives.dart:30 packages/cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart 126:12 get
js_primitives.dart:30 packages/cloud_firestore/src/document_snapshot.dart 92:48 get
js_primitives.dart:30 packages/cloud_firestore/src/document_snapshot.dart 96:40 _get
js_primitives.dart:30 packages/embrasa2/pages/homePage.dart 114:68
js_primitives.dart:30 packages/flutter/src/material/ink_well.dart 1183:21 handleTap
js_primitives.dart:30 packages/flutter/src/gestures/recognizer.dart 315:24 invokeCallback
js_primitives.dart:30 packages/flutter/src/gestures/tap.dart 652:11 handleTapUp
js_primitives.dart:30 packages/flutter/src/gestures/tap.dart 309:5 [_checkUp]
js_primitives.dart:30 packages/flutter/src/gestures/tap.dart 242:7 handlePrimaryPointer
js_primitives.dart:30 packages/flutter/src/gestures/recognizer.dart 670:9 handleEvent
js_primitives.dart:30 packages/flutter/src/gestures/pointer_router.dart 98:7 [_dispatch]
js_primitives.dart:30 packages/flutter/src/gestures/pointer_router.dart 143:9
js_primitives.dart:30 dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:7 forEach
js_primitives.dart:30 packages/flutter/src/gestures/pointer_router.dart 141:17 [_dispatchEventToRoutes]
js_primitives.dart:30 packages/flutter/src/gestures/pointer_router.dart 127:7 route
js_primitives.dart:30 packages/flutter/src/gestures/binding.dart 495:5 handleEvent
js_primitives.dart:30 packages/flutter/src/gestures/binding.dart 475:14 dispatchEvent
js_primitives.dart:30 packages/flutter/src/rendering/binding.dart 430:11 dispatchEvent
js_primitives.dart:30 packages/flutter/src/gestures/binding.dart 420:7 [_handlePointerEventImmediately]
js_primitives.dart:30 packages/flutter/src/gestures/binding.dart 383:5 handlePointerEvent
js_primitives.dart:30 packages/flutter/src/gestures/binding.dart 330:7 [_flushPointerEventQueue]
js_primitives.dart:30 packages/flutter/src/gestures/binding.dart 299:9 [_handlePointerDataPacket]
js_primitives.dart:30 lib/_engine/engine/platform_dispatcher.dart 1361:5 invoke1
js_primitives.dart:30 lib/_engine/engine/platform_dispatcher.dart 286:5 invokeOnPointerDataPacket
js_primitives.dart:30 lib/_engine/engine/pointer_binding.dart 398:30 [_sendToFramework]
js_primitives.dart:30 lib/_engine/engine/pointer_binding.dart 224:7 onPointerData
js_primitives.dart:30 lib/_engine/engine/pointer_binding.dart 1001:20
js_primitives.dart:30 lib/_engine/engine/pointer_binding.dart 930:7
js_primitives.dart:30 lib/_engine/engine/pointer_binding.dart 531:9 loggedHandler
js_primitives.dart:30 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 550:37 _checkAndCall
js_primitives.dart:30 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 555:39 dcall
js_primitives.dart:30
js_primitives.dart:30 Handler: "onTap"
js_primitives.dart:30 Recognizer:
js_primitives.dart:30 TapGestureRecognizer#fe4b2
js_primitives.dart:30 ════════════════════════════════════════════════════════════════════════════════════════════════════

o trecho do codigo q esta dando erro e

StreamBuilder(
stream: FirebaseFirestore.instance.collection('nomes').snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasError) {
return Text('Erro ao carregar os nomes');
}

                                  if (snapshot.connectionState == ConnectionState.waiting) {
                                    return CircularProgressIndicator();
                                  }

                                  // Exibir os nomes salvos
                                  final List<QueryDocumentSnapshot> documents = snapshot.data!.docs;
                                  return Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: documents
                                        .map((QueryDocumentSnapshot document)  => ElevatedButton(
                                          onPressed: (){
                                            int voto = document['voto'];
                                            getVoto(
                                              voto+1,
                                              document['nome']
                                            );
                                            Navigator.of(context).pushNamed('/votos');
                                          },
                                          child: Text(document['nome']))
                                        ).toList(),
                                  );
                                },
                              ),

e caso presise da funcao getVoto()
Future getVoto( int voto, String name) async {
try {
await FirebaseFirestore.instance
.collection('votos') // Substitua 'nomes' pelo nome da sua coleção no Firestore
.add(
{
'voto': voto,
'nome': name
},
);
print('Nome salvo com sucesso no Firestore!');
} catch (e) {
print('Erro ao salvar nome no Firestore: $e');
}
}

@heitortorrezani heitortorrezani added new New issue request attention question Questions about using some feature or general working of the package labels Mar 26, 2024
@edugemini
Copy link
Contributor

int voto = document.data()['voto'];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new New issue request attention question Questions about using some feature or general working of the package
Projects
None yet
Development

No branches or pull requests

2 participants