我想将用户在我的应用中选择的照片发送到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中是否有任何压缩和调整照片大小的方法?我很好,质量下降.
根据这个:示例代码
我创建了自己的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) 我今天遇到了一个奇怪的问题.请看这段代码:
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?.为什么?
让我们假设我们有一个简单的泛型类:
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'的要求
谁能告诉我为什么?以及如何解决这个问题?
我在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) 我开始使用集成了 SPM 的新 Xcode 11。
我在我的项目中添加了第一个依赖项:
但检测到文件未提取到我的项目文件夹中,而是提取到 Xcode 的缓存中:
我想将我所有的依赖文件提交到我的主项目存储库中,所以我的问题是:
是否可以使用 Xcode 11 通过 SPM 更改获取的包的位置?
我在我的项目中设置了Firestore.我创建了名为的新集合categories.在这个集合中,我使用uniq id创建了三个文档.现在我想在我的Flutter应用程序中获取此集合,因此我创建了CollectionReference:
Firestore.instance.collection('categories')
Run Code Online (Sandbox Code Playgroud)
但我不知道接下来会发生什么.
我正在使用这个插件 firebase_firestore: 0.0.1+1
我在决定下载Xcode9之前.我想玩新的框架 - ARKit.我知道要用ARKit运行应用程序我需要一个带有A9芯片或更新版本的设备.不幸的是我有一个较旧的.我的问题是已经下载了新Xcode的人.在我的情况下有可能运行ARKit应用程序吗?那个或其他的任何模拟器?有什么想法或者我必须购买新设备吗?
我创建了 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) 我想使用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>'
我做错什么了?
ios ×7
swift ×4
dart ×3
flutter ×3
core-data ×2
firebase ×2
arkit ×1
generics ×1
ios10 ×1
nativescript ×1
swift4 ×1
tabcontrol ×1
typescript ×1
unit-testing ×1
xcode ×1
xcode11 ×1
xcode9 ×1