获取一个简单的应用程序以使用Cloud Firestore

时间:2018-04-05 19:31:59

标签: android dart google-cloud-firestore flutter

我正在关注网站https://pub.dartlang.org/packages/cloud_firestore#-readme-tab-中的示例。我在README.md中按照Android应用程序的所有说明进行操作。在Firebase控制台中创建Android应用,复制google-services.json并更新两个buidl.gradle文件,如下所示:

机器人/的build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        // Add this line
        // **********************************
        classpath 'com.google.gms:google-services:3.2.0'
        // **********************************
    }
}

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
}

机器人/应用/的build.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.")
}

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

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.fluttercloudfirestore"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        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 {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    // Add this line
    // **********************************
    compile 'com.google.firebase:firebase-core:12.0.0'
    // **********************************
}

// Add to the bottom of the file
// **********************************
apply plugin: 'com.google.gms.google-services'
// **********************************

还更新了我的pubspec.yaml

name: flutter_cloud_firestore
description: A new Flutter project.

dependencies:
  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.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  cloud_firestore: "^0.4.0"


# 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:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # 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

当我运行 flutter packages get 时,我收到以下错误:

在flutter_cloud_firestore中运行“ flutter packages get ”... 软件包cloud_firestore没有匹配> = 0.4.0< 0.5.0的版本派生自: - flutter_cloud_firestore取决于版本^ 0.4.0 酒吧失败(1)

根据this页面,0.4.0是当前版本。是什么给了什么?

1 个答案:

答案 0 :(得分:0)

通过软件包主页或pub软件包管理器的错误消息本身没有简单的方法可以告诉您这一点,但Flutter的{{{{{{{{{{{ {1}}频道(此帖子的默认设置),因此您必须切换到beta频道。

您可以使用dev命令更改您的发布频道。在这种情况下,如果您使用flutter channel设置为“{1}},则需要访问0.4.0频道:

dev

然后$ flutter channel dev $ flutter doctor // May not be strictly necessary, but a good check 应该正确获取包。