Message box doesnt expand according to the message length - flutter

I am making a chat application where the message box should expand according to the message length. This works fine for only text but i am listing a series of small images also on the message box but on this case the message box doesn't expand.
This is the code:
Column(
// crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width:100,
height:40,
child: ListView.builder(
//physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
//shrinkWrap: true,
itemCount: checkregexpression(argument['message'])
.length,
itemBuilder: (context, index) {
return checkregexpression(
argument['message'])[index] ==
'†'
? Image.asset('assets/emojis/' +
currentemoji[i++] +
'.png')
: Text(checkregexpression(
argument['message'])[index]
.toString());
},
),
),
],
)
I have used box constraint for this but listing a series of image displays the text and images on a horizontal scroll view rather than expanding accordingly. if possible an example of how to include box constraint onto a list view will also help.

Related

Auto Card Flip on Listview.builder flutter

I am trying to use a flip_card flutter package to flip items in a list view builder. I want each item flip automatically and with different random time. How can I achieve that.
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: length,
itemBuilder: (context, index) {
return FlipCard(
fill: Fill.fillBack, // Fill the back side of the card to make in the same size as the front.
direction: FlipDirection.HORIZONTAL, // default
front: Container(
child: Text('Front'),
),
back: Container(
child: Text('Back'),
),
);

Flutter - ListView.Builder with two direction scroll and unknown children size

I'm building a data list like this
List<String> list=[.....]; //a lot of data
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
controller: scrollController,
itemCount: list.length,
itemBuilder: (context, i) =>
ListTile(title: Text(list[i])))
It can scroll on vertical now but some long data will overflow on the right,so I want to add a horizontal scroll outside.
I tried many ways but it always return error such as "'constraints.hasBoundedWidth': is not true."
Code like this works fine but I have to set a width in Container first :
ListView(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children: [
Container(
width: 2000, //will return error if not set a value
child: ListView.builder(.....)
)])
Is there any way to add a horizontal scroll outside with unknown child width?
Nothing wrong in vertical list. I have run code in android studio as well.
no need to use Listview in the inner of another list view. you can wrap your title with Expanded widget, if your list title overflow on right side of screen.
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
padding: EdgeInsets.all(10),
itemCount:100,
itemBuilder: (context, i) =>
ListTile(title: Text("{$i ===}babul dshdshfdsh dfhdhfdh hbfdshhds hdfhdsvhfdsv hdsvd hdsfhdshv dhfbhdsb hdsghshdsg hdvshvv jdsfjfdbvjfdnfjbfjbfhbfbf fhbfdhbfdhbf")));
}
Below code will serve your purpose. Happy coding...
return Container(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount:10,
itemBuilder: (context, i) =>
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new Text(
"Description that is too long in text format(Here Data is coming from API Description that is too long in text format)",
style: new TextStyle(
fontSize: 16.0, color: Colors.black87,
),
),
),
),);

Nested Listview not scrolling horizontally

I have a relatively complex Listview setup, where one Listview acts as a scrolling parent of a horizontal Listview, which acts as a parent to a third vertical Listview.
Here is an image of the general idea of the layout: https://cdn.discordapp.com/attachments/752981111738466467/895739370227773480/IMG_20211007_142732.jpg.
I'm having trouble getting the middle Listview, the horizontal Listview (marked 2 in the image), to scroll.
ConstrainedBox(
constraints: BoxConstraints(...),
child: ListView.builder( // This is Listview 1
controller: ScrollController(),
itemCount: itemCount,
itemBuilder: (context, worldIndex) {
return ConstrainedBox(
constraints: BoxConstraints(...),
child: ListView.builder( // This is Listview 2
controller: ScrollController(),
itemCount: ...,
scrollDirection: Axis
.horizontal, // grows horizontally to show the hierarchy of one card (the card selected in the hierarchy above it, or for the first level, the world) to its children
itemBuilder: (context, index) {
...
return ConstrainedBox(
constraints: BoxConstraints(...),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
decoration: ...,
),
child: ListView.builder( // This is Listview 3
controller: ScrollController(),
itemCount: getNumChildren(index),
itemBuilder: (context, index2) {
return ...;
}),
)));
}));
}));
For brevity, I have removed several parts of my code and replaced them with elipses. I don't think it is likely that any of these areas could cause any issues with the Listview, but please let me know if they could.
Edit: The code I have already works properly, aside from the horizontal Listview not scrolling. My solution needs to have a dynamically expandable Listview at each level of the tree (1, 2, and 3, in the image, for example). The primary target platform for this is Windows.
I'm assuming the issue involves a problem with which Listview wins the GestureArena, but I am currently at a loss in how to work around that issue, providing a way to scroll all of available Listviews.
Thank you in advance, and I hope you have a great day!
As I could understand it. Maybe you are looking for something like this? I have commented the 3 types of scrolls you need. If anything is not as expected, please mention.
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
for (var i = 0; i < 5; i++)
// One big section in the largest col (1).
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 200.0,
child: ListView.builder(
// Horizontal item builder. (2)
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: 10,
itemBuilder: (context, index) {
return SingleChildScrollView(
child: Column(
// Inside one vertical section. (3)
children: [
for (var i = 0; i < 5; i++)
ElevatedButton(
onPressed: () {}, child: Text("OK")),
],
),
);
},
),
),
],
),
],
),
),
),
),
);
}
The solution to this turned out to be that Flutter has intentionally turned off the ability to scroll horizontally using both scroll wheel and dragging for Windows (or at least, that's what seems to be the case according to what I was able to find in this issue).
To solve that, they have made a migration guide here.
Following the guide, it is extremely simple to override the drag devices used in order to re-enable the intended drag scrolling. This still does not enable scrolling horizontally with a mouse wheel, but for my code that is not an issue.
class CustomScrollBehavior extends MaterialScrollBehavior { // A custom scroll behavior allows setting whichever input device types that we want, and in this case, we want mouse and touch support.
#override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
};
}
Then, in the actual Listview's code, we set a ScrollConfiguration with this new class as its behavior.
ScrollConfiguration(
behavior: CustomScrollBehavior(),
child: Listview.Builder(
controller: ScrollController(),
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
...
})

Flutter: How does one generate Raisedbuttons from a list horizontally?

I'm having this issue where I have a list of options that I want to display within the same row. This piece of code generates the buttons I want, but each button takes up the entire row. This makes it so that the buttons are stacked vertically instead of horizontally. Help?
Container(child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Row(children: <Widget>[
Flexible(
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: this.item.sizes.length,
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return _sizeButton(index);
},
),
),
],
/* SOME OTHER WIDGETS */
],
),
);
Try to replace Row+Flexible with Expanded.
As mentioned, use scrollDirection: Axis.horizontal too.
https://dartpad.dartlang.org/ec28750de6310c2b4d397250aa9e22d1
The default behavior for a ListView is to put its items in a vertical list, whereby each item takes up one row. Use scrollDirection: Axis.horizontal, to put the items next to another horizontally.
Have you tried to add
scrollDirection = Axis.horizontal
in ListView.builder

FloatingActionButton over last item of list

I have a scrollable list with a FloatingActionButton. I would like to make the list to finish before the FloatingActionButton because last item of list isn't visible anymore(FloatingActionButton it's over list item)
return Scaffold(
body: ListView(
scrollDirection: Axis.vertical,
controller: _scrollController,
shrinkWrap: true,
children: <Widget>[
_buildUpcomingExpansionTileEvents(myUpcomingEvents),
_buildPastExpansionTileEvents(myPastEvents),
],
),
floatingActionButton: UnicornDialer(
parentButtonBackground: Colors.blue,
orientation: UnicornOrientation.VERTICAL,
parentButton: Icon(OMIcons.add),
childButtons: childButtons,
),
);
How could I change my list to finish with one empty item? Or what's the best solution to this problem?
FloatingActionButton has size of 56 for non-mini and 40 for mini, so what you can do is use padding in ListView like:
ListView(
padding: EdgeInsets.only(bottom: 56), // if you have non-mini FAB else use 40
// ...
),
To solve this I just add a sized box as the last element in the list. That way you still get the end of list highlight in the correct place when the user scrolls to the bottom of the list.
ListView(
scrollDirection: Axis.vertical,
controller: _scrollController,
shrinkWrap: true,
children: <Widget>[
_buildUpcomingExpansionTileEvents(myUpcomingEvents),
_buildPastExpansionTileEvents(myPastEvents),
SizedBox(
height: 100, // or whatever height works for your design
),
],
),