I have a Container
with some widgets in it. I don't want to give this Container
a specific size, I just want it to wrap around the elements in it.
I know that you can use crossAxisAlignment
on a Column
to align its elements to the left, center or right, but I want to do this for only one specific element. I already tried using the Align
widget, but then the Container width expands to the width of the screen which I don't want. I want the title and subtitle 1 to be centered, and I want subtitle 2 to be constrained to the left. How do I do this?
Here is my code:
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
final textTheme = theme.textTheme;
return Scaffold(
body: Center(
child: Container(
padding: const EdgeInsets.all(48),
decoration: BoxDecoration(
color: colorScheme.surface,
borderRadius: BorderRadius.circular(2),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'This is the title text',
style: textTheme.displayMedium,
),
const SizedBox(height: 16),
Text(
'Subtitle 1',
style: textTheme.bodyLarge,
),
Text('Subtitle 2'),
],
),
),
),
);
}
}