Flutter – Center Align Application Bar Title
To center align text of App Bar title, use Scaffold and in appBar, set the centerTitle property to true.
Following is a quick code snippet to align title at the center of application bar.
Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
'Flutter Tutorial',
),
),
centerTitle: true
sets the text in title at center.
Example 1: Center Align Title in App Bar
Create a Flutter application and replace the code of main.dart with the following code.
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Flutter Tutorial',
home: MyApp(),
debugShowCheckedModeBanner: false,
));
}
class MyApp extends StatefulWidget {
@override
_State createState() => _State();
}
class _State extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(
'Flutter Tutorial',
),
),
body: Container(),
);
}
}
Run this application in an Android or Apple device.
Screenshot
Summary
In this Flutter Tutorial, we learned how to align app bar title at center.