Issue
The title of my ListTile
isn't centered horizontally with respect to my browser's window:
.
Steps to reproduce the issue
main.dart
with what followsimport 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ListView(
children: [ListTile(title: Center(child: Text('Hello World!')))],
),
),
),
);
}
}
What I've tried and didn't work
Text
's textAlign
to TextAlign.center
, whether the Text
itself is wrapped in a Center
or notAlign
ListTile(
title: Align(
alignment: Alignment.center,
child: Text('Hello World!'),
)
),
Row
:ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [Text('Hello World!')],
),
),
Environment
Chrome 138.0.7204.169
Flutter 3.32.6
MacBook Air M1 8GB
macOS 15.5
ListTile
adds leading and trailing padding. Remove the default padding insets by setting the contentPadding
property to zero.
Code:
ListTile(
title: Center(
child: Text('Hello World!')
),
contentPadding: EdgeInsets.zero, // set content padding to zero
)