Created
June 22, 2021 17:46
-
-
Save HansMuller/f59cf26b6bdb2523b2a6bf8e6ab1482a to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
| class DemoRow extends StatelessWidget { | |
| DemoRow(this.alignment); | |
| final MainAxisAlignment alignment; | |
| @override | |
| Widget build(BuildContext context) { | |
| const List<Widget> items = <Widget>[ | |
| Text('One'), | |
| Text('Two'), | |
| Text('Free'), | |
| Text('Four'), | |
| ]; | |
| final Color backgroundColor = Directionality.of(context) == TextDirection.ltr ? Colors.green : Colors.yellow; | |
| return Padding( | |
| padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16), | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| children: <Widget>[ | |
| Container( | |
| color: backgroundColor.withOpacity(0.15), | |
| child: Row(children: items, mainAxisAlignment: alignment), | |
| ), | |
| Container( | |
| color: backgroundColor.withOpacity(0.25), | |
| child: OverflowBar(children: items, alignment: alignment), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } | |
| class AlignmentDemo extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: SingleChildScrollView( | |
| child: Column( | |
| children: <Widget>[ | |
| Directionality( | |
| textDirection: TextDirection.ltr, | |
| child: Column( | |
| children: <Widget>[ | |
| DemoRow(MainAxisAlignment.start), | |
| DemoRow(MainAxisAlignment.center), | |
| DemoRow(MainAxisAlignment.end), | |
| DemoRow(MainAxisAlignment.spaceAround), | |
| DemoRow(MainAxisAlignment.spaceBetween), | |
| DemoRow(MainAxisAlignment.spaceEvenly), | |
| ], | |
| ), | |
| ), | |
| Directionality( | |
| textDirection: TextDirection.rtl, | |
| child: Column( | |
| children: <Widget>[ | |
| DemoRow(MainAxisAlignment.start), | |
| DemoRow(MainAxisAlignment.center), | |
| DemoRow(MainAxisAlignment.end), | |
| DemoRow(MainAxisAlignment.spaceBetween), | |
| DemoRow(MainAxisAlignment.spaceAround), | |
| DemoRow(MainAxisAlignment.spaceEvenly), | |
| ], | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| void main() { | |
| runApp(MaterialApp(home: AlignmentDemo())); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment