Center 위젯
Text 위젯을 수직 및 수평으로 중앙에 배치
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text(
'Center',
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
),
),
),
);
}
}
Align 위젯
Align 위젯의 alignment 속성을 Alignment.center 로 정의한다.
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.center,
child: Text(
'Center',
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
),
),
),
);
}
}
Container 위젯
Container 위젯의 alignment 속성을 Alignment.center 로 정의한다.
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
alignment: Alignment.center,
child: const Text(
'Center',
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
),
),
),
);
}
}