Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. void main() {
  3. runApp(MaterialApp(
  4. home: MyButton(),
  5. ));
  6. }
  7. class MyButton extends StatefulWidget {
  8. @override
  9. MyButtonState createState() => MyButtonState();
  10. }
  11. class MyButtonState extends State<MyButton> {
  12. int counter = 0;
  13. List<String> strings = ['México', 'lindo', 'y', "qurerido"];
  14. String displayedString = "Hello World!";
  15. void onPressOfButton() {
  16. setState(() {
  17. displayedString = strings[counter];
  18. counter = counter < 3 ? counter + 1 : 0;
  19. });
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return Scaffold(
  24. appBar: AppBar(
  25. title: Text("Stateful Widget"),
  26. backgroundColor: Colors.green,
  27. ),
  28. body: Container(
  29. child: Center(
  30. child: Column(
  31. mainAxisAlignment: MainAxisAlignment.center,
  32. children: <Widget>[
  33. Text(displayedString, style: TextStyle(fontSize: 40.0)),
  34. Padding(padding: EdgeInsets.all(10.0)),
  35. RaisedButton(
  36. child: Text(
  37. "Press me",
  38. style: TextStyle(color: Colors.teal),
  39. ),
  40. color: Colors.blue,
  41. onPressed: onPressOfButton,
  42. )
  43. ],
  44. ),
  45. ),
  46. ),
  47. );
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement