Using showDialog(...builder: ...), I am unable to size the content of SomeWidget.
What is happening
No matter what widgets I try to insert into the builder I cannot control sizing.
showDialog(context: context, builder: (context) => Container(
color: Colors.white,
width: 10.0,
height: 10.0,
));
No matter which values I insert into width and height, the dialog always displays full screen. The Container in this case will take up all available space. The code I posted above will result in the following:
Full size screenshot showing an Android screen, where everything except for the navigation bar, status bar and debug tag is filled out with white. (the SafeArea you can see comes from here)
Padding
Doing the same but surrounding it with a Padding and applying padding will work as sizing. Applying padding will remove parts from the side of the Container. This is the only successful way I have come up with. E.g. SizedBox or ConstrainedBox do not make a difference.
What I would like to see
Both CupertinoAlertDialog and Material AlertDialog can be inserted as a widget to the builder of showDialog and will not fill up the whole screen.
I tried figuring out what those two widgets are doing differently than me, but to me it looks like they are also using Container sizing or ConstrainedBox as sizing, which both did not work for me.
The problem is: Size itself is not enough of an information to actually render it on screen.
Flutter needs a way to know how to align that 10x10 box inside the screen.
A Center should do the trick:
showDialog(
builder: (context) {
return Center(
child: Container(),
)
}
)
AlertDialog and similar do the same for you implicitly.
You need to wrap the Container Widget with Center Widget.
Updated Code :
showDialog(
context: context,
builder: (context) => Center(
child: Container(
color: Colors.white,
width: 10.0,
height: 10.0,
),
),
);
Related
The top section can grow and shrink based on data coming from server, the middle section is map and takes whole height available while keeping some space for a button. Any ideas how can I achieve this?
You can use Column combined with Expanded
Column(
children: [
Text('Top'),
Expanded(child: Container(color: Colors.red)),
Text('bottom'),
],
)
I dont really understand what you want but If you want to show data no matter the size of the data you wanted the show
you can use SingleChildScrollView
return SingleChildScrollView(
child: YourGrowAbleWidgetHere()
),
able the scroll
I'm making layout inside the ListView with Stack widget, but the problem is the position. Everytime I add another widget, it's always started at the TopLeft. That's why i used Symmetrical Padding. At first, it still easy, but after three widgets, i feel it's really troublesome to use Symmetrical Padding with height more than 255.0
Padding(
padding: const EdgeInsets.symmetric(vertical: 235.0)),
And, this is the short version of my layout code:
return AnimatedBuilder{
builder: (BuildContext context, Widget child) {
return Scaffold(
//BODY
body: ListView(
children: <Widget>[
new Container(
child: new Stack(
children: <Widget>[
//THE WIDGET
new Container(),
new Transform(),
new FadeTransition(),
new FadeTransition(),
new Text(),
Any help would greatly appreciated!
The Answer is in your Question Title - Use Positioned Widget for positioning widget under Stack
Now this Widget is Specifically Designed to use under Stack.
As Per Documentation:
A Positioned widget must be a descendant of a Stack, and the path from the Positioned widget to its enclosing Stack must contain only StatelessWidgets or StatefulWidgets (not other kinds of widgets, like RenderObjectWidgets).
If a widget is wrapped in a Positioned, then it is a positioned widget in its Stack. If the top property is non-null, the top edge of this child will be positioned top layout units from the top of the stack widget. The right, bottom, and left properties work analogously.
Here's my problem:
How can I create a card for each item where I don't have to worry about the number of Fields that will be on each Item without Overflowing?
From what I understand the card in this case is a square box.
Overflow errors on the UI are usually occurs when the children inside the widget exceeds their parent's dimension, unless the children inside the parent widget was wrapped with a Scrollable. A workaround that you can apply here is by using IntrinsicHeight as a parent widget to dynamically adjust its dimension base from its child widget, and use ConstrainedBox as IntrinsicHeight widget's child to set a minimum dimension for the items.
IntrinsicHeight(
child: ConstrainedBox(
constraints: const BoxConstraints(
/// Set minimum height for the item
minHeight: 100,
),
/// child widget with dynamic height goes here
child: Container(),
),
),
Or if you're looking for a staggered Grid, there's a plugin for this use case: flutter_staggered_grid_view
How can I achieve the multi-Line view on Text and Multi-Line TextField that can auto size the container at the bottom.
Edit:And align them properly
You have this in the following question:
Is there a way to dynamically change the Flutter TextField's maxLines?
Set this on your code:
new TextField(
maxLines: null,
keyboardType: TextInputType.multiline,
);
I was trying to make the TextInput to be auto scaling, that is, the height of the TextInput increases as the text is wrapped to next line.
So I'm trying to calculate the width of the text, and compare it width the width of the TextInput. If it's greater than the width, the height of the TextInput will increase.
So my question is how to calculate the width of the text?
Are there any other ways to accomplish the auto scaling effect?
Thanks!
Currently there is no easy way to get the inner content width of a TextInput.
React Native is badly in need of an autosizing text input like the one you describe. I could use one also, so when I find time I may try to write one.
In the meantime, here's a workaround for accomplishing what you describe:
Create your TextInput with its initial (fixed) height.
Create a cloned <Text> element somewhere offscreen (e.g. use absolute position) with the same style as the TextInput. This is easy to do thanks to the declarative nature of React's style attribute. Set the width to the same width as your TextInput.
If your TextInput has responsive width, you may want to look at onLayout, or measure to get the width, otherwise there are ways to automatically render the clone with the same width (e.g. place it in the same container but offscreen).
Write an onChange handler for the TextInput which:
(a) Updates the clone's any time the TextInput text changes
(b) Measures the height of the clone (since <Text> elements autosize)
(c) Sets the new height of the Textinput
Although this is kind of a pain, you only have to write it once. It can easily be encapsulated into a component (e.g. ) which you can then re-use with impunity.
Though I'm not answering the question asked, I want to point out that the auto-scaling TextInput can be easily implemented in React Native 0.34.
class AutoScaleTextInput extends React.Component {
constructor() {
super();
this.state = {
inputHeight: 35
};
}
render() {
return (
<TextInput
multiline={true}
style={{
height: this.state.inputHeight
}}
onContentSizeChange={ this._onTextContentSizeChange }/>
);
}
_onTextContentSizeChange = (event) => {
this.setState({
inputHeight: Math.min(event.nativeEvent.contentSize.height, 100)
});
}
}
See: TextInput#onContentSizeChange
Expo Snack example https://snack.expo.io/HkqE2AhAe