Created
May 24, 2022 16:02
-
-
Save definev/583c21e2b11d014de6ec605d53537d46 to your computer and use it in GitHub Desktop.
How to center without Column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
main() { | |
runApp( | |
const MaterialApp( | |
home: Scaffold( | |
body: Center( | |
child: SizedBox( | |
height: 50, | |
child: DecoratedBox( | |
decoration: BoxDecoration( | |
color: Colors.blue, | |
), | |
child: Padding( | |
padding: EdgeInsets.symmetric(horizontal: 50), | |
// center this vertically | |
// while preserving the width | |
// without using Row or Column | |
child: IntrinsicWidth(child: Center(child: Text('Foo'))), | |
), | |
), | |
), | |
), | |
), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment