我正在使用带卡片的flutter + firebase,并单击以将数据发送到新屏幕。例如,我单击卡上的标题和图像进入下一个屏幕(DetailPage)。我该如何实现?
我的代码:-
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:loading/indicator/ball_pulse_indicator.dart';
import 'package:loading/loading.dart';
class StreamBuilderFireStore extends StatelessWidget {
Widget _buildList(BuildContext context, DocumentSnapshot document) {
return Card(
elevation: 8,
child: InkWell(
onTap: () {
// Function is executed on tap.
},
child: Column(
children: <Widget>[
AspectRatio(
child: Image.network(document['img'], fit: BoxFit.cover),
aspectRatio: 2 / 1,
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Text(
document['title'],
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
),
),
Padding(
padding: EdgeInsets.only(bottom: 5.0),
)
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder(
stream: Firestore.instance.collection('posts').snapshots(),
//print an integer every 2secs, 10 times
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: Loading(
indicator: BallPulseIndicator(),
size: 80.0,
color: Colors.red),
);
}
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
return _buildList(context, snapshot.data.documents[index]);
},
);
},
),
);
}
}
class DetailPage extends StatefulWidget {
@override
_DetailPageState createState() => _DetailPageState();
}
class _DetailPageState extends State<DetailPage> {
@override
Widget build(BuildContext context) {
return Container();
}
}