问题描述
我遇到以下错误,但找不到原因。
那里发生了什么
有2个下拉按钮。第二个按钮取决于第一个按钮的值。 然后显示与第二个按钮的结果值相关的表格。
我在下面附上了代码。
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 {
final GlobalKey<ScaffoldState> globalKey;
const AdAdvertisement({Key key,this.globalKey}) : super(key: key);
@override
_AdAdvertisementState createState() => _AdAdvertisementState();
}
class _AdAdvertisementState extends State<AdAdvertisement> {
var selectedCurrency,selectedSub;
var selectedCurrency2,selectedType;
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>();
var category_names = Firestore.instance.collection("category_names").snapshots();
void ValueChanged(var currencyValue){
setState(() {
selectedCurrency =currencyValue;
});
}
void ValueSubchange(var 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)
),TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Model Year';
// }
// return null;
//},decoration: const Inputdecoration(
hintText: 'Enter Car Model year',labelText: 'Model Year',TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Mileage';
// }
// return null;
//},decoration: const Inputdecoration(
hintText: 'Enter Mileage',labelText: 'Mileage ',TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Enter Transmission type';
// }
// return null;
//},decoration: const Inputdecoration(
hintText: 'Enter Transmission type',labelText: 'Transmission ',TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Fueltype';
// }
// return null;
//},decoration: const Inputdecoration(
hintText: 'Enter Fuel type',labelText: 'Fueltype ',TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Engine capaciy';
// }
// return null;
//},decoration: const Inputdecoration(
hintText: 'Enter Engine capacity',labelText: 'Engine capacity(cc) ',TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please enter Description';
// }
// return null;
//},decoration: const Inputdecoration(
hintText: 'Enter Description here',labelText: 'Description ',TextFormField(
//validator: (value) {
// if (value.isEmpty) {
// return 'Please Price';
// }
// return null;
//},decoration: const Inputdecoration(
hintText: 'Enter Price',labelText: 'Price',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();
}
},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)
)
),]
)
)
);
}
List<DropdownMenuItem> currencyItems2 = [];
@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: category_names,builder: (context,snapshot) {
if (!snapshot.hasData)
return Text("Loading.....");
else {
List<DropdownMenuItem> currencyItems = [];
for (int i = 0; i < snapshot.data.documents.length; i++) {
DocumentSnapshot snap = snapshot.data.documents[i];
currencyItems.add(
DropdownMenuItem(
child: Text(
snap.documentID,style: TextStyle(color: Color(0xff11b719)),value: "${snap.documentID}",);
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
SizedBox(width: 20.0),DropdownButton(
items: currencyItems,onChanged: (currencyValue) {
setState(() {
selectedCurrency = currencyValue;
//disabledropdown = true;
});
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++) {
currencyItems2.add(
DropdownMenuItem(
child: Text(
snap.data['${j + 1}'].toString(),style:
TextStyle(color: Color(0xff11b719)),value: snap.data['${j + 1}'].toString(),);
}
}
}
final snackBar = SnackBar(
content: Text(
'Selected Currency value is $currencyValue',);
Scaffold.of(context).showSnackBar(snackBar);
},value: selectedCurrency,isExpanded: false,hint: new Text(
"Choose Category Type",DropdownButton(
items: currencyItems2,onChanged: (currencyValue) {
final snackBar = SnackBar(
content: Text(
'Selected Currency value is $currencyValue',);
Scaffold.of(context).showSnackBar(snackBar);
setState(() {
selectedCurrency2 = currencyValue;
});
},);
}
}),_widgetForm(),Card(
child: InkWell(
splashColor: Colors.blue.withAlpha(30),onTap: () {
print('Card tapped.');
},child: Container(
width: 300,height: 100,child: Text('A card that can be tapped'),);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)