Created with <3 with dartpad.dev.
Last active
March 7, 2023 17:56
-
-
Save pratikbutani/de00ad7637984e509d2eff05ef910887 to your computer and use it in GitHub Desktop.
Dart with HTML & CSS
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
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Dart + HTML + CSS Example</title> | |
<link rel="stylesheet" type="text/css" href="styles.css"> | |
</head> | |
<body> | |
<h1>Click the button to change the color of the text!</h1> | |
<br><br> | |
<button id="colorButton">Change color</button> | |
</body> | |
</html> |
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 'dart:html'; | |
void main() { | |
var colorButton = querySelector('#colorButton'); | |
var h1 = querySelector('h1'); | |
var colors = ['red', 'green', 'blue']; | |
var currentColorIndex = 0; | |
colorButton?.onClick.listen((event) { | |
h1?.style.color = colors[currentColorIndex]; | |
currentColorIndex = (currentColorIndex + 1) % colors.length; | |
}); | |
} |
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
h1 { | |
color: black; | |
} | |
body { | |
font-family: sans-serif; | |
text-align: center; | |
margin-top: 50px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment