【发布时间】:2020-12-17 23:22:19
【问题描述】:
我正在尝试将数据从快照传递到小部件,以便渲染数据,但出现以下错误
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'),
),
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(12.0, 0.0, 40.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, 1),
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());
},
)
],
),
);
}
}
【问题讨论】:
标签: flutter snapshot flutter-widget