问题描述
我试图将数据从快照传递到小部件,以便可以呈现数据,但出现以下错误
lib/screens/RetailerList.dart:215:35: Error: Too few positional arguments: 1 required,0 given.
? _buildretailer(retailer: snapshot.data)
小部件
Widget _buildretailer(Retailer retailer) {
return GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
// builder: (_) => RetailerDetails(retailer: retailer[0]),),);
},child: Padding(
padding: EdgeInsets.only(left: 40.0,bottom: 30.0),child: Column(
crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
Hero(
tag: retailer.slug,child: Container(
width: double.infinity,height: 250.0,decoration: Boxdecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),bottomLeft: Radius.circular(20.0),image: decorationImage(
image: NetworkImage(
"https://site-assets.afterpay.com/assets/favicon/apple-touch-icon-47062a004c5b1440ea8159b43580154540d76df61dc55dc87522378f8f76bbec.png",fit: BoxFit.cover,Padding(
padding: EdgeInsets.fromLTRB(12.0,12.0,40.0,0.0),child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,children: <Widget>[
Text(
retailer.name,style: TextStyle(
fontFamily: 'Montserrat',fontSize: 24.0,fontWeight: FontWeight.bold,IconButton(
icon: Icon(Icons.favorite_border),iconSize: 30.0,color: Color(0xFFFD6456),onpressed: () => print('Favorite'),],0.0,12.0),child: Text(
retailer.shortDescription,style: TextStyle(
fontFamily: 'Montserrat',fontSize: 16.0,color: Colors.grey,);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: Theme.of(context).platform == TargetPlatform.iOS
? CupertinoNavigationBar(
actionsForegroundColor: Color.fromrGBO(108,212,196,1),middle: Text('Explore Retailers',style: GoogleFonts.nunito(
fontWeight: FontWeight.w700,textStyle: TextStyle(
color: Color.fromrGBO(98,49,158,letterSpacing: .5,fontSize: 20))),leading: IconButton(
tooltip: 'Filter Retailers',icon: Icon(IconData(0xF4A6,fontFamily: CupertinoIcons.iconFont,fontPackage: CupertinoIcons.iconFontPackage)),// onpressed: _onButtonpressed
),)
: AppBar(
title: Text('Explore Retailers',style: GoogleFonts.nunito(fontWeight: FontWeight.w700)),actions: <Widget>[
IconButton(
tooltip: 'Filter Retailers',icon: Icon(Icons.filter_list),// onpressed: _onButtonpressed
)
],backgroundColor: Colors.white,body: ListView(
children: <Widget>[
SizedBox(height: 10.0),Container(height: 100.0,child: _buildListView()),SizedBox(height: 50.0),StreamBuilder<List<Retailer>>(
stream: fetchRetailers().asstream(),builder: (context,snapshot) {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
? _buildretailer(retailer: snapshot.data)
: Center(child: CircularProgressIndicator());
},)
],);
}
}
解决方法
代替buildRetailer(retailer: snapshot.data)
执行buildRetailer(snapshot.data)
由于您要将数据传递给不存在的命名参数retailer
,因为您已经在positional parameter
方法中定义了buildRetailer