Created
June 24, 2021 22:43
-
-
Save HansMuller/3ed98084842e989392d066568322a05a to your computer and use it in GitHub Desktop.
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'; | |
class Home extends StatefulWidget { | |
const Home({ Key? key }) : super(key: key); | |
@override | |
_HomeState createState() => _HomeState(); | |
} | |
class _HomeState extends State<Home> { | |
MainAxisAlignment? _alignment; | |
@override | |
Widget build(BuildContext context) { | |
const List<MainAxisAlignment?> alignments = <MainAxisAlignment?>[ | |
null, | |
MainAxisAlignment.start, | |
MainAxisAlignment.center, | |
MainAxisAlignment.end, | |
MainAxisAlignment.spaceBetween, | |
MainAxisAlignment.spaceAround, | |
MainAxisAlignment.spaceEvenly, | |
]; | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('AlertDialog actionsAlignment'), | |
actions: <Widget>[ | |
PopupMenuButton<MainAxisAlignment?>( | |
child: Padding( | |
padding: EdgeInsetsDirectional.only(end: 8), | |
child: Icon(Icons.menu) | |
), | |
onSelected: (MainAxisAlignment? result) { | |
setState(() { _alignment = result; }); | |
}, | |
itemBuilder: (BuildContext context) { | |
return alignments.map((MainAxisAlignment? alignment) { | |
return PopupMenuItem<MainAxisAlignment?>( | |
value: alignment, | |
child: Text(alignment == null ? 'default' : '$alignment'.substring(18)), | |
); | |
}).toList(); | |
}, | |
), | |
], | |
), | |
body: AlertDialog( | |
actionsAlignment: _alignment, | |
title: Text('AlertDialog: $_alignment'), | |
content: SingleChildScrollView( | |
child: ListBody( | |
children: <Widget>[ | |
Text('This is an AlertDialog.'), | |
SizedBox(height: 8), | |
Text('Select different values for actionsAlignment'), | |
Text('from the AppBar dropdown menu on the right.'), | |
], | |
), | |
), | |
actions: <String>['One', 'Two', 'Free', 'Four'].map<Widget>((String text) { | |
return TextButton( | |
child: Text(text), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
); | |
}).toList(), | |
), | |
); | |
} | |
} | |
void main() { | |
runApp(MaterialApp( | |
home: Home(), | |
// The "DEBUG" banner obscures the menu button. | |
debugShowCheckedModeBanner: false, | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment