Created with <3 with dartpad.dev.
Last active
November 8, 2022 04:37
-
-
Save dicenull/944d3df328cbc6a828068ee3762e09a1 to your computer and use it in GitHub Desktop.
bustling-dryad-7998
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
home: MainPage(), | |
); | |
} | |
} | |
class MainPage extends StatefulWidget { | |
const MainPage({Key? key}) : super(key: key); | |
@override | |
State<MainPage> createState() => _MainPageState(); | |
} | |
class _MainPageState extends State<MainPage> { | |
final baseNumberCtrl = TextEditingController(); | |
final firstHalfCtrl = TextEditingController(); | |
final secondHalfCtrl = TextEditingController(); | |
final firstHalfBonus = TextEditingController(); | |
final secondHalfBonus = TextEditingController(); | |
int income = 0; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Padding( | |
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 8), | |
child: Column( | |
children: [ | |
TextField( | |
controller: baseNumberCtrl, | |
decoration: const InputDecoration(labelText: '1月から4月の給与'), | |
), | |
TextField( | |
controller: firstHalfCtrl, | |
decoration: const InputDecoration(labelText: '5月から10月の給与'), | |
), | |
TextField( | |
controller: secondHalfCtrl, | |
decoration: const InputDecoration(labelText: '11月から12月の給与'), | |
), | |
TextField( | |
controller: firstHalfBonus, | |
decoration: const InputDecoration(labelText: '4月のボーナス'), | |
), | |
TextField( | |
controller: secondHalfBonus, | |
decoration: const InputDecoration(labelText: '10月のボーナス'), | |
), | |
TextButton( | |
onPressed: () { | |
final base = int.parse(baseNumberCtrl.text); | |
final firstHalf = int.parse(firstHalfCtrl.text); | |
final secondHalf = | |
int.parse(secondHalfCtrl.text); | |
final firstBonus = int.parse(firstHalfBonus.text); | |
final secondBonus = int.parse(secondHalfBonus.text); | |
setState(() { | |
income = base * 4 + | |
firstHalf * 6 + | |
secondHalf * 2 + | |
firstBonus + | |
secondBonus; | |
}); | |
}, | |
child: const Text('計算!'), | |
), | |
Text( | |
'$income円', | |
style: const TextStyle(fontSize: 128), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment