在我的应用程序正常之前,我尝试使用图像路径上传图像。当我尝试添加 import 'package: path / path.dart'; 和 basename (image.path) 为了上传我的图像,我的对话框警报中出现了一个新错误。上下文中的更多细节:上下文。这是我的代码:
import 'package:path/path.dart';
Future uploadFile() async {
final FirebaseUser user = await FirebaseAuth.instance.currentUser();
final userId = user.uid;
_imageList.forEach((_image) {
final StorageReference firebaseStorageRef = FirebaseStorage.instance
.ref()
.child('category')
.child('food')
.child('images')
.child(username)
.child(basename(_image.path));
final StorageUploadTask task = firebaseStorageRef.putFile(_image);
return task;
});
}
Run Code Online (Sandbox Code Playgroud)
以及出现错误的以下代码:
Future<void> alertSuccess() async {
return showDialog<void>(
/*this error*/
context: context,
/*------------*/
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Success'),
content: SingleChildScrollView(
child: ListBody(
children: …Run Code Online (Sandbox Code Playgroud) 我需要帮助伙计们。我有 2 个 dart 文件:main.dart 和 alertform.dart。有些情况需要在我的应用程序中使用这种方法。我想尝试在 main.dart 上的按钮上从 alertform.dart 访问 alerdialog。那可能吗?这是我的代码:
main.dart
import 'package:flutter/material.dart';
import 'alertform.dart';
class MainPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: new Text('Test'),
),
body: new Column(
children: <Widget>[
RaisedButton(
child: new Text('Show Alert'),
onPressed: (){
CommentForm();
},
)
],
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
alertform.dart
import 'package:flutter/material.dart';
class AlertForm extends StatefulWidget {
@override
_AlertFormState createState() => _AlertFormState();
}
class _AlertFormState extends State<AlertForm> {
void _showDialog() {
// flutter defined …Run Code Online (Sandbox Code Playgroud) 我想计算一个集合中有多少文档,而不是文档的长度。我已经用一些代码尝试过,但出现的是我的文档名称中字符的长度。
这是我的代码:
StreamSubscription<DocumentSnapshot> userpost;
final DocumentReference documentReference =
Firestore.instance.document("product/$documentPost");
userpost = documentReference.snapshots().listen((datasnapshot) {
if (datasnapshot.exists) {
for (int i = 0; i < datasnapshot.data.length; i++){
print(datasnapshot.data.length);
}
Run Code Online (Sandbox Code Playgroud) 我是新手。我尝试使应用程序使用颤振上传一些图像。我已经成功地从图像选择器中选择了一些图像,但是当我尝试将数据写入 Firebase 存储时,只有一张图像成功上传。这是我的代码:
List<File> _imageList = [];
File _image;
Future uploadFile() async {
final FirebaseUser user = await FirebaseAuth.instance.currentUser();
final userId = user.uid;
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(userId).child('images');
final StorageUploadTask task = firebaseStorageRef.putFile(_image);
return task;
}
Run Code Online (Sandbox Code Playgroud)
这是我选择和显示图像的代码
Future getImageFromGallery() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
_imageList.add(_image);
});
}
List<Widget> builtImageDisplay() {
return [
Padding(
padding: const EdgeInsets.all(8.0),
child: new Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: _imageList.length == 0
? new Image.asset('assets/images/format.jpg')
: …Run Code Online (Sandbox Code Playgroud)