Skip to content

Instantly share code, notes, and snippets.

@definev
Created May 24, 2022 16:02
Show Gist options
  • Save definev/583c21e2b11d014de6ec605d53537d46 to your computer and use it in GitHub Desktop.
Save definev/583c21e2b11d014de6ec605d53537d46 to your computer and use it in GitHub Desktop.
How to center without Column
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