Recipe
Recipe: Flutter widget scaffold
A minimal Flutter widget blueprint with state, build, and dispose — ready to copy into any Dart file.
import 'package:flutter/material.dart';
class CounterWidget extends StatefulWidget {
final String label;
const CounterWidget({super.key, required this.label});
@override
State<CounterWidget> createState() => _CounterWidgetState();
}
class _CounterWidgetState extends State<CounterWidget> {
int _count = 0;
void _increment() {
setState(() {
_count++;
});
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(widget.label, style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 8),
Text('Count: $_count'),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _increment,
child: const Text('Increment'),
),
],
);
}
}Usage
Drop the widget into any screen. Pass a label string and it renders a self-contained counter.
CounterWidget(label: 'Likes')