Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates Flutter widget lifecycle, state management, and UI composition.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: CounterScreen(),
);
}
}
class CounterScreen extends StatefulWidget {
@override
_CounterScreenState createState() => _CounterScreenState();
}
class _CounterScreenState extends State<CounterScreen> {
int _counter = 0;
List<String> _history = [];
void _incrementCounter() {
setState(() {
_counter++;
_history.add('Incremented to $_counter');
});
}
void _decrementCounter() {
setState(() {
_counter--;
_history.add('Decremented to $_counter');
});
}
void _resetCounter() {
setState(() {
_counter = 0;
_history.clear();
_history.add('Counter reset');
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Counter'),
backgroundColor: Theme.of(context).primaryColor,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Current Count:',
style: Theme.of(context).textTheme.headlineSmall,
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton(
onPressed: _decrementCounter,
tooltip: 'Decrement',
child: Icon(Icons.remove),
heroTag: 'decrement',
),
FloatingActionButton(
onPressed: _resetCounter,
tooltip: 'Reset',
child: Icon(Icons.refresh),
heroTag: 'reset',
),
FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
heroTag: 'increment',
),
],
),
SizedBox(height: 30),
Expanded(
child: Container(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'History:',
style: Theme.of(context).textTheme.titleMedium,
),
Expanded(
child: ListView.builder(
itemCount: _history.length,
itemBuilder: (context, index) {
return ListTile(
leading: Icon(Icons.history),
title: Text(_history[index]),
subtitle: Text('Action ${index + 1}'),
);
},
),
),
],
),
),
),
],
),
);
}
}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.
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.