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
| import 'package:flutter/material.dart';
class ChangeTextByButton extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ChangeTextByButton();
}
}
class _ChangeTextByButton extends State<ChangeTextByButton> {
var swVal = false;
var str = 'Jaejin Jang off';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ChangeTextByButton',
theme: ThemeData(
primaryColor: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity),
darkTheme: ThemeData.light(),
home: Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
str,
style: TextStyle(color: Colors.blue, fontSize: 20),
),
Switch(
value: swVal,
onChanged: (value) {
setState(() {
swVal = value;
str = value ? 'Jaejin Jang On' : 'Jaejin Jang off';
});
},
),
]))),
);
}
}
|