Files
2019-07-23 03:42:56 +02:00

57 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MyButton(),
));
}
class MyButton extends StatefulWidget {
@override
MyButtonState createState() {
return MyButtonState();
}
}
class MyButtonState extends State<MyButton> {
int counter = 0;
List<String> strings = ['Flutter', 'is', 'cool', "and","awesome!"];
String displayedString = "Hello World!";
void onPressOfButton() {
setState(() {
displayedString = strings[counter];
counter = counter < 4 ? 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.white),
),
color: Colors.red,
onPressed: onPressOfButton,
)
],
),
),
),
);
}
}