How to scroll a text? - arrays

I have a text and I've tried a lot to make it scrollable, what I want is to make the postDesc text scrollable I've tried to wrap it with single child scroll view and listview and expanded but not worked.
please give me a solution
I want to make the screen or the container scrollable or to scroll the text only.
I've seen many solutions but it didn't work for me.
My project has been stopped because of that.
For any details you want please leave a comment.
thanks,
My Code:
#override
Widget build(BuildContext context) {
final userimage = InkWell(
child: Container(
margin: EdgeInsets.only(right: 10.0),
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage('${widget.userPhoto}'),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(7.0),
),
),
);
final headerDesc = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'${widget.writer}',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
Text(
'25 minutes ago',
style: TextStyle(
color: Colors.grey.withOpacity(0.6),
fontWeight: FontWeight.bold,
),
)
],
);
final header = Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[userimage, headerDesc],
);
final descriptionText = Text(
'${widget.postTitle}',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Amiri',
color: Colors.black87,
fontWeight: FontWeight.w600,
fontSize: MediaQuery.of(context).size.width / 20,
),
);
final divider = Divider(
thickness: 0.5,
color: Colors.grey,
);
final footer = Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
onPressed: () {
print(null);
},
icon: Icon(
Icons.share,
color: Theme.of(context).primaryColor,
),
),
Row(
children: <Widget>[
SizedBox(
width: 30.0,
),
StreamBuilder<QuerySnapshot>(
stream: _firestore.collection('posts').snapshots(),
builder: (context, snapshot) {
var documents = snapshot.data.documents;
var likes;
for (var document in documents) {
if (document.documentID == widget.uid) {
likes = document['likes'];
}
}
return Text(
'$likes',
);
}),
SizedBox(
width: 3.0,
),
Icon(
Icons.favorite,
color: Colors.red,
),
],
),
],
);
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: MediaQuery.of(context).size.height,
child: Stack(
children: <Widget>[
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImagePreview(
image: widget.networkImage,
),
),
);
},
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(14.0),
child: Container(
height: MediaQuery.of(context).size.height / 5,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14.0),
image: DecorationImage(
image: widget.networkImage.image,
fit: BoxFit.cover,
),
),
),
),
),
Positioned(
top: 90.0,
left: 0.0,
right: 0.0,
child: Padding(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
child: Material(
elevation: 5.0,
shadowColor: Colors.white,
borderRadius: BorderRadius.circular(14.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14.0),
),
child: Padding(
padding: EdgeInsets.only(
top: 20.0,
bottom: 00.0,
left: 20.0,
right: 20.0,
),
child: ListView(
shrinkWrap: true,
children: <Widget>[
header,
SizedBox(
height: 10.0,
),
descriptionText,
SizedBox(
height: 5,
),
divider,
Padding(
padding: const EdgeInsets.all(20),
child: SingleChildScrollView(
child: Text(
'${widget.postDesc}',
),
),
),
footer,
SizedBox(
height: 10,
),
],
),
),
),
),
),
)
],
),
),
),
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.red,
child: Icon(
Icons.favorite,
color: Colors.white,
),
onPressed: () async {
await likePost();
},
),
);
}

I might be wrong here, but I think the problem is that you have a SingleChildScrollView inside a ListView. If you just want to scroll the postDesc, you might want to add this to your ListView:
ListView(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: [...]
),

Related

How I use data from database So that I don't Have to add hundred thousand of images in assets in flutter?

Beginner here,
I have never used database before.
I am creating an flutter app which contain product images and its affiliate link...but my app size is getting bigger because in assests i have uploaded hundreds of images which is taking lots of space..
Is there any way i can fetch data from backend or something like that ...
enter image description here
i want this type of UI..
enter image description here
And this my code for it...
enter code here: SliverToBoxAdapter(
child: SizedBox(
child: Column(
children: [
// ignore: prefer_const_constructors
Padding(
padding: const EdgeInsets.only(right: 210.0),
// ignore: prefer_const_constructors
child: Text(
"Great Personality",
// ignore: prefer_const_constructors
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
height: 200,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
child: Container(
width: 120,
color: Colors.amber,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 120,
color: Colors.white,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 120,
color: Colors.white,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 120,
color: Colors.white,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 120,
color: Colors.white,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 120,
color: Colors.white,
),
),
],
),
),
)
],
)
],
),
),
),
Use Cached Network Image and fetch from firebase or any other server. (Works offline as long as the image has been loaded before.)
if your app will work on ofline mode it will crash
Yes, Use Firebase Storage to store your images and fetch images from there.

List view using array list with name image date in flutter

How to get data from static or dynamic list and set to list view or grid view
If you want to convert your list of data into a ListView of widgets you can map the data list to your resultant widget list. Follow the code below:
class TestPage extends StatefulWidget {
#override
_TestPageState createState() => _TestPageState();
}
class _TestPageState extends State<TestPage> {
List<Data> dataList = [
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
];
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
width: width,
height: height,
child: ListView(
scrollDirection: Axis.vertical,
children: dataList.map((data){
return Container(
width: width,height: 80,
decoration: BoxDecoration(border: Border(bottom: BorderSide(width: 1.5,color: Colors.black))),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(width: 50,height: 50,decoration: BoxDecoration(image: DecorationImage(image: NetworkImage(data.imageURL))),),
Column(
mainAxisSize: MainAxisSize.max,
children: [
Text(data.name),
Expanded(child: Text(data.description)),
],
),
Text(data.date.toString());
],
),
);
}).toList(),
),
),
);
}
}
class Data {
String name;
String imageURL;
String description;
DateTime date;
Data({this.name,this.imageURL,this.date,this.description});
}
Check the above code based on your requirement.
List dataList = [
Data(
name: "Title",date: "12/03/2021",description: "Description",imageURL:'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
];
#override
Widget build(BuildContext context) {
double width = MediaQuery
.of(context)
.size
.width;
double height = MediaQuery
.of(context)
.size
.height;
return Scaffold(
appBar: new AppBar(
bottomOpacity: 0.0,
elevation: 0.0,
backgroundColor: Color(0xFF104C57),
title: new Text("Notification"),
leading: new IconButton(
icon: new Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop(),
),
),
body: SingleChildScrollView(
child: Container(
child: Card(
margin: EdgeInsets.only(left: 7.0, right: 7.0),
child: Container(
width: width,
height: height,
child: ListView(
scrollDirection: Axis.vertical,
children: dataList.map((data) {
return Container(
margin: EdgeInsets.only(left: 6.0, right: 6.0, top: 10.0),
width: width,
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
border: Border.all(
color: Color(0xFFDCDADB),
width: 0.5,
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 10,
),
Container(
width: 65,
height: 65,
decoration: BoxDecoration(
image: DecorationImage(
image: ExactAssetImage(
'lib/images/notificationicon.png',
),
)),
),
SizedBox(
width: 10,
),
Container(
width: 145,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
height: 20,
),
Text(
data.name,
style: TextStyle(
fontSize: 12.0,
//fontWeight: FontWeight.w700,
color: Color(0xFF75778A),
fontWeight: FontWeight.w500,
),
),
Expanded(
child: Text(
data.description,
style: TextStyle(
fontSize: 12.0,
//fontWeight: FontWeight.w700,
color: Color(0xFF868C9A),
),
)),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
height: 20,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"Date : ",
style: TextStyle(
fontSize: 12.0,
color: Color(0xFF868C9A),
),
),
Text(
data.date,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w500,
color: Color(0xFF6A7180),
),
),
],
),
],
),
],
),
);
}).toList(),
),
),
),
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(00)),
image: DecorationImage(
image: ExactAssetImage('lib/images/homebg.png'),
fit: BoxFit.fill,
),
),
),
),
);
}
class Data {
String name,imageURL,description,date;
Data({this.name, this.imageURL, this.date, this.description});
}

Unable to create data tables dynamically using TextField input

I am trying out to create an invoice application, wherein the user is entering the data, and then it should come up listed as a table.
What I have achieved so far is just a single row with just a single user input detail like with errors in it as well...
I wanted the application to
HardCoded Code:
class Sixth extends StatefulWidget {
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return SixthState();
}
}
class SixthState extends State<Sixth> {
final pdf = pw.Document();
String path;
share() async {
Share.shareFiles([path]);
}
create() async {
print('creating');
pdf.addPage(pw.MultiPage(
pageFormat: PdfPageFormat.a4,
margin: pw.EdgeInsets.all(12),
build: (pw.Context context) {
return <pw.Widget>[
pw.Paragraph(
text: 'SOLUTION HUB\nVENDORS',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(left: 450),
text: 'Billing Address:',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Row(children: [
pw.Paragraph(
text: 'wrqijwqiojqwoirjq\nirjorwiuroeriuwor\noerweo8rw',
padding: pw.EdgeInsets.only(top: 10)),
pw.SizedBox(width: 370),
pw.Paragraph(
text: 'wrqijwqiojqwoirjq\nirjorwiuroeriuwor\noerweo8rw',
padding: pw.EdgeInsets.only(top: 10))
]),
pw.Paragraph(
padding: pw.EdgeInsets.only(top: 15),
text: 'PAN No. ${panvalue}',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(top: 15),
text: 'GST Registration No. ${gstvalue}',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(top: 15),
text: 'Order No. ${ordernovalue}',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(top: 15),
text: 'Order Date. ${orderdatevalue}',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.Paragraph(
padding: pw.EdgeInsets.only(left: 450),
text: 'INVOICE NUMBER\n03950234982042980',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold)),
pw.SizedBox(height: 20),
pw.Table.fromTextArray(data: <List<String>>[
<String>[
'SI\nNo.',
'Description',
'Unit\nPrice',
'Qty',
'Net Amount',
'Tax\nRate',
'Tax\nType',
'Tax\nAmt',
'Total\nAmt'
],
<String>[
'1',
'${SecondState.descriptionController.text}',
'${ThirdState.unitpriceController.text}',
'1',
'500',
'${FourthState.taxrateController.text}',
'${FourthState.taxtypeController.text}',
'${FourthState.taxamountController.text}',
'276.6'
],
])
];
},
));
}
Future save() async {
print('sacing');
Directory directory = await getApplicationDocumentsDirectory();
String documentpath = directory.path;
File file = File("$documentpath/example.pdf");
setState(() {
path = "$documentpath/example.pdf";
});
file.writeAsBytesSync(pdf.save());
}
int _value = 1;
AnimationController animationController;
Animation<Offset> offset;
static var panvalue;
static var gstvalue;
static var ordernovalue;
static var orderdatevalue;
static var descriptionvalue;
static var unitpricevalue;
static var quantityvalue;
static var taxratevalue;
static var taxtypevalue;
static var taxamtvalue;
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
drawer: Drawer(),
appBar: AppBar(
centerTitle: true,
title: Text('ORDER DETAILS'),
backgroundColor: Colors.blueGrey,
actions: <Widget>[
Padding(
padding: EdgeInsets.all(2),
child: IconButton(
onPressed: () {}, //USER PROFILE
icon: Icon(Icons.supervised_user_circle),
iconSize: 30,
),
)
],
),
body: SingleChildScrollView(
child: SafeArea(
child: Column(children: <Widget>[
Container(
padding: EdgeInsets.only(right: 220, top: 20),
child: Text(
'SOLUTION HUB \n VENDORS',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
),
Container(
padding: EdgeInsets.only(left: 240),
child: Text(
'Billing Adress:',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
),
SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 30),
child:
Text('Ubga wjpw wiqjoiw\n owqkdw qwok qoqkw \nojq vpoqk'),
),
Container(
padding: EdgeInsets.only(right: 15),
child: Text('oefkwpfoke 20-32 \n 032902 0239 \n 0392230'),
)
],
),
Container(
width: 800,
padding: EdgeInsets.only(left: 35, right: 10, top: 45),
child: Text(
"Pan No. ${panvalue}",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Container(
width: 800,
padding: EdgeInsets.only(left: 35, right: 10, top: 25),
child: Text(
"GST REGISTRATION NO. ${gstvalue}",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Container(
width: 800,
padding: EdgeInsets.only(left: 35, right: 10, top: 25),
child: Text(
"Order No. ${ordernovalue} ",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Container(
width: 400,
padding: EdgeInsets.only(left: 35, right: 20, top: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Order Date: ${orderdatevalue}",
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
'INVOICE NUMBER',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14),
)
],
),
),
Container(
padding: EdgeInsets.only(left: 250, top: 5),
child: Text('5920384283429')),
Row(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
child: DataTable(columnSpacing: 4, columns: [
DataColumn(
label: Text(
'Si\nNo.',
textAlign: TextAlign.left,
)),
DataColumn(label: Text('Description')),
DataColumn(label: Text('Unit\nPrice')),
DataColumn(label: Text('Qty')),
DataColumn(label: Text('Net\namount')),
DataColumn(label: Text('Tax\nRate')),
DataColumn(label: Text('Tax\nType')),
DataColumn(label: Text('Tax\nAmt')),
DataColumn(label: Text('Total\nAmt'))
], rows: [
DataRow(cells: [
DataCell(Wrap(
children: <Widget>[
Text(
'1',
textAlign: TextAlign.start,
)
],
)),
DataCell(Text(
'${SecondState.descriptionController.text}',
textAlign: TextAlign.center,
)),
DataCell(Wrap(
children: <Widget>[
Text(
'${ThirdState.unitpriceController.text}',
textAlign: TextAlign.center,
)
],
)),
DataCell(Text('${ThirdState.quantityController.text}')),
DataCell(Text('500')),
DataCell(Text('${FourthState.taxrateController.text}')),
DataCell(Text('${FourthState.taxtypeController.text}')),
DataCell(Text('${FourthState.taxamountController.text}')),
DataCell(Text('500')),
])
]))),
],
),
SizedBox(
height: 150,
),
ButtonTheme(
minWidth: 110,
height: 50,
child: RaisedButton(
color: Colors.blue[300],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18)),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("COMPLETE ACTION USING"),
content: Container(
height: 150,
width: 100,
child: Column(
children: <Widget>[
FlatButton(
onPressed: () async {
create();
await save();
share();
},
child: Text('WhatsApp'),
),
FlatButton(
onPressed: () {},
child: Text('Gmail'),
),
FlatButton(
onPressed: () {},
child: Text("Download"),
)
],
),
),
);
});
},
child: Text('Share'),
),
)
]),
),
),
));
}
}
What I want to achieve is this
It should automatically add rows as user inputs enter details
Errors I have encountered:
Whenever I going to add more items the previous data are stored in the text fields.
There are more colors on the right side but am unable to view it.
Please help me solve this issue

how to update flutter UI according to firebase

I have this list of Post where user can like, comment and share.
Widget build(BuildContext context) {
return Container(
child: FutureBuilder(
future: _data,
builder: (_, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index) {
return Card(
elevation: 4,
child: Padding(
padding: EdgeInsets.only(left: 10.0, top: 10),
child: InkWell(
onTap: () => navigateToDetail(
snapshot.data[index],
snapshot.data[index].data["Userid"],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
children: <Widget>[
Container(
width: 45,
height: 45,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(snapshot
.data[index].data["User Pic"]),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(
Radius.circular(50.5)),
),
),
Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
snapshot.data[index].data["Name"],
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18),
),
),
],
),
Padding(
padding: EdgeInsets.only(left: 60, bottom: 10),
child: Text(
DateFormat.yMMMd().add_jm().format(
DateTime.parse(snapshot
.data[index].data["Creation Time"]
.toDate()
.toString())),
style: TextStyle(
color: Colors.black38, fontSize: 12),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(left: 75, right: 15),
child: Text(
snapshot.data[index].data["Description"],
style: TextStyle(fontSize: 16),
),
),
),
Padding(
padding: EdgeInsets.only(
left: 75, top: 15, bottom: 8),
child: Text(
snapshot.data.length.toString() +
"Files uploaded",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 14,
fontStyle: FontStyle.italic),
),
),
Divider(),
new Row(
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
IconButton(
onPressed: () {
Firestore.instance.runTransaction((transaction) async{
DocumentSnapshot freshData = await transaction.get(snapshot.data[index].reference);
await transaction.update(freshData.reference, {
'Likes':freshData['Likes']+1,
});
});
},
icon: Icon(Icons.favorite_border,
color: Colors.redAccent,
size: 23.0),
),
Text(snapshot.data[index].data["Likes"].toString())
],
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.chat_bubble_outline,
color: Colors.blue,
size: 23.0,
),
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.near_me,
color: Colors.blue,
size: 23.0,
),
),
),
],
),
],
),
),
),
);
});
}
}),
);
}
and have a Firestore like this :
storing likes in Post collection.
I need:
when the user press on like icon it will update the firestore as well as count in flutter UI.
what I have done so far:
it will only update the firestore and for updation in flutter UI I have to refresh the screen.
Thanks.
Update:
#override
void initState() {
super.initState();
_data = UserManagement().getPosts();
}
from UserManagement:
getPosts() async {
QuerySnapshot Qn = await Firestore.instance.collection("Posts").orderBy(
"Creation Time", descending: true).getDocuments();
return Qn.documents;
}
Just replace your FutureBuilder with StreamBuilder to get the stream whenever there is an update in your collection
Widget build(BuildContext context) {
return Container(
child: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection("Posts").orderBy(
"Creation Time", descending: true).snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index) {
return Card(
elevation: 4,
child: Padding(
padding: EdgeInsets.only(left: 10.0, top: 10),
child: InkWell(
onTap: () => navigateToDetail(
snapshot.data[index],
snapshot.data[index].data["Userid"],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
children: <Widget>[
Container(
width: 45,
height: 45,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(snapshot
.data[index].data["User Pic"]),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(
Radius.circular(50.5)),
),
),
Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
snapshot.data[index].data["Name"],
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18),
),
),
],
),
Padding(
padding: EdgeInsets.only(left: 60, bottom: 10),
child: Text(
DateFormat.yMMMd().add_jm().format(
DateTime.parse(snapshot
.data[index].data["Creation Time"]
.toDate()
.toString())),
style: TextStyle(
color: Colors.black38, fontSize: 12),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(left: 75, right: 15),
child: Text(
snapshot.data[index].data["Description"],
style: TextStyle(fontSize: 16),
),
),
),
Padding(
padding: EdgeInsets.only(
left: 75, top: 15, bottom: 8),
child: Text(
snapshot.data.length.toString() +
"Files uploaded",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 14,
fontStyle: FontStyle.italic),
),
),
Divider(),
new Row(
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
IconButton(
onPressed: () {
Firestore.instance.runTransaction((transaction) async{
DocumentSnapshot freshData = await transaction.get(snapshot.data[index].reference);
await transaction.update(freshData.reference, {
'Likes':freshData['Likes']+1,
});
});
},
icon: Icon(Icons.favorite_border,
color: Colors.redAccent,
size: 23.0),
),
Text(snapshot.data[index].data["Likes"].toString())
],
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.chat_bubble_outline,
color: Colors.blue,
size: 23.0,
),
),
),
Expanded(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.near_me,
color: Colors.blue,
size: 23.0,
),
),
),
],
),
],
),
),
),
);
});
}
}),
);
}
I assume you should use a StreamBuilder instead of a FutureBuilder.
StreamBuilders are like FutureBuilders that continuously update, depending on their stream.
You should also subscribe to the stream of the Firestore collection, instead of getting it only once.
Instead of getPosts maybe use this:
Stream<QuerySnapshot> getPostsStream() {
return Firestore.instance.collection("Posts").orderBy(
"Creation Time", descending: true).snapshots();
}
And change your FutureBuilder to a StreamBuilder:
StreamBuilder<QuerySnapshot>(
stream: getPostsStream(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
} else {
final List<DocumentSnapshot> documents = snapshot.data.documents;
// use as documents[index].
// ....
}
},
),

Why can't I scroll my list when I have carousels above it?

I created a homepage containing horizontal carousels, and under this carousel I created a vertical scrolling list,
I don't know why, but my vertical list doesn't scroll, can anyone have any idea why? I would like vertical scrolling to scroll through everything, both carousels and lists
my code:
#override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return StoreConnector<AppState, OrdersScreenProps>(
converter: (store) => mapStateToProps(store),
onInitialBuild: (props) => this.handleInitialBuild(props),
builder: (context, props) {
List<Order> data = props.listResponse.data;
bool loading = props.listResponse.loading;
Widget body;
if (loading) {
body = Center(
child: CircularProgressIndicator(),
);
} else {
body =
Container(
height: 150.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: data.length,
itemBuilder: (context, i) {
Order order = data[i];
return GestureDetector(
onTap: () {
props.getOrderDetails(order.id);
Navigator.pushNamed(context, AppRoutes.orderDetails);
},
child: Container(
margin: EdgeInsets.all(5.0),
width: 210.0,
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Positioned(
bottom: 15.0,
child: Container(
height: 120.0,
width: 200.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0.0, 2.0),
blurRadius: 6.0,
),
],
),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
order.title,
style: TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.w600,
letterSpacing: 1.2),
),
Text(
order.city,
style: TextStyle(color: Colors.grey),
)
],
),
),
),
),
],
),
),
);
},
),
),
ListView.separated(
scrollDirection: Axis.vertical,
shrinkWrap: true,
padding: const EdgeInsets.all(10.0),
itemCount: data.length,
separatorBuilder: (context, index) => Divider(),
itemBuilder: (context, i) {
Order order = data[i];
return Card(
child: ListTile(
isThreeLine: true,
contentPadding: EdgeInsets.all(25.0),
leading: CircleAvatar(
child: Icon(Icons.person),
foregroundColor: Colors.white,
backgroundColor: Colors.green),
title: Text(
order.title,
style: TextStyle(
fontSize: 24.0, fontWeight: FontWeight.bold),
),
subtitle: Text(order.city),
trailing: Icon(Icons.arrow_forward_ios),
dense: true,
onTap: () {
props.getOrderDetails(order.id);
Navigator.pushNamed(context, AppRoutes.orderDetails);
},
));
},
)
],
);
}
return Scaffold(
// resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: PreferredSize(
preferredSize: Size.fromHeight(height * 0.15),
child: AppBar(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.vertical(bottom: Radius.circular(10))),
title: Image(
image: AssetImage('assets/images/logo.png'),
height: 60.0,
),
],
),
),
body: SingleChildScrollView(child: body,),
),
);
},
);
thanks for any help in advance :)
Try adding physics: ClampingScrollPhysics() or physics: BouncingScrollPhysics() on your second/vertical ListView
Also, your Widget body contains a Container and a ListView.separated widget. Wrap it in a column like below code:
Widget body = Column(
children: <Widget>[
Container(
height: 150.0,
child: ListView.builder(
//rest of your code
),
),
ListView.builder(
physics: ClampingScrollPhysics(),
//rest of your code
),
],
);
Then add it to your Scaffold
return Scaffold(
body: SingleChildScrollView(
child: body,
),
);

Resources