Center
為 Layout Widget,可將內層 Widget 水平垂直置中
。
Version
Flutter 3.24
Flutter
Hello World
在頁面水平垂直置中
Home
home.dart
import 'package:flutter/material.dart';
class Home extends StatelessWidget {
const Home({super.key});
Widget build(BuildContext context) {
return const Scaffold(
body:
Center(child: Text(style: TextStyle(fontSize: 30), 'Hello World')));
}
}
- 定義
Home
page
Line 6
build(BuildContext context) {
return const Scaffold(
body:
Center(child: Text(style: TextStyle(fontSize: 30), 'Hello World')));
}
Widget
Center
:將內層 widget 垂直水平置中child
:設定內層 widget
Conclusion
Center
可簡單將內層 widget 垂直水平置中,且不受長寬限制