import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text("Extended Counter"), ), body: const Counter(), ), ); } } class Counter extends StatefulWidget { const Counter({super.key}); @override State createState() => CounterState(); } class CounterState extends State { int counter = 0; int increment = 1; void incrementCounter() { setState(() { if (counter + increment <= 100) counter += increment; }); } void decrementCounter() { setState(() { if (counter - increment >= 0) counter -= increment; }); } void setIncrement(double newValue) { setState(() { increment = newValue.toInt(); }); } @override Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ SizedBox( width: 100, child: TextField( textAlign: TextAlign.center, style: const TextStyle(fontSize: 30,), onChanged: (text) => {increment = int.tryParse(text) ?? 0}, ), ), Text( "$counter", style: const TextStyle(fontSize: 150, fontWeight: FontWeight.bold,), textAlign: TextAlign.center, ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ IconButton( onPressed: counter == 0 ? null : decrementCounter, icon: const Icon(Icons.remove), ), IconButton( onPressed: counter == 100 ? null : incrementCounter, icon: const Icon(Icons.add), ), ], ), ], ); } }