1. Home
  2. /
  3. Flutter
  4. /
  5. Counter with Reset

Counter with Reset - Flutter Typing CST Test

Loading…

Counter with Reset — Flutter Code

Counter widget with increment, decrement, and reset functionality.

import 'package:flutter/material.dart';

void main() => runApp(CounterResetApp());

class CounterResetApp extends StatelessWidget {
	@override
	Widget build(BuildContext context) => MaterialApp(home: CounterScreen());
}

class CounterScreen extends StatefulWidget {
	@override
	_CounterScreenState createState() => _CounterScreenState();
}

class _CounterScreenState extends State<CounterScreen> {
	int _count = 0;

	void _increment() => setState(() => _count++);
	void _decrement() => setState(() => _count--);
	void _reset() => setState(() => _count = 0);

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(title: Text('Counter Reset')),
			body: Center(
				child: Column(
					mainAxisAlignment: MainAxisAlignment.center,
					children: [
						Text('Count: $_count', style: TextStyle(fontSize: 32)),
						Row(
							mainAxisAlignment: MainAxisAlignment.center,
							children: [
								ElevatedButton(onPressed: _decrement, child: Text('-')),
								SizedBox(width: 10),
								ElevatedButton(onPressed: _reset, child: Text('Reset')),
								SizedBox(width: 10),
								ElevatedButton(onPressed: _increment, child: Text('+')),
							],
						)
					],
				),
			),
		);
	}
}

Flutter Language Guide

Flutter is an open-source UI framework by Google for building cross-platform mobile, web, and desktop applications using a single Dart codebase, featuring a highly performant rendering engine and a rich set of customizable widgets.

Primary Use Cases

  • ▸Cross-platform mobile apps (iOS & Android)
  • ▸Web applications
  • ▸Desktop apps (macOS, Windows, Linux)
  • ▸Startup MVP development
  • ▸Enterprise internal tools
  • ▸Apps requiring advanced UI/animations
  • ▸Real-time dashboards and admin apps

Notable Features

  • ▸Single codebase for all platforms
  • ▸Hot reload and hot restart
  • ▸High-performance Skia rendering engine
  • ▸Rich built-in widget library
  • ▸Material & Cupertino components
  • ▸Dart AOT/JIT compilation
  • ▸Support for custom animations
  • ▸Strong ecosystem with Firebase

Origin & Creator

Created by Google; initial public release in 2017.

Industrial Note

Dominates fast cross-platform development for mobile-first startups, enterprise apps, fintech dashboards, e-commerce platforms, and apps requiring custom, fluid UI experiences across devices.

More Flutter Typing Exercises

Flutter Stateless WidgetFlutter Counter with Increment and DecrementFlutter Dark/Light Theme ToggleFlutter Simple StopwatchFlutter Counter with History

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher