Doesn't fit all content on the page Flutter - flutter

Faced a problem. My content does not fit on the page, so I added SingleChildScrollView in the TabBarLibrary. And wrapped in Expanded. As a result, I got scrolling, but also the content size greatly decreased due to Expanded, I attached a screenshot below where you can see that an empty space has appeared. How can I make the content appear on the entire page and be able to scroll?
body
Column(
children: [
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Column(
children: [
TabBarWidget(tabController: _tabController),
],
),
),
const SizedBox(height: 20),
_divider,
TabBarLibrary(
tabController: _tabController,
size: size,
),
],
);
TabBarLibrary
return Expanded(
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: widget.size.height * .69),
child: TabBarView(
controller: widget._tabController,
children: [
_tab1(),
Text('Tab2'),
Text('Tab3'),
],
),
),
),
);
}
tab1
return Column(
children: [
_divider,
const Padding(
padding: EdgeInsets.only(left: 24, top: 20),
child: Align(
alignment: Alignment.centerLeft,
//TODO dropdown
child: Text(
'DrowDown',
style: TextStyle(color: Colors.white),
),
),
)
...
without Expanded

Try remove ConstrainedBox, it limit your TabBarLibrary height.
Explain: You have already Expanded to determined height and a SingleChildScrollView inside wich want to fill there height, ConstrainedBox inside that limit the height, so content will not fill full the scrollview.

try wrap Expanded with SingleChildScrollView
return SingleChildScrollView(
child: Expanded(
child: ConstrainedBox(

Related

Stack inside column not working. What should I use instead?

I want to create this widget. The pseudocode I tried is just like this:
Column
Container (My Widget)
Column
Image
Stack
Message Text
Positioned
Status Text
Constraints:
Status must look like it stays inside the text widget. But it shouldn't be on it.
Text and image sizes are not fixed !!!
Problem: Stack inside column without size is not working. So status text appears under the text widget as centered.
return MessageBallon(
directory: message.direction,
childElement: Column(
children: [
message.hasMedia
? Container(
padding: EdgeInsets.only(bottom: height * .05),
child: CustomMedia(
src: message.media,
),
)
: const SizedBox(),
Stack(
children: [
Container(
padding: const EdgeInsets.only(
bottom: 13,
top: 18,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Container(
constraints: BoxConstraints(maxWidth: width * .53),
child: Text(
message.content,
style: TextStyles.normalTextBlack,
),
),
],
),
),
Positioned(
bottom: 0,
right: 0,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
child: Text(
message.messageDate,
style: TextStyles.detailText,
),
),
message.direction == SmsDirection.incoming
? Align(
alignment: Alignment.centerRight,
child: messageStatus,
)
: const SizedBox(),
],
),
)
],
)
],
),
);
Just use Scaffold with FloatingActionButton for your status.
Rest Image and Text can be inside a column.
You can achieve something like the below only with these widgets.

Image overflow in container

I am working on a Flutter app. There is a widget where I need to resize an image to fit in the container.
Here you have the code:
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Column(
children: [
Container(
child: Image.asset("./assets/slide3.png",)),
],
),
),
),
And here you have the output:
How can I get the image fit the container size and avoid the bottom overflowed by 117 pixels?
this is should be a comment but ok
you need to wrap Container with Expanded
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Column(
children: [
Expanded(
child: Container(child: Image.asset("./assets/slide3.png")),
),
],
),
),
),
try to use fit like this
Container(height: 200.0,child: Image.asset("./assets/slide3.png",fit: BoxFit.cover,)),

Vertically center content inside SingleChildScrollView with min height of screen height

I am trying to create a web layout that that consists of a scrollable column that has a min height of the screen height but can expand past the screen height if the content is too large. I have been able to create the scrolling container but I cannot vertically center the main content while still making the entire sections scrollable. The only working version I can get wont vertically center the content, I have to added a SizedBox above it to create padding to make it look centered but then its not responsive on different heights.
The parent of the content looks like this:
Container(
width: MediaQuery.of(context).size.width / 2,
height: double.infinity,
padding: const EdgeInsets.fromLTRB(100, 30, 100, 0),
child: SingleChildScrollView(
child: Column(
children: [
LoginLayout(),
SizedBox(height: 30),
],
),
),
),
Then to simplify the content column, its basically this:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 30),
child: Image.asset(
'assets/images/2.0x/logo-full.png',
width: 125,
fit: BoxFit.contain,
),
),
// This column needs to be vertically centered if fits in the screen height
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text('Welcome Back!', style: _textTheme.headline2),
SizedBox(height: 10),
Text('Sign in to continue', style: _textTheme.bodyText2),
SizedBox(height: 60),
EmailInput(label: 'EMAIL'),
SizedBox(height: 30),
PasswordInput(label: 'PASSWORD'),
SizedBox(height: 60),
Button(
label: 'Login',
icon: Icons.link,
theme: ButtonColor.PRIMARY,
onPressed: () {},
),
],
),
],
);
I was able to apply an Expanded widget around the centered column which did work but then I lost the ability to scroll if the content was larger that the screen height.
Here is an example for reference as well
Not sure how to do that in SingleChildScrollView though,
try using ListView with shrinkWrap: true
Container(
width: MediaQuery.of(context).size.width / 2,
height: double.infinity,
padding: const EdgeInsets.fromLTRB(100, 30, 100, 0),
child: Center(
child: ListView(
shrinkWrap: true,
children: [
LoginLayout(),
],
)
),
)

overflowing flutter columns and rows

I have this list view in flutter which I am trying to make into a chat list. Similar to what you see in WhatsApp and telegram. However I am struggling to get the idea of how rows and columns work because I keep getting overflows.
Here is the code:
ListView(
physics: BouncingScrollPhysics(),
children: [
Dismissible(
key: Key(""),
background: Container(color: Colors.grey[200]),
direction: DismissDirection.endToStart,
child: InkWell(
onTap: () {},
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flex(
direction: Axis.vertical,
children: [
Text("Hello"),
],
),
Flex(
direction: Axis.vertical,
children: [
Text(
"al;skdl;aksd a;skd ;aks;dk a;skd ;laks;d a;lsk d;lkas; dka;lsk d;laks; ldka;slk d;a",
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
],
),
],
),
),
),
],
Now we often experience the text overflow problem so if we think it that we we have provided column a particular width and restricted it but if we wrap the things up with flexible widget it now tells column/Row that you can change your size and be flexible
order would be
flexible > Container > Column/Row
The reason we are applying this to container is Column/Row will ask immediate parent for width and height
now this problem can also be solved by text overflow property that is we can clip text but what if we dont want too
So all you have to do is Wrap the column/Row in Container and then into Flexible as now it will tell container that yes you can adjust your height
Your concept can be cleared by how actually widgets parent child relationship works i.e in brief
basically If am a child I will ask my parent okay what is my size so since my parent if it has a size it will bound me but if it doesnt has a size it will ask its parent okay tell me what space should I take and it goes on. Expanded and Flexible says that okay you can adjust yourself instead of being Fixed.
Flexible(
child: Container(
margin: EdgeInsets.only(left: 10.0,right: 10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('${dataBookTitleSearch1[index]} ', style: kGoodSearchResultTextStyle, textAlign: TextAlign.left,),
SizedBox(
height: 10.0,
),
Text('${dataBookAuthorSearch1[index]}', style: kGoodSearchResultTextStyle,textAlign: TextAlign.left),
SizedBox(
height: 10.0,
),
Text('${dataBookExtensionSearch1[index]} ', style: kGoodSearchResultTextStyle,textAlign: TextAlign.left),
SizedBox(
height: 20.0,
),
Container(
width: 80.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
color: Colors.white
),
child: Padding(
padding: const EdgeInsets.only(left:20.0,top: 12.0),
child: Text('Read'),
),
),
],
),
),
)

How to adjust TextField width?

I'm re-writing a simple app which calculates averages. However, I have a hard time with a TextField. I would like it to be exactly as on a first screenshot.
The TextField's width is stretched, I don't want that. I want it to be exactly as it is on the screenshot.
Desired look:
What I have:
Code:
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
class ArithmeticAverageScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('arithmetic_average_title').tr(),
),
body: Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Card(
child: Container(
padding: EdgeInsets.symmetric(vertical: 20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(Icons.help),
title: Text('arithmetic_average_help').tr(),
subtitle: Text('arithmetic_average_help_content').tr(),
)
],
),
)
),
SizedBox(height: 16.0),
Card(
child: Container(
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text('arithmetic_average_your_grades', style: Theme.of(context).textTheme.headline5).tr(),
SizedBox(height: 16.0),
Text('arithmetic_average_grades_one_at_a_time', style: Theme.of(context).textTheme.headline6,).tr(),
SizedBox(height: 16.0),
Text('arithmetic_average_grade', style: Theme.of(context).textTheme.subtitle2).tr(),
TextField()
],
),
),
)
],
),
)
);
}
}
This will help you make generic width on all devices, so here width * 0.3 means it will take 30% of the screen width
Container(
width: MediaQuery.of(context).size.width * 0.3,
child: TextField(),
)
Use Row Widget, and put Expanded Widget as child Widget and inside that put your widgets, as Expanded will take up equal space.
return Row(
children: [
Expanded(
child: TextField();
),
Expanded(
child: Button();
)
],
);
When ever you want to play with height and width you can use the widget Container.If you want to play with a property which cannot found in the widget you are using wrap it with a widget with that property will help you.
Container(
margin: const EdgeInsets.only(right: 150),
child: new TextField(
decoration: new InputDecoration(
hintText: 'Grade',
)
)
)
You can try to wrap your TextField and Button with two Flexible widgets and apply desired proportions, e.g. 1:2 which would give you following result:
Row(
children: [
Flexible(
flex: 1,
child: TextField(),
),
Flexible(
flex: 2,
child: RaisedButton(
child: Text('Hello'), onPressed: () {}),
)
],
)
],
You can also replace the first Flexible with SizedBox and set an exact value, e.g:
Row(
children: [
SizedBox(
width: 100.0,
child: TextField(),
),
Flexible(
flex: 2,
child: RaisedButton(
child: Text('Hello'), onPressed: () {}),
)
],
)
],
TextField doesn't have an intrinsic size (width) constraint so it will always try to occupy all horizontal space. Flexible allows to constraint it to desired width in a Row.
Full example on DartPad.