Simple Stopwatch - Flutter Typing CST Test
Loading…
Simple Stopwatch — Flutter Code
Basic stopwatch that counts seconds using StatefulWidget and Timer.
import 'package:flutter/material.dart';
import 'dart:async';
void main() => runApp(StopwatchApp());
class StopwatchApp extends StatelessWidget {
@override
Widget build(BuildContext context) => MaterialApp(home: StopwatchScreen());
}
class StopwatchScreen extends StatefulWidget {
@override
_StopwatchScreenState createState() => _StopwatchScreenState();
}
class _StopwatchScreenState extends State<StopwatchScreen> {
int _seconds = 0;
Timer? _timer;
void _start() => _timer = Timer.periodic(Duration(seconds: 1), (_) => setState(() => _seconds++));
void _stop() => _timer?.cancel();
void _reset() => setState(() => _seconds = 0);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Stopwatch')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('$_seconds s', style: TextStyle(fontSize: 48)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(onPressed: _start, child: Text('Start')),
SizedBox(width: 10),
ElevatedButton(onPressed: _stop, child: Text('Stop')),
SizedBox(width: 10),
ElevatedButton(onPressed: _reset, child: Text('Reset')),
],
)
],
),
),
);
}
}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.