无法识别rxdart在颤动中的用法

时间:2018-08-17 16:25:25

标签: android dart flutter dart-pub flutter-dependencies

我正试图在 flutter 应用程序中首次使用 rxdart 软件包,并且已将该软件包添加到yaml文件中,然后我将其保存并保存为 vscode 之后,自动运行flutter程序包进入项目,我尝试通过以下行

导入该程序包
import 'package:rxdart/rxdart.dart';

,但是编译器无法识别软件包中的rxdart。这会导致应用程序中的错误。

  

以下是我对 pubspec.yaml

的依赖
dependencies:
  flutter:
    sdk: flutter


  cupertino_icons: ^0.1.2

  rxdart: ^0.18.0

dev_dependencies:
  flutter_test:
    sdk: flutter

更新

这是我正在从事的项目的仓库-> https://www.github.com/touseefbsb/LoginStateful

您必须打开文件夹login_stateful_bloc,并且错误在我尝试导入它的 bloc.dart 文件中。

1 个答案:

答案 0 :(得分:3)

您必须保留缩进量:

import Cocoa
import Alamofire

// Create my object via Struct
struct Package {
    var latency: Double?
    var name: String?
    var statuscode: Int?
    var download: Bool?
    var downloadUrl: String? 
}
// Download the package from the provided download url and return the object
func getPKG(pkgName: String, dpUrl: String, completion: @escaping (Package) -> (Package)) {
    let url = URL(string: "\(dpUrl)\(pkgName)")
    let parameters: Parameters = ["foo":"bar"]
    Alamofire.download(url, method: .get, parameters: parameters, encoding: JSONEncoding.default, to: destination)
        .downloadProgress(queue: DispatchQueue.global(qos: .utility)) { progress in
            debugPrint("Download Progress...: \(progress.fractionCompleted)")
        }
        .validate(statusCode: 200..<399)
        .response { response in
            debugPrint(response.response!)
            debugPrint(response.response!.statusCode)
            debugPrint(response.timeline.latency)
            let dlObject = Package(latency: response.timeline.latency, name: pkgName, statuscode: response.response?.statusCode, download: true, downloadUrl: dpUrl)
            completion(dlObject)
    }

}

var share_response = [String: Double]()
var package_sources: NSArray! = ["https://www.jss1.com/Share", "https://www.jss2.com/Share", "https://www.jss3.com/Share"]
let package_names: String = ["Dummy1.pkg", "Dummy2.pkg", "Dummy3.pkg"]
// Loop through the package sources and find the one with 
// the lowest latency.
for share_url in package_sources {
    getPKG(pkgName: "Dummy.pkg", dpUrl: share_url, completion: {
        dlObject in
        if dlObject.latency != nil {
            share_response[share_url] = dlObject.latency
        } else {
            debugPrint("nothing yet")
        }
        return dlObject
    })
}

let final_download_url = share_response.min { a, b in a.value < b.value }

//  Here is where it breaks and responds with nil

for package in package_names {
    let download_url = URL(string: final_download_url + package)
    Download commands here...
}