import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { TextEditingController hassasiyet = TextEditingController(); bool islem = true; double pay = 4; double sayac = 0; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: Column( children: [ TextField( controller: hassasiyet, keyboardType: TextInputType.number, decoration: InputDecoration( labelText: "Hassasiyet Giriniz:" ), ), SizedBox(height: 10), ElevatedButton(onPressed: () { setState(() { sayac = 0; islem = true; int hass = int.tryParse(hassasiyet.text) ?? 0; for(var i = 0; i < hass; i++){ double payda = 1 + (i * 2); if(islem == true){ sayac = sayac + (pay / payda); islem = false; } else{ sayac = sayac - (pay / payda); islem = true; } } }); }, child: Text("Hesapla"),), Text("$sayac") ], ), ), ), ); } }