小编Kam*_*icz的帖子

Flutter&Firebase:上传图片前的压缩

我想将用户在我的应用中选择的照片发送到Firebase存储.我有一个简单的类属性_imageFile,其设置如下:

File _imageFile;

_getImage() async {
    var fileName = await ImagePicker.pickImage();
    setState(() {
        _imageFile = fileName;
    });
}
Run Code Online (Sandbox Code Playgroud)

之后,我发送照片与此代码:

final String rand1 = "${new Random().nextInt(10000)}";
final String rand2 = "${new Random().nextInt(10000)}";
final String rand3 = "${new Random().nextInt(10000)}";
final StorageReference ref = FirebaseStorage.instance.ref().child('${rand1}_${rand2}_${rand3}.jpg');
final StorageUploadTask uploadTask = ref.put(_imageFile);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
print(downloadUrl);
Run Code Online (Sandbox Code Playgroud)

问题是照片通常非常大.在上传之前,Flutter/Dart中是否有任何压缩和调整照片大小的方法?我很好,质量下降.

dart firebase flutter firebase-storage

18
推荐指数
4
解决办法
1万
查看次数

TabController构造函数中的`vsync`属性

根据这个:示例代码

我创建了自己的TabController实现:

void main() {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {

  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: choices.length);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        bottomNavigationBar: new Material(
          color: Colors.blue,
          child: new TabBar(
            controller: _tabController,
            isScrollable: false,
            tabs: choices.map((Choice choice) {
              return new Tab(
                text: null, …
Run Code Online (Sandbox Code Playgroud)

tabcontrol dart flutter

14
推荐指数
7
解决办法
7203
查看次数

为什么Swift4会抛出一组UIButton!到[UIButton?]类型?

我今天遇到了一个奇怪的问题.请看这段代码:

class A {

    var button1: UIButton!
    var button2: UIButton!

    func foo() {
        let array = [button1, button2]
    }
}
Run Code Online (Sandbox Code Playgroud)

Xcode说这array[UIButton?]类型.出于某种原因,Swift4将UIButton!元素转换为UIButton?.为什么?

ios swift swift4

14
推荐指数
2
解决办法
834
查看次数

在Swift4中扩展泛型类

让我们假设我们有一个简单的泛型类:

class Foo<T> {

}
Run Code Online (Sandbox Code Playgroud)

接下来添加到这个extension实现的类UITableViewDatasoure:

extension Foo: UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        //Code here
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //Code here
    }
}
Run Code Online (Sandbox Code Playgroud)

此结构导致编译器错误消息:

从泛型类Non-'@ objc'方法继承的泛型类或类的扩展中不支持@objc

'tableView(_:numberOfRowsInSection :)'不满足'@objc'协议'UITableViewDataSource'的要求

谁能告诉我为什么?以及如何解决这个问题?

generics ios swift

13
推荐指数
1
解决办法
3839
查看次数

NativeScript TextField [(ngModel)]不起作用

我在TextField中遇到数据绑定问题 ngModel

我有模特课

export class Product {
    name: string
    description: string
    imageUrl: string
}
Run Code Online (Sandbox Code Playgroud)

视图:

<GridLayout backgroundColor="red">
    <!--
    This part is for logged users
    -->
    <StackLayout
        [id]="container"
        [visibility]="isLogged ? 'visible' : 'collapse'">
            <Label text="Add product" textWrap="true"></Label>
            <TextField
                hint="product name"
                [(ngModel)]="product.name">
            </TextField>
            <TextField
                hint="product desc"
                [(ngModel)]="product.description">
            </TextField>
            <Button text="Zrób zdj?cie produktu" (tap)="didTapTakePhoto()">
            </Button>
            <Button text="Wy?lij na serwer" (tap)="didTapSendProduct()">
            </Button>
            <Image #photo></Image>
    </StackLayout>

    <!--
    This part is for not logged users
    -->
    <StackLayout [visibility]="isLogged ? 'collapse' : 'visible'">
        <Label text="Musisz si? zalogowa?!" …
Run Code Online (Sandbox Code Playgroud)

ios typescript nativescript

9
推荐指数
1
解决办法
2841
查看次数

使用 Xcode 11 将 SPM 下载的包保存到项目 GIT 中

我开始使用集成了 SPM 的新 Xcode 11。

我在我的项目中添加了第一个依赖项:

在此处输入图片说明

但检测到文件未提取到我的项目文件夹中,而是提取到 Xcode 的缓存中:

在此处输入图片说明

我想将我所有的依赖文件提交到我的主项目存储库中,所以我的问题是:

是否可以使用 Xcode 11 通过 SPM 更改获取的包的位置?

ios swift-package-manager xcode11

9
推荐指数
1
解决办法
1201
查看次数

从Flutter的Firestore集合中获取所有内容

我在我的项目中设置了Firestore.我创建了名为的新集合categories.在这个集合中,我使用uniq id创建了三个文档.现在我想在我的Flutter应用程序中获取此集合,因此我创建了CollectionReference:

Firestore.instance.collection('categories')
Run Code Online (Sandbox Code Playgroud)

但我不知道接下来会发生什么.

我正在使用这个插件 firebase_firestore: 0.0.1+1

dart firebase flutter google-cloud-firestore

8
推荐指数
7
解决办法
1万
查看次数

在没有iPhone6s或更新版本的情况下测试ARKit

我在决定下载Xcode9之前.我想玩新的框架 - ARKit.我知道要用ARKit运行应用程序我需要一个带有A9芯片或更新版本的设备.不幸的是我有一个较旧的.我的问题是已经下载了新Xcode的人.在我的情况下有可能运行ARKit应用程序吗?那个或其他的任何模拟器?有什么想法或者我必须购买新设备吗?

xcode ios arkit xcode9

7
推荐指数
2
解决办法
2841
查看次数

NSInMemoryStoreType 类型的核心数据忽略实体的约束

我创建了 CoreData 堆栈的模拟版本

import Foundation
import CoreData

@testable import Companion

final class MockedDatabaseStackController: DatabaseStackControllerProtocol {

    let batchRequestsAvailable: Bool = false

    private lazy var managedObjectModel = NSManagedObjectModel.mergedModel(from: [Bundle(for: type(of: self))])!

    lazy var persistentContainer: NSPersistentContainer = {
        let description = NSPersistentStoreDescription()
        description.type = NSInMemoryStoreType
        description.shouldAddStoreAsynchronously = false

        let container = NSPersistentContainer(
            name: "database",
            managedObjectModel: managedObjectModel
        )
        container.persistentStoreDescriptions = [description]
        container.loadPersistentStores { description, error in
            // Check if the data store is in memory
            precondition( description.type == NSInMemoryStoreType )

            // Check if creating …
Run Code Online (Sandbox Code Playgroud)

unit-testing core-data ios swift

7
推荐指数
1
解决办法
398
查看次数

无法将类型“ NSFetchRequest &lt;NSFetchRequestResult&gt;”的值转换为指定的类型“ NSFetchRequest &lt;T&gt;”

我想使用iOS10中引入的新Core Data API。

@available(iOS 10.0, *)
open class func fetchRequest() -> NSFetchRequest<NSFetchRequestResult>
Run Code Online (Sandbox Code Playgroud)

我创建了通用函数来获取各种对象:

func getAllEntities<T: NSManagedObject>(ofType type: T.Type, success: @escaping ([T]) -> ()) throws -> [T] {
    let fetchRequest: NSFetchRequest<T> = T.fetchRequest()
    let asyncFetchRequest = NSAsynchronousFetchResult(fetchRequest: fetchRequest) { result in
        success(result.finalResult ?? [])
    }

    try databaseStack.persistentContainer.viewContext.execute(asyncFetchRequest)
}
Run Code Online (Sandbox Code Playgroud)

但是let fetchRequest: NSFetchRequest<T> = T.fetchRequest()我遇到了问题:

无法将类型的值转换'NSFetchRequest<NSFetchRequestResult>'为指定的类型'NSFetchRequest<T>'

我做错什么了?

core-data ios swift ios10

5
推荐指数
1
解决办法
1158
查看次数