Skip to content

Instantly share code, notes, and snippets.

@bluenote10
Last active August 12, 2021 18:51
Show Gist options
  • Save bluenote10/907c8dbc30331e2caf9d7a06d81392ba to your computer and use it in GitHub Desktop.
Save bluenote10/907c8dbc30331e2caf9d7a06d81392ba to your computer and use it in GitHub Desktop.
Flutter: Center Positioned
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