Last active
August 12, 2021 18:51
-
-
Save bluenote10/907c8dbc30331e2caf9d7a06d81392ba to your computer and use it in GitHub Desktop.
Flutter: Center Positioned
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"; | |
void main() { | |
runApp(App()); | |
} | |
class App extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: "Some App", | |
theme: ThemeData( | |
primarySwatch: Colors.green, | |
), | |
home: Scaffold( | |
body: Stack(children: [ | |
Positioned( | |
left: 100, | |
top: 100, | |
child: SomeChild(text: "Some child"), | |
), | |
Positioned( | |
left: 100, | |
top: 100, | |
child: Container(width: 5, height: 5, color: Colors.red.shade900), | |
), | |
Positioned( | |
left: 100, | |
top: 150, | |
child: SomeChild(text: "Some child with longer text"), | |
), | |
Positioned( | |
left: 100, | |
top: 150, | |
child: Container(width: 5, height: 5, color: Colors.red.shade900), | |
), | |
]), | |
), | |
); | |
} | |
} | |
class SomeChild extends StatelessWidget { | |
final String text; | |
const SomeChild({Key? key, required this.text}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Text(text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment