-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.dart
84 lines (73 loc) · 1.96 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import 'dart:async';
import 'package:flutter/material.dart';
void main() => runApp(new MyStatelessWidget(title: "StatelessWidget Example"));
class MyStatelessWidget extends StatelessWidget {
final String title;
MyStatelessWidget({Key key, this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key, this.title}) : super(key: key);
final String title;
@override
_MyStatefulWidgetState createState() => new _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
bool showtext = true;
bool toggleState = true;
Timer t2;
void toggleBlinkState() {
setState(() {
toggleState = !toggleState;
});
var twenty = const Duration(milliseconds: 1000);
if (toggleState == false) {
t2 = new Timer.periodic(twenty, (Timer t) {
toggleShowText();
});
} else {
t2.cancel();
}
}
void toggleShowText() {
setState(() {
showtext = !showtext;
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("State Change Demo"),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
(showtext
? (new Text(
'I love blinking.',
))
: (new Container())
),
new Padding(
padding: new EdgeInsets.only(top: 70.0),
child: new RaisedButton(
onPressed: toggleBlinkState,
child: (toggleState
? (new Text("Blink"))
: (new Text("Stop Blinking"))
)
)
)
],
),
),
);
}
}