Created
July 31, 2015 20:40
-
-
Save kasperpeulen/c6f1a9ba2a692afb6bde to your computer and use it in GitHub Desktop.
How to make your own custom material dialog in mdl.
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
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <link rel="stylesheet" href="packages/mdl/assets/styles/material.min.css"> | |
| <link rel="stylesheet" href="styles.css"> | |
| </head> | |
| <body class="mdl-upgrading"> | |
| <div class="loading">Loading...</div> | |
| <div id="wrapper" class="mdl-shadow--2dp"> | |
| <button id="customdialog" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect"> | |
| Custom dialog | |
| </button> | |
| </div> | |
| <script type="application/dart" src="main.dart"></script> | |
| </body> | |
| </html> |
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 "dart:html"; | |
| import 'package:mdl/mdl.dart'; | |
| DivElement wrapper = querySelector('#wrapper'); | |
| ButtonElement button = querySelector("#customdialog"); | |
| main() async { | |
| registerMdl(); | |
| await componentFactory().run(); | |
| CustomDialog customDialog = new CustomDialog( | |
| title: "Hello World", yesButton: "Uh... yes !", noButton: "Maybe not ?"); | |
| button.onClick.listen((_) { | |
| customDialog.show(); | |
| }); | |
| } | |
| class CustomDialog extends MaterialDialog { | |
| final String title, yesButton, noButton; | |
| CustomDialog({this.title: "", this.yesButton: 'Yes', this.noButton: 'No'}) | |
| : super(new DialogConfig()); | |
| bool get hasTitle => title.isNotEmpty; | |
| onYes() => close(MdlDialogStatus.YES); | |
| onNo() => close(MdlDialogStatus.NO); | |
| String template = """ | |
| <div class="mdl-dialog"> | |
| <div class="mdl-dialog__content"> | |
| {{#hasTitle}}<h5>{{title}}</h5>{{/hasTitle}} | |
| <p>Will this work ... ?</p> | |
| </div> | |
| <div class="mdl-dialog__actions"> | |
| <button class="mdl-button mdl-js-button" data-mdl-click="onNo()"> | |
| {{noButton}} | |
| </button> | |
| <button class="mdl-button mdl-js-button mdl-button--colored" data-mdl-click="onYes()"> | |
| {{yesButton}} | |
| </button> | |
| </div> | |
| </div>"""; | |
| } |
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
| name: mdl.mdl_MaterialDialog_DialogConfig | |
| description: | | |
| How to make your own custom material dialog in mdl. | |
| environment: | |
| sdk: '>=1.11.0 <2.0.0' | |
| dependencies: | |
| mdl: '>=1.3.2 <2.0.0' |
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
| div.loading { | |
| display: none; | |
| } | |
| body.mdl-upgrading > * { | |
| display: none; | |
| } | |
| body.mdl-upgrading div.loading { | |
| display: block; | |
| } | |
| #wrapper { | |
| width: 400px; | |
| margin: 10px auto; | |
| padding: 10px; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment