mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-06-13 09:57:31 +08:00
implemented stateful_widget example
This commit is contained in:
stateful_widget
.gitignoreREADME.md
android
.gitignore
app
build.gradle
build.gradlesrc/main
AndroidManifest.xml
java/com/yourcompany/statefulwidget
res
mipmap-hdpi
mipmap-mdpi
mipmap-xhdpi
mipmap-xxhdpi
mipmap-xxxhdpi
gradle/wrapper
gradlewgradlew.batsettings.gradleios
.gitignore
Flutter
Runner.xcodeproj
Runner.xcworkspace
Runner
AppDelegate.hAppDelegate.m
Assets.xcassets/AppIcon.appiconset
Contents.jsonIcon-App-20x20@1x.pngIcon-App-20x20@2x.pngIcon-App-20x20@3x.pngIcon-App-29x29@1x.pngIcon-App-29x29@2x.pngIcon-App-29x29@3x.pngIcon-App-40x40@1x.pngIcon-App-40x40@2x.pngIcon-App-40x40@3x.pngIcon-App-60x60@2x.pngIcon-App-60x60@3x.pngIcon-App-76x76@1x.pngIcon-App-76x76@2x.pngIcon-App-83.5x83.5@2x.png
Base.lproj
Info.plistmain.mlib
pubspec.yamltest
56
stateful_widget/lib/main.dart
Normal file
56
stateful_widget/lib/main.dart
Normal file
@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
runApp(new MaterialApp(
|
||||
home: new MyButton(),
|
||||
));
|
||||
}
|
||||
|
||||
class MyButton extends StatefulWidget {
|
||||
@override
|
||||
MyButtonState createState() {
|
||||
return new 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 new Scaffold(
|
||||
appBar: new AppBar(
|
||||
title: new Text("Stateful Widget"),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
body: new Container(
|
||||
child: new Center(
|
||||
child: new Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
new Text(displayedString, style: new TextStyle(fontSize: 40.0)),
|
||||
new Padding(padding: new EdgeInsets.all(10.0)),
|
||||
new RaisedButton(
|
||||
child: new Text(
|
||||
"Press me",
|
||||
style: new TextStyle(color: Colors.white),
|
||||
),
|
||||
color: Colors.red,
|
||||
onPressed: onPressOfButton,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user