Based on the Flutter Docs,
... This widget will be as big as possible if its dimensions are constrained and widthFactor and heightFactor are null. If a dimension is unconstrained and the corresponding size factor is null then the widget will match its child's size in that dimension. ...
Dummy code:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: LoginPage(),
);
}
}
class LoginPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
//height: 100,
child: Column(
children: <Widget>[
Center(
child: Text('Logo'),
),
],
),
),
),
);
}
}
Output: It simply prints "Logo" that is centered horizontally BUT not vertically.
This obeys the docs, "If a dimension is unconstrained ... match its child's size". In this case, Column has unbounded vertical constrains thus Center's incoming constraints are also unbounded. Thus Center matches height of Text widget and isn't centered vertically.
Dummy code(with comment uncommented):
We run the exact same code but with the //height: 100, being uncommented.
What I thought should happen: Since now vertical dimension is constrained, I thought "Logo" would be both vertically and horizontally centered.
Actual output: Same output as previous dummy code.
Question: Why does this happen? According to the docs: "widget will be as big as possible ... are null" so shouldn't the Center widget be big as possible and center the child vertically and horizontally.
Sidenote: I only get the expected behavior of being centered horizontally and vertically if I remove the Column widget