728x90
728x170
▶ main.dart
import 'package:flutter/material.dart';
void main() => runApp(TestApplication());
class TestApplication extends StatelessWidget {
static const String _title = 'Test Application';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MainPage(),
);
}
}
class MainPage extends StatefulWidget {
MainPage({Key key}) : super(key: key);
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
List<String> _buttonTextList = ['더하기', '빼기', '곱하기', '나누기'];
List<DropdownMenuItem<String>> _menuItemList =
List<DropdownMenuItem<String>>();
String _currentButtonText;
String _resultText = '';
TextEditingController controller1 = TextEditingController();
TextEditingController controller2 = TextEditingController();
@override
void initState() {
super.initState();
for (String buttonText in _buttonTextList) {
_menuItemList
.add(DropdownMenuItem(value: buttonText, child: Text(buttonText)));
}
_currentButtonText = _menuItemList[0].value;
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test Application'),
),
body: Container(
child: Center(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(15),
child: Text(
'결과 : $_resultText',
style: TextStyle(fontSize: 20),
),
),
Padding(
padding: EdgeInsets.only(left: 20, right: 20),
child: TextField(
keyboardType: TextInputType.number,
controller: controller1,
),
),
Padding(
padding: EdgeInsets.only(left: 20, right: 20),
child: TextField(
keyboardType: TextInputType.number,
controller: controller2,
),
),
Padding(
padding: EdgeInsets.all(15),
child: RaisedButton(
child: Row(
children: <Widget>[
Icon(Icons.add),
Text(_currentButtonText),
],
),
color: Colors.amber,
onPressed: () {
setState(() {
double value1 = double.parse(controller1.value.text);
double value2 = double.parse(controller2.value.text);
double result;
if (_currentButtonText == '더하기') {
result = value1 + value2;
} else if (_currentButtonText == '빼기') {
result = value1 - value2;
} else if (_currentButtonText == '곱하기') {
result = value1 * value2;
} else {
result = value1 / value2;
}
_resultText = result.toString();
});
}),
),
Padding(
padding: EdgeInsets.all(15),
child: DropdownButton(
items: _menuItemList,
onChanged: (value) {
setState(() {
_currentButtonText = value;
});
},
value: _currentButtonText,
),
),
],
),
),
),
);
}
}
728x90
그리드형(광고전용)
'Flutter' 카테고리의 다른 글
[FLUTTER] TextField 클래스 : keyboardType/controller 속성 사용하기 (0) | 2021.05.18 |
---|---|
[FLUTTER] EdgeInsets 클래스 : only 생성자 사용하기 (0) | 2021.05.18 |
[FLUTTER] EdgeInsets 클래스 : all 생성자 사용하기 (0) | 2021.05.18 |
[FLUTTER] 폰트 파일 추가하기 (0) | 2021.05.18 |
[FLUTTER] Import 키워드 : 파일 임포트하기 (0) | 2021.05.18 |
[FLUTTER] Image 클래스 : width/height/fit 속성 사용하기 (0) | 2021.05.18 |
[FLUTTER] TextStyle 클래스 사용하기 (0) | 2021.05.17 |
[FLUTTER] Text 클래스 : textAlign 속성을 사용해 수평 정렬하기 (0) | 2021.05.17 |
[FLUTTER] ThemeData 클래스 : visualDensity 속성 사용하기 (0) | 2021.05.17 |
[FLUTTER] 할 일 관리 앱 만들기 (파이어베이스 연동) (0) | 2021.05.10 |