1st Call Your data and store it into a list;
List<dynamic> -newsData = <dynamic>[];
QuerySnapshot snap =
await
Firestore.instance.collection('contents').getDocuments();
var x = snap.documents;
_newsData.clear();
notifyListeners();
x.forEach((f) => _newsData.add(f));
----------
from you view call :
dataList(ab.newsData));
----------
Widget dataList(d) {
return ListView.separated(
padding: EdgeInsets.only(top: 50, bottom: 50),
itemCount: d.length,
separatorBuilder: (BuildContext context, int index) {
return SizedBox(
height: 20,
);
},
itemBuilder: (BuildContext context, int index) {
return Container(
padding: EdgeInsets.all(15),
height: 160,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey[200]),
borderRadius: BorderRadius.circular(10)),
child: Row(
children: <Widget>[
Container(
height: 130,
width: 130,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(d[index]['image url'] ?? ""))),
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(
top: 15,
left: 15,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
d[index]['title'].toString(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.w600),
),
Text(
"Source: " + d[index]['source'].toString(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12, fontWeight: FontWeight.w600),
),
SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.circular(20),
),
child: Text(d[index]['group'] ?? "",
style: TextStyle(
fontSize: 13, color: Colors.white)),
),
Container(
padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
decoration: BoxDecoration(
color: Colors.deepPurpleAccent,
borderRadius: BorderRadius.circular(20),
),
child: Text(d[index]['category'] ?? "",
style: TextStyle(
fontSize: 13, color: Colors.white)),
),
SizedBox(width: 5),
Icon(Icons.access_time, size: 11, color: Colors.grey),
FittedBox(
child: Text(
d[index]['date'].toString(),
style: TextStyle(fontSize: 12),
),
),
],
),
SizedBox(
height: 10,
),
Row(
children: <Widget>[
Container(
height: 35,
width: 45,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(10)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.favorite,
size: 16,
color: Colors.grey,
),
Text(
d[index]['loves'].toString(),
style: TextStyle(
color: Colors.grey, fontSize: 13),
)
],
),
),
SizedBox(width: 10),
InkWell(
child: Container(
height: 35,
width: 45,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(10)),
child: Icon(
Icons.comment,
size: 16,
color: Colors.grey[800],
),
),
onTap: () => navigateToCommentsPage(
context, d[index]['timestamp']),
),
SizedBox(
width: 10,
),
InkWell(
child: Container(
height: 35,
width: 45,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(10)),
child: Icon(Icons.remove_red_eye,
size: 16, color: Colors.grey[800])),
onTap: () {
handlePreview(
context,
d[index]['title'],
d[index]['source'],
d[index]['description'],
d[index]['date'],
d[index]['image url'],
d[index]['loves'],
d[index]['timestamp'],
d[index]['category']);
}),
SizedBox(width: 10),
InkWell(
child: Container(
height: 35,
width: 45,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(10)),
child: Icon(Icons.edit,
size: 16, color: Colors.grey[800])),
onTap: () => navigateToEditPage(context, d[index]),
),
SizedBox(width: 10),
InkWell(
child: Container(
height: 35,
width: 45,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(10)),
child: Icon(Icons.delete,
size: 16, color: Colors.grey[800])),
onTap: () {
handleDelete(context, d[index]['timestamp']);
},
),
],
),
],
),
),
)
],
),
);
},
);
Please check the full code edit from your code. Actually you are using two FloatingActionButton. So you need to use two heroTag with different name. I already added in the code. No problem with NewTrip class.
import 'package:flutter/material.dart';
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Page0(),
);
}
}
class Page0 extends StatefulWidget {
@override
_Page0State createState() => _Page0State();
}
class _Page0State extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF493597),
body: ListView(
children: [
Padding(
padding: EdgeInsets.only(top: 15.0, left: 10.0),
),
SizedBox(
height: 25.0,
),
Padding(
padding: EdgeInsets.only(left: 40.0),
child: Row(
children: [
Text(
'Expense',
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 25.0),
),
SizedBox(
width: 10.0,
),
Text(
'What',
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.white,
fontSize: 25.0,
),
),
],
),
),
SizedBox(height: 60.0),
Container(
margin: EdgeInsets.only(
left: 10.0,
right: 10.0,
),
height: MediaQuery.of(context).size.height - 150,
decoration: BoxDecoration(
color: Color(0xFFFCFCFC),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(75.0),
topRight: Radius.circular(75.0),
),
),
child: ListView(
primary: false,
padding: EdgeInsets.only(
left: 15.0,
right: 20.0,
top: 25.0,
),
children: [
Padding(
padding: const EdgeInsets.only(
top: 30.0,
),
child: Column(
children: [
//greeting text
Row(
children: [
Expanded(
child: Center(
child: Text(
'Hello! :)',
style: TextStyle(
fontFamily: 'Permanent-Marker',
color: Colors.black,
fontSize: 30.0,
),
),
),
),
],
),
SizedBox(
height: 30.0,
),
//add button
Row(children: [
Expanded(
flex: 1,
child: Container(
height: 100.0,
width: 100.0,
child: FittedBox(
child: FloatingActionButton(
heroTag: "btn",
elevation: 10.0,
backgroundColor: Colors.white,
child: Icon(
Icons.add,
color: Colors.black,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewTrip()),
);
},
),
),
),
),
//add text
Expanded(
flex: 1,
child: Text(
'New trip',
style: TextStyle(
fontFamily: 'Nanum',
fontSize: 30.0,
),
),
),
]),
SizedBox(
height: 30.0,
),
//previous trip button
Row(
children: [
Expanded(
flex: 1,
child: Container(
height: 100.0,
width: 100.0,
child: FittedBox(
child: FloatingActionButton(
heroTag: "btn1",
elevation: 10.0,
backgroundColor: Colors.white,
onPressed: () {},
child: Icon(
Icons.assessment,
color: Colors.black,
),
),
),
),
),
//previous trip text
Expanded(
flex: 1,
child: Text(
'Previous trips',
style: TextStyle(
fontFamily: 'Nanum',
fontSize: 30.0,
),
),
)
],
),
SizedBox(
height: 50.0,
),
],
),
),
],
),
),
],
),
);
}
}
NewTrip class
class NewTrip extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Text('NEW TRIP'),
);
}
}