Created
March 29, 2020 19:44
-
-
Save 5omar5/40a3feee618f3da88f0c635da4ccc721 to your computer and use it in GitHub Desktop.
u3_a1
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'; | |
void main() { | |
runApp(MaterialApp( | |
home: MyButton(), | |
)); | |
} | |
class MyButton extends StatefulWidget { | |
@override | |
MyButtonState createState() => MyButtonState(); | |
} | |
class MyButtonState extends State<MyButton> { | |
int counter = 0; | |
List<String> strings = ['Estoy', 'aprendiendo', 'Flutter']; | |
String displayedString = "Hello World!"; | |
void onPressOfButton() { | |
setState(() { | |
displayedString = strings[counter]; | |
counter = counter < 2 ? counter + 1 : 0; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Stateful Widget"), | |
backgroundColor: Colors.green, | |
), | |
body: Container( | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text(displayedString, style: TextStyle(fontSize: 40.0)), | |
Padding(padding: EdgeInsets.all(10.0)), | |
RaisedButton( | |
child: Text( | |
"Press me", | |
style: TextStyle(color: Colors.black), | |
), | |
color: Colors.blue, | |
onPressed: onPressOfButton, | |
) | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment