Skip to content

Instantly share code, notes, and snippets.

@5omar5
Created March 29, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5omar5/40a3feee618f3da88f0c635da4ccc721 to your computer and use it in GitHub Desktop.
Save 5omar5/40a3feee618f3da88f0c635da4ccc721 to your computer and use it in GitHub Desktop.
u3_a1
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