firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.71k stars 3.98k forks source link

🐛 [cloud_firestore_web] GeoPoint used with FieldValue.arrayUnion throws conversion error on web #4572

Closed ankitmundada closed 3 years ago

ankitmundada commented 3 years ago

Bug report

Describe the bug Whenever there's a GeoPoint in the fieldvalue.arrayUnion update (I tested only with arrayunion), the plugin throws error and does not update the document

Steps to reproduce

Steps to reproduce the behavior:

1.

    Map<String, dynamic> _updateData = {
      'test': FieldValue.arrayUnion([GeoPoint(0, 0)])
    }
    _documentRef.update(_updateData);
  1. See error below
    
    [cloud_firestore/unknown] Invalid argument (dartObject): Could not convert: Instance of 'NativeJavaScriptObject'
    dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 216:49  throw_
    packages/cloud_firestore_web/src/document_reference_web.dart 45:7             update
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
    dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:12           _async
    packages/cloud_firestore_web/src/document_reference_web.dart 41:22            update
    packages/cloud_firestore/src/document_reference.dart 98:22                    update

### Expected behavior
The document should be updated

---

### Flutter doctor

Run `flutter doctor` and paste the output below:

<details><summary></summary>

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, 1.25.0-8.1.pre, on Linux, locale en_IN) [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3) [✓] Chrome - develop for the web [✓] Android Studio (version 4.0) [✓] Connected device (1 available)

• No issues found!



</details>

---
markusaksli-nc commented 3 years ago

Reproducible on the latest master 1.26.0-2.0.pre.200 only on web with cloud_firestore: ^0.14.4 with

  <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>
flutter doctor -v ``` [√] Flutter (Channel master, 1.26.0-2.0.pre.200, on Microsoft Windows [Version 10.0.19041.685], locale et-EE) • Flutter version 1.26.0-2.0.pre.200 at C:\Development\flutter_master • Framework revision d0e9959a46 (5 hours ago), 2021-01-05 22:14:03 -0500 • Engine revision e115066dcd • Dart version 2.12.0 (build 2.12.0-179.0.dev) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at C:\Users\marku\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.2 • Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community • Visual Studio Community 2019 version 16.7.30621.155 • Windows 10 SDK version 10.0.18362.0 [√] Android Studio (version 4.1.0) • Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [√] Connected device (4 available) • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19041.685] • Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88 • Edge (web) • edge • web-javascript • Microsoft Edge 87.0.664.66 • No issues found! ```
Minimal reproducible code sample ```dart import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); FirebaseApp app = await Firebase.initializeApp(); assert(app != null); runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Material App', theme: ThemeData.dark(), home: Home(), ); } } class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Firestore Example'), ), body: Center( child: Column( children: [ RaisedButton( child: const Text('Set'), onPressed: () { FirebaseFirestore.instance.doc('test/geo').set({'test': [GeoPoint(0,0)]}); }, ), RaisedButton( child: const Text('Update'), onPressed: () { FirebaseFirestore.instance.doc('test/geo').update({'test': FieldValue.arrayUnion([GeoPoint(1,1)])}); }, ), ], ), ), ); } } ```
Logs ``` Error: [cloud_firestore/unknown] Invalid argument (dartObject): Could not convert: Instance of 'NativeJavaScriptObject' at Object.throw_ [as throw] (http://localhost:58187/dart_sdk.js:5296:11) at document_reference_web.DocumentReferenceWeb.new.update (http://localhost:58187/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:631:21) at update.next () at runBody (http://localhost:58187/dart_sdk.js:38581:34) at Object._async [as async] (http://localhost:58187/dart_sdk.js:38612:7) at document_reference_web.DocumentReferenceWeb.new.update (http://localhost:58187/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:626:20) at cloud_firestore.DocumentReference.__.update (http://localhost:58187/packages/cloud_firestore/cloud_firestore.dart.lib.js:631:32) at http://localhost:58187/packages/triage/main.dart.lib.js:445:78 at ink_well._InkResponseState.new.[_handleTap] (http://localhost:58187/packages/flutter/src/material/icon_button.dart.lib.js:49767:42) at tap.TapGestureRecognizer.new.invokeCallback (http://localhost:58187/packages/flutter/src/gestures/recognizer.dart.lib.js:197:18) at tap.TapGestureRecognizer.new.handleTapUp (http://localhost:58187/packages/flutter/src/gestures/tap.dart.lib.js:405:40) at tap.TapGestureRecognizer.new.[_checkUp] (http://localhost:58187/packages/flutter/src/gestures/tap.dart.lib.js:211:12) at tap.TapGestureRecognizer.new.handlePrimaryPointer (http://localhost:58187/packages/flutter/src/gestures/tap.dart.lib.js:158:23) at tap.TapGestureRecognizer.new.handleEvent (http://localhost:58187/packages/flutter/src/gestures/recognizer.dart.lib.js:452:16) at pointer_router.PointerRouter.new.[_dispatch] (http://localhost:58187/packages/flutter/src/gestures/pointer_router.dart.lib.js:97:9) at http://localhost:58187/packages/flutter/src/gestures/pointer_router.dart.lib.js:132:26 at LinkedMap.new.forEach (http://localhost:58187/dart_sdk.js:25715:11) at pointer_router.PointerRouter.new.[_dispatchEventToRoutes] (http://localhost:58187/packages/flutter/src/gestures/pointer_router.dart.lib.js:129:29) at pointer_router.PointerRouter.new.route (http://localhost:58187/packages/flutter/src/gestures/pointer_router.dart.lib.js:121:37) at binding$5.WidgetsFlutterBinding.new.handleEvent (http://localhost:58187/packages/flutter/src/gestures/binding.dart.lib.js:325:26) at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:58187/packages/flutter/src/gestures/binding.dart.lib.js:308:24) at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:58187/packages/flutter/src/rendering/layer.dart.lib.js:6035:13) at binding$5.WidgetsFlutterBinding.new.[_handlePointerEventImmediately] (http://localhost:58187/packages/flutter/src/gestures/binding.dart.lib.js:279:14) at binding$5.WidgetsFlutterBinding.new.handlePointerEvent (http://localhost:58187/packages/flutter/src/gestures/binding.dart.lib.js:252:43) at binding$5.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (http://localhost:58187/packages/flutter/src/gestures/binding.dart.lib.js:241:14) at binding$5.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (http://localhost:58187/packages/flutter/src/gestures/binding.dart.lib.js:231:65) at Object.invoke1 (http://localhost:58187/dart_sdk.js:181597:7) at _engine.EnginePlatformDispatcher.__.invokeOnPointerDataPacket (http://localhost:58187/dart_sdk.js:162676:15) at _engine.PointerBinding.__.[_onPointerData] (http://localhost:58187/dart_sdk.js:163310:49) at http://localhost:58187/dart_sdk.js:163762:26 at http://localhost:58187/dart_sdk.js:163715:16 at http://localhost:58187/dart_sdk.js:163414:11 ```
russellwheatley commented 3 years ago

This has been fixed now:

Screenshot 2021-05-25 at 12 53 19