View Height Problems (Continued)

Make body have 100% of the browser height

Try setting the height of the html element to 100% as well.

html, 
body {
height: 100%;
}

Body looks to its parent (HTML) for how to scale the dynamic property, so the HTML element needs to have its height set as well.

However the content of body will probably need to change dynamically.
Setting min-height to 100% will accomplish this goal.

html {
height: 100%;
}
body {
min-height: 100%;
}

Cannot set dynamic height for TabBarView in flutter

I have fixed this issue by changing SingleChildScrollView into ListView and writing my own TabView widget which contains tabs in Stack wrapper.

Top level widget body wrappers changed from Column and SingleChildScrollView to ListView:

  Widget build(BuildContext context) {
SizeConfig().init(context);
return Scaffold(
appBar: RestaurantInfoAppBar(),
body: ListView(
children: <Widget>[Description(), Tabs()],
),
);
}

Tabs widget - removed Container with a static width wrapper:

  Widget build(BuildContext context) {
return DefaultTabController(
length: _tabs.length,
child: Column(
children: <Widget>[
TabBar(
labelColor: PickColors.black,
indicatorSize: TabBarIndicatorSize.tab,
tabs: _tabs,
),
TabsView(
tabIndex: _tabIndex,
firstTab: MenuTab(),
secondTab: ReviewsTab(),
)
],
));
}

New custom TabsView component currently handles only two tabs (since I only need two) but can be easily changed to handle dynamic numbers of tabs:

class TabsView extends StatelessWidget {
TabsView(
{Key key,
@required this.tabIndex,
@required this.firstTab,
@required this.secondTab})
: super(key: key);

final int tabIndex;
final Widget firstTab;
final Widget secondTab;

@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
AnimatedContainer(
child: firstTab,
width: SizeConfig.screenWidth,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
transform: Matrix4.translationValues(
tabIndex == 0 ? 0 : -SizeConfig.screenWidth, 0, 0),
duration: Duration(milliseconds: 300),
curve: Curves.easeIn,
),
AnimatedContainer(
child: secondTab,
width: SizeConfig.screenWidth,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
transform: Matrix4.translationValues(
tabIndex == 1 ? 0 : SizeConfig.screenWidth, 0, 0),
duration: Duration(milliseconds: 300),
curve: Curves.easeIn,
)
],
);
}
}

P.S. SizeConfig is the same as MediaQuery.of(context).size.width.

Hope this helps someone like me! :)

How to solve Layout issues with nested StackViews?

Here is a layout that does not generate any layout warnings / ambiguities:

Sample Image

The stack views' properties are set as follows:

Sample Image

Sample Image

Sample Image

I designed one "Row Stack" in the Vertical "Outer Stack" and then just duplicated it 3 times.

Here is how it looks at run-time (labels have background colors to make it easy to see their frames):

Sample Image

and with the label backgrounds set to clear:

Sample Image

How to use Auto Height and Scroll View at the same time in iOS?

You need two height constraints - The aspect ratio constraint that you already have, plus a second height constraint of >= 40.

Set the priority of the aspect ratio constraint to a lower value than the new height constraint. E.g. Set the aspect ratio constraint to 750 and leave the new height constraint at the default of 1000.

With this set of constraints the minimum height of the view will be 40 (set by the required constraint) but can be greater (if set by the aspect ratio constraint). The different priorities avoids a conflicting constraints warning.



Related Topics



Leave a reply



Submit