не могу отправить в облачный пожарный магазин - PullRequest
0 голосов
/ 17 февраля 2019

Я пытаюсь использовать Firebase Cloud Firestore в моем проекте флаттера

Я хочу отправить имя пользователя таким способом

final DocumentReference reference = Firestore.instance.collection('users').document('info');
@override
  void initState() {
    reference.setData({'name':widget.username});
    super.initState();
  }

, но у меня всегда возникает эта проблема

это потому, что я что-то забыл или мой код верен?Окно запуска:

[ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (19131): PlatformException(error, Firestore component is not present., null)
E/flutter (19131): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7)
E/flutter (19131): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
E/flutter (19131): <asynchronous suspension>
E/flutter (19131): #2      DocumentReference.setData (file:///C:/Users/Khaled/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0+2/lib/src/document_reference.dart:46:30)
E/flutter (19131): #3      _Mainpage.initState (package:family_store/mainpage/mainpage.dart:25:15)
E/flutter (19131): #4      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3830:58)
E/flutter (19131): #5      ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (19131): #6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #7      Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #8      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
E/flutter (19131): #9      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #10     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #11     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (19131): #12     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (19131): #13     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
E/flutter (19131): #14     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (19131): #15     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #16     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #17     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
E/flutter (19131): #18     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #19     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #20     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
E/flutter (19131): #21     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #23     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
E/flutter (19131): #24     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #25     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #26     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
E/flutter (19131): #27     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #28     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #29     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (19131): #30     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (19131): #31     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
E/flutter (19131): #32     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
E/flutter (19131): #33     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (19131): #34     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #35     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #36     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (19131): #37     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (19131): #38     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
E/flutter (19131): #39     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
E/flutter (19131): #40     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
E/flutter (19131): #41     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
E/flutter (19131): #42     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
E/flutter (19131): #43     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
E/flutter (19131): #44     ComponentElement._fir`

Окно Logcat:

2019-02-17 19:26:09.995 26233-26233/kbaq.familystore E/MethodChannel#plugins.flutter.io/cloud_firestore: Failed to handle method call
    java.lang.NullPointerException: Firestore component is not present.
        at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787)
        at com.google.firebase.firestore.FirebaseFirestore.zza(com.google.firebase:firebase-firestore@@17.1.1:86)
        at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.1:78)
        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getFirestore(CloudFirestorePlugin.java:82)
        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.getDocumentReference(CloudFirestorePlugin.java:92)
        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.onMethodCall(CloudFirestorePlugin.java:512)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
        at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:325)
        at android.os.Looper.loop(Looper.java:142)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
2019-02-17 19:26:10.579 4651-4651/? D/io_stats: !@   8,0 r 10125543 434553904 w 8205894 179383648 d 838308 76817324 f 2264196 2262971 iot 16398040 14934520 th 392016 0 0 pt 0 inp 0 0 740999.148
2019-02-17 19:26:10.652 26233-26345/kbaq.familystore E/flutter: [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
    PlatformException(error, Firestore component is not present., null)
    #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7)
    #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
    <asynchronous suspension>
    #2      DocumentReference.setData (file:///C:/Users/Khaled/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.0+2/lib/src/document_reference.dart:46:30)
    #3      _Mainpage.initState (package:family_store/mainpage/mainpage.dart:25:15)
    #4      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3830:58)
    #5      ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
    #6      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #7      Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #8      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
    #9      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #10     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #11     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
    #12     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
    #13     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
    #14     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
    #15     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #16     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #17     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
    #18     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #19     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #20     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
    #21     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #23     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
    #24     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #25     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #26     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
    #27     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #28     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #29     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
    #30     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
    #31     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
    #32     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
    #33     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
    #34     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #35     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #36     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
    #37     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
    #38     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
    #39     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
    #40     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
    #41     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
    #42     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
    #43     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
    #44     ComponentElement._fir

pubspec.yaml

name: family_store
description: family store

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

dependencies:
  cloud_firestore: ^0.9.0+2
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  firebase_auth: ^0.8.1
  google_sign_in: ^4.0.1
  shared_preferences: ^0.5.1+1


dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/Coffee.jpg
    - assets/Food.png
    - assets/Juices.jpg
    - assets/Sweets.jpg
    - assets/textback.png
    - assets/Divider.png
    - assets/Icon.png
    - assets/sectionback.png
    - btn_gplus.png
    - btn_mobile.png

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.io/custom-fonts/#from-packages

app/gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "kbaq.familystore"
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.firebase:firebase-core:16.0.7'
}
apply plugin: 'com.google.gms.google-services'

android/gradle

buildscript {
    ext.kotlin_version = '1.3.0'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath ('com.google.gms:google-services:4.2.0') {
            exclude group: 'com.google.guava', module: 'guava-jdk5'
        }

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.google.gms.google-services'

Я попробовал это посвящение, которое minshond здесь Flutter: компонент Firestore отсутствует

, но не работал

Ответы [ 3 ]

0 голосов
/ 19 февраля 2019

Вы можете сделать функцию как myFunc () {} и установить данные облака в этой функции.После этого вызовите функцию в initstate () {}.

 final DocumentReference reference = Firestore.instance.collection('users').document('info');

      _myFunc() async {
        reference.setData({'name':_userName.text}).whenComplete((){
          print('Data updated in Cloud.');
        });
      }

void initState() {
    _myFunc();
    super.initState();
}
0 голосов
/ 24 февраля 2019

У меня возникла эта проблема, но в моем случае я не указал версию cloud_firestore.Вместо этого я оставил поле пустым «cloud_firestore:», как объяснено в Официальном флаттере videos .Однако, если вы не укажете номер версии, похоже, что загружена самая последняя.Тем не менее, похоже, что последняя версия не совместима с AndroidX и не работает понижение версии.

Я решил эту проблему, создав новый проект Flutter в Android Studio и включив совместимость с Kotlin и Swift на начальном экране конфигурации проекта.

Затем в pubspec.yaml я набрал следующий код:

dependencies:

  firebase_core: 0.2.5+1
  cloud_firestore: 0.8.2+3

Более того, похоже, что ваш pubspec.yaml не имеет зависимости firebase_core.

Это сборка для моего приложения:

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.organization.app"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}
//The following line must be placed at the end of the file
apply plugin: 'com.google.gms.google-services'

И это сборка для моего проекта:

buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Я понимаю, что это решение может быть не самым эффективным.Специально, учитывая, что вам, возможно, придется создать новый проект Flutter.Тем не менее, как только новый проект будет создан, как упоминалось выше, вы можете скопировать свои старые файлы дротиков Flutter в новый.

Надеюсь, это поможет вам.

0 голосов
/ 19 февраля 2019

Вы пытались понизить зависимость cloud_firestore?Я видел пару сообщений на эту тему совсем недавно, все из которых используют cloud_firestore 9.0 + 2.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...