Center widget is used to center its child widget within the available space. The Center widget takes a single child and positions it at the center of its parent widget.
There Are Some Common Attributes for Center
File open lib->main.dart file −
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('Center Example',
style:TextStyle(fontSize: 20,color: Colors.white)),
),
body: MyApp(),
),
)
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return
Center(
child: Padding(
padding: EdgeInsets.only(top: 10.0,bottom: 10.0,left: 10.0,right: 10.0),
// padding: EdgeInsets.all(10),
child: Container(
alignment: Alignment.center,
child: Text("Micro Tutorial",
style:TextStyle(fontSize: 20,color: Colors.red),
)
)
)
);
}
}
Open
Device Manager, run the emulator, and then run the application. Next,
check the working output and check the output you declared in your
code.