Skip to content

Instantly share code, notes, and snippets.

@bwnyasse
Last active January 24, 2022 04:27
Show Gist options
  • Save bwnyasse/86473efa188d0dc9e598a84770e3fc2c to your computer and use it in GitHub Desktop.
Save bwnyasse/86473efa188d0dc9e598a84770e3fc2c to your computer and use it in GitHub Desktop.
/*
* Dart & Flutter - Training
*
* Copyright (c) Boris-Wilfried Nyasse
* All rights reserved
*
*/
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({required this.title});
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
children: <Widget>[
const Text(
'I am aligned at start',
).alignAtStart(),
Container(
height: 50,
width: 200,
color: Colors.red,
).alignAtEnd()
],
),
),
);
}
}
extension ExtendedText on Widget {
Widget alignAtStart() {
return Align(
alignment: AlignmentDirectional.centerStart,
child: this,
);
}
Widget alignAtEnd() {
return Align(
alignment: AlignmentDirectional.centerEnd,
child: this,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment