mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-07-10 22:44:18 +08:00
57 lines
1.3 KiB
Dart
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,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|