Created
October 8, 2020 04:11
-
-
Save granoeste/0e0fcb6f9ebeb89a7f4011d5ccc797cb to your computer and use it in GitHub Desktop.
Custom Dialog Demo
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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Custom Dialog Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Custom Dialog Demo'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
void _showDialog() { | |
var height = MediaQuery.of(context).size.height; | |
var width = MediaQuery.of(context).size.width; | |
var minWidth = (width > 720 ? width * 0.50 : width * 0.70); | |
showDialog( | |
context: context, | |
builder: (_) => SimpleDialog( | |
contentPadding: | |
EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0), | |
children: <Widget>[ | |
CircleAvatar( | |
child: Icon(Icons.alarm, size: 48.0), minRadius: 36.0), | |
SizedBox(height: 8.0), | |
ConstrainedBox( | |
constraints: BoxConstraints( | |
minWidth: minWidth, | |
), | |
child: Column( | |
children: [ | |
Text('TitleTitleTitleTitleTitle', | |
style: Theme.of(context).textTheme.headline5), | |
SizedBox(height: 8.0), | |
Text( | |
'DescriptionDescriptionDescriptionDescriptionDescriptionDescription', | |
style: Theme.of(context).textTheme.bodyText1, | |
), | |
SizedBox(height: 8.0), | |
Container( | |
padding: EdgeInsets.all(8.0), | |
width: 200.0, | |
color: Colors.lightBlue, | |
child: Column( | |
children: [ | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
SizedBox(width: 100.0, child: Text('height:')), | |
Expanded( | |
child: Text('$height', | |
textAlign: TextAlign.right), | |
), | |
], | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
SizedBox(width: 100.0, child: Text('width:')), | |
Expanded( | |
child: Text('$width', | |
textAlign: TextAlign.right), | |
), | |
], | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
SizedBox( | |
width: 100.0, child: Text('minWidth:')), | |
Expanded( | |
child: Text('${minWidth.toStringAsFixed(1)}', | |
textAlign: TextAlign.right), | |
), | |
], | |
), | |
], | |
), | |
), | |
SizedBox(height: 8.0), | |
Text( | |
'AnnotationAnnotation', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
RaisedButton( | |
onPressed: () {}, | |
child: Text('OK'), | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.all(Radius.circular(45.0)), | |
), | |
), | |
], | |
), | |
), | |
], | |
)); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text(widget.title)), | |
body: Container(), | |
floatingActionButton: FloatingActionButton( | |
onPressed: _showDialog, | |
tooltip: 'ShowDialog', | |
child: Icon(Icons.send), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment