如何解决将快照数据传递到Flutter Widget
我试图将数据从快照传递到小部件,以便可以呈现数据,但出现以下错误
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。