How to make the entire page in flutter scrollable - flutter

I want to make the entire page in flutter scrollable, while the height in each element inside remains dynamic.
Now the two Expanded elements have fixed height and are vertically scrollable - I want to make them extend to their regular height and be able to scroll down to the next element.
body: Scaffold(
body: Column(
children: <Widget>[
Text(),
IntrinsicHeight( //This is fixed height and doesn't move
child: Text(),
),
new Divider(height: 0.1),
Text(),
Expanded( //This is now vertically scrollable in its own box
child: Text()
),
Expanded( //This is now vertically scrollable in its own box
child: Text()
),
],
),
),
I tired several versions of wrapping the first column in SingleChildScrollView but for some reason it doesn't work.

Try below code hope its helpful to you. Wrap your Column() inside IntrinsicHeight() widget,
Refere IntrinsicHeight here
Refere SingleChildScrollView here, this widget is used for Scrolling the Widget..
return Scaffold(
body: SingleChildScrollView(
child: IntrinsicHeight(
child: Column(
children: <Widget>[
Text(
'Try',
),
IntrinsicHeight(
child: Text(
'Done',
),
),
new Divider(height: 0.1),
Text(
'data',
),
Expanded(
child: Text(
'Okk',
),
),
Expanded(
child: Text(
'Yes',
),
),
],
),
),
),
);

Wrap your column with a SingleChildScrollView(), so select Column than wrap it with a widget witch is SingleChildScrollView()

Wrap your Column widget using IntrinsicHeight widget. Then wrap IntrinstHeight with SingleChildScrollView.
This work fine for me
body: SingleChildScrollView(
child: IntrinsicHeight(
child: Column(
children: <Widget>[
Text("tes"),
IntrinsicHeight( //This is fixed height and doesn't move
child: Text("tes"),
),
new Divider(height: 0.1),
Text("tes"),
Expanded( //This is now vertically scrollable in its own box
child: Text("tes")
),
Expanded( //This is now vertically scrollable in its own box
child: Text("tes")
),
],
),
),
),
Note: Put the code inside Scaffold body

Related

flutter layout in singlechildscrollview

I have the below layout and want to push CustomPaints at the end of the page for any screen size, how to achieve that? I tried Spacer but got an error and tried Flexible but I don't know how to use them properly.
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
const HeaderShape(),
const SizedBox(
height: 50,
),
body,
SizedBox(
height: 150,
child: Stack(
children: [
CustomPaint(
painter: const FooterPainter1(),
child: Container(),
),
CustomPaint(
painter: const FooterPainter2(),
child: Container(),
),
],
),
),
],
),
),
);
}
You can not use spacer in a column widget, if you did not wrap your column widget with a container/sizedBox with a definite height.
Flexible widget will wrap your widget to take the available space of the parent widget, but will NOT force the child to fit the space.
Expanded will share the available space of the parent widget, and force the child widget to change its width/height to fill the available space.
So, wraping you column with a sizedbox with height and using spacer widget will help you to achieve what you are looking for. Check the code below:
SingleChildScrollView(
child: SizedBox(
height: MediaQuery.of(context).size.height -kToolbarHeight - MediaQuery.of(context).padding.top -MediaQuery.of(context).padding.bottom,
child: Column(
children: [
Container(child: Text('My Header')),
const SizedBox(
height: 50,
),
Container(child: Text('My Body')),
Spacer(),
Container(child: Text('My Footer')),
],
),
),
)
If you are not using appbar in your page, just remove kToolbarHeight and MediaQuery.of(context).padding.top from your SizedBox height parameter.

Proper text wrapping for right sided widget in a row

I have a layout as follows:
Widget1 is aligned to the left, Widget2 and the text widget - to the right.
How can I wrap the text with an ellipsis for example in case it doesn't fit into the row, as follows?
you can wrap 'Text with property...' inside ExpandedWidget.
Row(
children: [
WidgetA(),
WidgetB(),
Expanded(
child: Text("...."),
)
],
)
add your Text widget inside Expanded
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text('Atras'),
),
Expanded(
child: Text('Filtros offertos'),
),
Expanded(
child: Text('title'),
),
Expanded(
child: Text('titleasdas'),
),
Expanded(
child: Text('title'),
),
Expanded(
child: Text('titlesfsfsdf'),
),
],
),
Your result screen->

How to wrap an expanded column with another column?

I need to add padding (i.e. a space from screen edgess) for the first two widgets in a body column.
Scaffold(
body: Column(
children: [
// need to add padding for the next two widgets
Container(
child: Expanded(
child: Column(...),
),
),
Row(...),
// until here
Container(
child: Expanded(
child: Column(...
),
),
),
],
),
);
I tried to wrap them in a column again, but that gives the error:
RenderFlex children have non-zero flex but incoming height constraints
are unbounded.
I guess the problem is in wrapping the expanded column with new column. How to make that?
You need to wrap that newly created Column with another Expanded widget.
Scaffold(
child: Column(
children: [
Expanded(
child: Container(
child: Column(
children: [
Container(
child: Expanded(
child: Column(...),
),
),
Row(...),
],
),
),
),
...
margin inside Container does what you want
example
Container(
margin: EdgeInsets.only(
left: 10),
child:....
)
Bro, you need to wrap your first Column with Container first, or with SizedBox. The requirement is that you cannot set Column within unbounded Width or Height. Otherwise, it will give an error. So set it up first, and set the Expanded inside it.

How do I position a FAB in between 2 widgets in Flutter?

I want to achieve the following look:
How can I make the FAB flex-ibly positioned in between these 2 widgets? (between top profile image and bottom profile info)
I've managed to make the 2 containers, but I haven't got a clue on how to position the FAB at the exact horizontal border of them.
My code (this is the entire widget tree, wrapped in a scaffold):
Row(
children: <Widget>[
Expanded(
child: Column(
children: <Widget>[
Expanded(
flex: 4,
child: Container(
decoration: BoxDecoration(color: Colors.grey.shade300),
),
),
Expanded(
flex: 6,
child: Container(),
),
],
),
),
],
),
You can use a Stack & Positioned widget together to position the FAB as per your requirement.
Stack(
children:[
// Add your existing row & it's child here,
Positioned(
child: FloatingActionButton(
onPressed:(){ },
child: Icon(Icons.camera_alt)
),
right: 5,
top: MediaQuery.of(context).size.height * .3,
)
],
),
And the output:
Note: You may need to tweak the top value of the positioned widget to place the FAB accurately in your case. If you know the exact height of that image widget, you can set top as height - 28.

How to center content on screen and scroll if it overflows

I have as screen that is centered using:
SafeArea(
child: Column(
children: <Widget>[
Expanded(
child: Center(
child: ...,
),
),
],
),
)
But if the content is larger than the screen size, it will overflow. How can I keep the content centered, but at the same time start scrolling if it overflows?
You could use ListView widget and then put your content into it's children
Like so:
SafeArea(
child: ListView(
children: <Widget>[
Expanded(
children: <Widget>[
Center(
child: ...,
),
]
),
],
),
)
Replace your column with a ListView.
Following #Tembero's logic, I added a shrinkWraped ListView, removed the Expanded, and wrapped the ListView in a Center widget, so now it behaves exactly as expected:
SafeArea(
child: Center(
child: ListView(
shrinkWrap: true,
children: <Widget>[
Center(
child: ...
),
],
),
),
)