Say there is a Scaffold with a bottomNavigationBar property that is populated. If you use a Stack with a Align widget inside its body set to Alignment.center, the Align widget gets centered accounting to the bottomNavigationBar and centers in the remaining space minus that.
How do I get it so that it centers according to the total screen height, using all these widgets?
Stack(
body: Align widget with center alignment and some child,
bottomNavigationBar: Bottom app bar
)
I'm not entirely sure what you mean in your question - but I think you want the body of a Scaffold (not Stack) to center a widget for the whole height available on the device.
Here's how you could do that using a Scaffold, SizedBox and Center widgets along with a MediaQuery
Scaffold(
body: SizedBox(
height: MediaQuery.of(context).size.height,
child: Center(
child: Text("CENTERED")),
),
bottomNavigationBar: BottomNavigationBar(items: []),
)
Scaffold
Sized Box
Center
Media Query
Hopefully that puts you on the right path.
Related
Please refer to the Widget Text("HERE") and corresponding ScreenShot below.
When a keyboard appears from the bottom of device, the Widget Text("HERE") relatively moved to upper-side, hence I should care about overflow of whole widget size as well as size of user devices.
How can I locate this Widget absolutely, or should I always make all things (widget) scrollable to corresponds to any devices and also to avoid overflow problem ?
Stack(
children:[
,//omit
const Align(
alignment: Alignment.bottomCenter,
child: Text("HERE"),
)
]
)
first, make sure you constrained your Scaffold widget to the full-screen height, with MediaQuery:
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
),
child: Scaffold(// your screen code),
),
then wrap your Text with a Positioned widget, then set the bottom property to 0 or the value you want to bottom with:
// ...
child: Stack(
children:[
Positioned(
bottom: 0,
child: Text("HERE"),
)
]
)
now even the keyboard is on, the screen will not resize and the Text widget will stay forcelly in the bottom of screen.
just add this line in Scaffold
Scaffold(
...
resizeToAvoidBottomInset : ture
);
hope it helps :)
I have a widget tree that has a variable height.
I need to create another widget that will be on top of it under certain circumstances.
I need this other widget to take up the full height of the stack, depending on the first widget's height.
So it goes like this:
Stack(
children[
Widget2(),
SomeVariableHeighWidget1()
],
)
I've tried wrapping Widget2 in IntrinsicHeight, for example
Widget2 = IntrinsicHeight(
child: Container(
color: Colors.green,
),
),
but I see nothing. If I set a fixed height to the Container I can see it, and it does take up the full width, but I can't get it to take up the full height. I also tried Expanded but it is incorrect use of parent data widget.
Thank you
Hello there i got some troubles when i add a SingleChildScrollView on Column in the body of Scaffold widget i got full white Screein Please help
photos
https://pasteboard.co/K3Diclo.png
https://pasteboard.co/K3Diclo.png
whem i wrap it to SingleChildScrollView
i got a white screen (and lose my appbar)
Wrap your Column with a SingleChildScrollView.
Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
// Your items
],
),
),
);
I want to create a scrollable content which include:
A header widget that includes several child widgets - which it's height is unknown
A list of rows widgets
The correct way to do that is using a CustomScrollView, like this:
Widget _buildView(BuildContext context) {
return (
slivers: <Widget>[
SliverToBoxAdapter(
child: Container(
height: 128.0,
child: _buildHeader(context),
),
),
_buildList(context),
],
);
}
My problem is that my unlike this code sample, my header's height is unknown, and should fit its children's height (which can change).
How do I achieve that?
Since the Sliver needs to adapt on the header's height, you can consider using ConstrainedBox on your header. Depending on your use case, you can set a minHeight and maxHeight to let the viewport know the widget's size to be rendered.
I need to make animation like Hero in two different widgets. Is that possible?
Widget a with image a and widget b with image a but widget a is inside a listview and widget b is full screen image(it hide listview)
It's very simple. You just need to wrap both widgets in a Hero widget using the same TAG property value. The snippet below is assuming you've a Image in a ListTile and after user clicks you show a new page with the same image but that image will be animated by Hero widget.
In list page the list items can be
ListTile(
leading: Hero(
tag: IMAGE_TAG, // must be the same in different pages
child: Image(image: AssetImage('you_asset_dir/yourImage.png')),
),
title: Text('Anything'),
onTap: () => // Just go to full screen page
);
In full screen page
Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Hero(
tag: 'IMAGE_TAG', // must be the SAME VALUE DEFINED IN list tile hero child widget.
child: Image(image: AssetImage('you_asset_dir/yourImage.png')),
),
),
);
OBS: The Hero tag property must be the same in different contexts but if you have a list with many items using Hero widget each Hero int the same context/page must have different tag values.
To deep dive concepts about Hero animations check the official doc