When specifying a ColumnWidget as the child property of an AlignWidget, the Alignment’s [Y] doesn’t work.
When specifying the mainAxisAlignment of a ColumnWidget, you can set the Alignment for [Y] as center, top, or bottom, but you cannot specify it using numbers (e.g., Alignment(0.0, 0.3)), which limits the ability to make fine-grained adjustments.
Sample Code
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: MyHomePage());
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Align(
alignment: const Alignment(0.0, 0.0), // [Y] Not Working
child: Column(
children: [
Container(
height: 50,
width: 50,
color: Colors.amber,
),
],
)),
);
}
}
How can I specify fine-grained Alignment like Alignment(0.0, 0.3) within a ColumnWidget? Or is this a limitation of Flutter?
2
Answers
The default
mainAxisSize:MainAxisSize.max
on Column. means It will take as much height(constraints) as possible. You can setmainAxisSize:MainAxisSize.min
.More about ui/layout/constraints.
Try this code: