我正在寻找一种解决方案,以通过导航器或其他将快照传递到“详细信息页面”。
class SoccerList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final database = Provider.of<FirestoreDatabase>(context, listen: false);
return StreamBuilder<List<Soccer>>(
stream: database.soccerStream(),
builder: (_, snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
final soccer = snapshot.data;
if (soccer == null) {
return Scaffold(
body: Center(
child: Text('User list is empty',
style: Theme.of(context).textTheme.headline6),
),
);
}
return ListView.builder(
itemCount: soccer.length,
itemBuilder: (context, index) {
final item = soccer[index];
return Container(
margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5), //color of shadow
spreadRadius: 5, //spread radius
blurRadius: 7, // blur radius
offset: Offset(0, 2), // changes position of shadow
//first paramerter of offset is left-right
//second parameter is top to down
),
//you can set more BoxShadow() here
],
),
child: ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailBetScreen(soccer: soccer)
//[index],
)
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
leading: IconButton(
iconSize: 24,
icon: new SvgPicture.asset('assets/ball/fussball7.svg'), onPressed: () { },
),
title: item.displayname != null? Text(item.displayname) : Text(item.sporttype),
subtitle: Text(item.sporttype),
),
);
},
);
}
错误消息是:
窗口小部件库捕获到异常: “列表”类型不是“文档快照”类型的子类型 相关的引起错误的小部件是 MaterialApp
如何将快照(足球)传递到详细信息页面?确保快照包含列表...。我同时需要两者。提前想到任何想法!
这是我的信息流:
Stream<List<Soccer>> soccerStream() => _service.soccerStream<Soccer>(
path: FirestorePath.bets(),
builder: (data, documentId) => Soccer.fromMap(data, documentId),
);
这是我的详细信息屏幕:
class DetailBetScreen extends StatelessWidget {
final DocumentSnapshot soccerBet;
DetailBetScreen({Key key, @required this.soccerBet}) : super(key: key);
答案 0 :(得分:0)
您可以尝试以下方法:
class DetailBetScreen extends StatelessWidget {
final dynamic soccerBet;
DetailBetScreen({Key key, @required this.soccerBet}) : super(key: key);