Forms 颤振误差;生成函数返回null“0”;
我在我的应用程序中添加了两个下拉按钮。第二个按钮的选择值取决于第一个按钮,并以与第二个按钮中的值相关的形式出现。我在StreamBuilder中使用过它们 我在上面的表单中添加了multi-imagepicker 页面可以第一次滚动。但之后无法滚动。它抛出上述错误 它正在跳过流:Firestore.instance.collection(“类别名称”).snapshots(), 调试时的行 我在下面附上了代码和截图Forms 颤振误差;生成函数返回null“0”;,forms,firebase,flutter,dart,google-cloud-firestore,Forms,Firebase,Flutter,Dart,Google Cloud Firestore,我在我的应用程序中添加了两个下拉按钮。第二个按钮的选择值取决于第一个按钮,并以与第二个按钮中的值相关的形式出现。我在StreamBuilder中使用过它们 我在上面的表单中添加了multi-imagepicker 页面可以第一次滚动。但之后无法滚动。它抛出上述错误 它正在跳过流:Firestore.instance.collection(“类别名称”).snapshots(), 调试时的行 我在下面附上了代码和截图 import 'package:carousel_pro/carousel_pr
import 'package:carousel_pro/carousel_pro.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:multi_image_picker/multi_image_picker.dart';
import 'categories/vehicles/car.dart';
import 'categories/vehicles/van.dart';
import 'services/utils.dart';
class AdAdvertisement extends StatefulWidget {
@override
_AdAdvertisementState createState() => _AdAdvertisementState();
}
class _AdAdvertisementState extends State<AdAdvertisement> {
var selectedCurrency,selectedSub;
var value;
final databaseReference = Firestore.instance;
String now = new DateTime.now().toString();
List<Asset> images = List<Asset>();
//List<NetworkImage> _listOfImages = <NetworkImage>[];
List<String> imageUrls = <String>[];
//List<String> imageLocalLink = <String>[];
String _error = 'No Error Dectected';
bool isUploading = false;
bool carosal = false;
final _formKeyCar = GlobalKey<FormState>();
final _formKeyVan = GlobalKey<FormState>();
void ValueChanged(currencyValue){
setState(() {
selectedCurrency =currencyValue;
});
}
void ValueSubchange(subcategory){
setState(() {
selectedSub=subcategory;
});
}
void createRecord() async {
await databaseReference.collection("Advertisements")
.document(now)
.setData({
'title': 'Mastering Flutter',
'description': 'Programming Guide for Dart'
});
}
Widget _widgetForm() {
switch (selectedSub) {
case "car":
return _carForm();
break;
case "van":
build(context){
return vanForm();
};
//return _vanForm();
break;
}
}
//
//
Future<void> loadAssets() async {
List<Asset> resultList = List<Asset>();
String error = 'No Error Dectected';
try {
resultList = await MultiImagePicker.pickImages(
maxImages: 10,
enableCamera: true,
selectedAssets: images,
cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
materialOptions: MaterialOptions(
actionBarColor: "#abcdef",
actionBarTitle: "Upload Image",
allViewTitle: "All Photos",
useDetailsView: false,
selectCircleStrokeColor: "#000000",
),
);
print(resultList.length);
print((await resultList[0].getThumbByteData(122, 100)));
print((await resultList[0].getByteData()));
print((await resultList[0].metadata));
} on Exception catch (e) {
error = e.toString();
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
images = resultList;
carosal = true;
print('<<<<<<<<<<<<<<<<<<<');
print(images);
//_listOfImages = imageUrls.cast<NetworkImage>();
_error = error;
});
}
Widget _imageShow(){
if(carosal==true){
return CarouselSlider(
items: images
.map((e) => AssetThumb(asset:e, width: 300, height: 300,))
.toList(),
options: CarouselOptions(
height: 400,
aspectRatio: 16 /9 ,
viewportFraction: 0.8,
initialPage: 0,
enableInfiniteScroll: true,
reverse: false,
autoPlay: true,
autoPlayInterval: Duration(seconds: 3),
autoPlayAnimationDuration: Duration(milliseconds: 800),
autoPlayCurve: Curves.fastOutSlowIn,
enlargeCenterPage: true,
scrollDirection: Axis.horizontal,
),
);
}
else{
return Text('not yet selected');
}
}
void uploadImages(){
for ( var imageFile in images) {
postImage(imageFile).then((downloadUrl) {
imageUrls.add(downloadUrl.toString());
if(imageUrls.length==images.length){
String documnetID = DateTime.now().millisecondsSinceEpoch.toString();
Firestore.instance.collection('images').document(documnetID).setData({
'urls':imageUrls
}).then((_){
SnackBar snackbar = SnackBar(content: Text('Uploaded Successfully'));
//widget.globalKey.currentState.showSnackBar(snackbar);
setState(() {
images = [];
imageUrls = [];
carosal =false;
});
});
}
}).catchError((err) {
print(err);
});
}
}
Future<dynamic> postImage(Asset imageFile) async {
String fileName = DateTime.now().millisecondsSinceEpoch.toString();
StorageReference reference = FirebaseStorage.instance.ref().child(fileName);
StorageUploadTask uploadTask = reference.putData((await imageFile.getByteData()).buffer.asUint8List());
StorageTaskSnapshot storageTaskSnapshot = await uploadTask.onComplete;
print(storageTaskSnapshot.ref.getDownloadURL());
return storageTaskSnapshot.ref.getDownloadURL();
}
Widget _carForm() {
return Card(
child: Form(
key: _formKeyVan,
child: Column(children: <Widget>[
// Add TextFormFields and RaisedButton here.
//buildGridView(),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Brand';
// }
// //return null;
//},
decoration: const InputDecoration(
hintText: 'Enter your Car Brand',
labelText: 'Brand',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Model';
// }
// return null;
//},
decoration: const InputDecoration(
hintText: 'Enter your Car Model',
labelText: 'Car Model',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Model Year';
// }
// return null;
//},
decoration: const InputDecoration(
hintText: 'Enter Car Model year',
labelText: 'Model Year',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Mileage';
// }
// return null;
//},
decoration: const InputDecoration(
hintText: 'Enter Mileage',
labelText: 'Mileage ',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Enter Transmission type';
// }
// return null;
//},
decoration: const InputDecoration(
hintText: 'Enter Transmission type',
labelText: 'Transmission ',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Fueltype';
// }
// return null;
//},
decoration: const InputDecoration(
hintText: 'Enter Fuel type',
labelText: 'Fueltype ',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Engine capaciy';
// }
// return null;
//},
decoration: const InputDecoration(
hintText: 'Enter Engine capacity',
labelText: 'Engine capacity(cc) ',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Description';
// }
// return null;
//},
decoration: const InputDecoration(
hintText: 'Enter Description here',
labelText: 'Description ',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please Price';
// }
// return null;
//},
decoration: const InputDecoration(
hintText: 'Enter Price',
labelText: 'Price',
prefixIcon: Icon(Icons.add_circle)
),
),
SizedBox(height: 20.0),
RaisedButton(
child: new Text("add Image"),
onPressed: loadAssets,
),
SizedBox(height: 10.0,),
_imageShow(),
RaisedButton(
child: new Text("upload"),
onPressed: (){
if(images.length==0){
showDialog(context: context,builder: (_){
return AlertDialog(
backgroundColor: Theme.of(context).backgroundColor,
content: Text("No image selected",style: TextStyle(color: Colors.white)),
actions: <Widget>[
RaisedButton(
onPressed: (){
Navigator.pop(context);
},
child: Center(child: Text("Ok",style: TextStyle(color: Colors.white),)),
)
],
);
});
}
else{
SnackBar snackbar = SnackBar(content: Text('Please wait, we are uploading'));
//widget.globalKey.currentState.showSnackBar(snackbar);
uploadImages();
}
},
),
SizedBox(height: 20.0),
RaisedButton(
color: Color(0xff11b719),
textColor: Colors.white,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text("Submit", style: TextStyle(fontSize: 24.0)),
],
)),
onPressed: () {
createRecord();
},
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)
)
),
]
)
)
);
}
//Widget _vanForm() {
// return Form(
// key: _formKeyCar,
// child: Column(children: <Widget>[
// // Add TextFormFields and RaisedButton here.
// TextFormField(
// validator: (value) {
// if (value.isEmpty) {
// return 'Please enter some text';
// }
// return null;
// },
// decoration: const InputDecoration(
// hintText: 'Enter your Van Model',
// labelText: 'Model',
// ),
// ),
//
// ]));
//}
QuerySnapshot qs;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Container(
alignment: Alignment.center,
child: Text('Advertisement'),
),
),
body: ListView(
children: <Widget>[
Text('Select category here'),
Text('Select category here'),
SizedBox(height: 40.0),
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection("category_names").snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
const Text("Loading.....");
else {
List<DropdownMenuItem> currencyItems = [];
List<DropdownMenuItem> currencySub = [];
for(int i=0;i<snapshot.data.documents.length;i++){
DocumentSnapshot snap = snapshot.data.documents[i];
currencyItems.add(
DropdownMenuItem(
child: Text(
//snap.data.values.toString(),
snap.documentID
),
value: "${snap.documentID}",
),
);
}
for (int i = 0; i < snapshot.data.documents.length; i++) {
DocumentSnapshot snap = snapshot.data.documents[i];
if(snap.documentID==selectedCurrency){
for (int j = 0; j < snap.data.length; j++) {
currencySub.add(
DropdownMenuItem(
child: Text(
snap.data['${j + 1}'].toString(),
style: TextStyle(color: Color(0xff11b719)),
),
value: snap.data['${j + 1}'].toString(),
),
);
}
}
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
DropdownButton(
items: currencyItems,
onChanged: (currencyValue) => ValueChanged(currencyValue),
value: selectedCurrency,
isExpanded: false,
hint: new Text(
"Choose category Type",
style: TextStyle(color: Color(0xff11b719)),
),
),
DropdownButton(
items: currencySub,
onChanged: (subcategory) => ValueSubchange(subcategory),
value: selectedSub,
isExpanded: false,
hint: new Text(
"Choose sub",
style: TextStyle(color: Color(0xff11b719)),
),
),
],
);
}
}),
_widgetForm(),
],
),
);
}
}
import'包:carousel_pro/carousel_pro.dart';
导入“package:carousel_slider/carousel_slider.dart”;
导入“包:cloud_firestore/cloud_firestore.dart”;
导入“包:firebase_存储/firebase_存储.dart”;
进口“包装:颤振/材料.省道”;
导入“package:multi_image_picker/multi_image_picker.dart”;
进口“类别/车辆/汽车.省道”;
进口“类别/车辆/货车省道”;
导入“服务/utils.dart”;
类ADAdvertision扩展StatefulWidget{
@凌驾
_AdAdvertisementState createState()=>\u AdAdvertisementState();
}
类AdAdvertisementState扩展状态{
var selectedCurrency,selectedSub;
var值;
final databaseReference=Firestore.instance;
String now=new DateTime.now().toString();
列表图像=列表();
//列表_listOfImages=[];
列表ImageURL=[];
//列表imageLocalLink=[];
字符串_error='未检测到错误';
bool=false;
bool carosal=假;
最终_formKeyCar=GlobalKey();
最终_formKeyVan=GlobalKey();
无效值已更改(currencyValue){
设置状态(){
selectedCurrency=currencyValue;
});
}
无效值子更改(子类别){
设置状态(){
selectedSub=子类别;
});
}
void createRecord()异步{
等待databaseReference.collection(“广告”)
.文件(现在)
.setData({
“标题”:“掌握颤振”,
“说明”:“Dart编程指南”
});
}
Widget_widgetForm(){
开关(selectedSub){
案例“汽车”:
返回_carForm();
打破
案例“货车”:
构建(上下文){
返回形式();
};
//返回_vanForm();
打破
}
}
//
//
Future loadAssets()异步{
List resultList=List();
字符串错误='未检测到错误';
试一试{
结果列表=等待MultiImagePicker.pickImages(
最高限额:10,
启用摄像头:正确,
所选资产:图像,
cupertinoOptions:cupertinoOptions(takePhotoIcon:“聊天”),
材质选项:材质选项(
actionBarColor:#abcdef“,
actionBarTitle:“上传图像”,
allViewTitle:“所有照片”,
useDetailsView:false,
选择CircleStrokeColor:#000000,
),
);
打印(结果列表长度);
打印((等待结果列表[0].getThumbByteData(122100));
打印((等待结果列表[0]。getByteData());
打印((等待结果列表[0]。元数据));
}关于异常捕获(e){
错误=e.toString();
}
//如果在异步平台运行时从树中删除了小部件
//消息正在传输中,我们希望放弃回复而不是呼叫
//设置state以更新我们不存在的外观。
如果(!已安装)返回;
设置状态(){
图像=结果列表;
carosal=真;
打印(“StreamBuilder
有一个builder
属性,该属性的类型为AsyncWidgetBuilder
,它是一个typedef
,具有以下实现:
typedef AsyncWidgetBuilder<T> = Widget Function(BuildContext context, AsyncSnapshot<T> snapshot);
typedef AsyncWidgetBuilder=Widget函数(BuildContext上下文,AsyncSnapshot快照);
因此,您需要返回一个小部件:
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection("category_names").snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Text("Loading.....");
else if(snapshot.hasData)
return Text("data...");
else
return CircularProgressIndicator();
StreamBuilder(
流:Firestore.instance.collection(“类别名称”).snapshots(),
生成器:(上下文,快照){
如果(!snapshot.hasData)
返回文本(“加载…”);
else if(snapshot.hasData)
返回文本(“数据…”);
其他的
返回循环ProgressIndicator();