Skip to content

Instantly share code, notes, and snippets.

@Andrious
Created March 1, 2024 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrious/12b4f9b3f0d810e9658022c5e78fa7c8 to your computer and use it in GitHub Desktop.
Save Andrious/12b4f9b3f0d810e9658022c5e78fa7c8 to your computer and use it in GitHub Desktop.
The Counter App with a prints() functions highlighting the system & user events
//
import 'package:flutter/foundation.dart';
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(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({super.key, this.title}) {
if (kDebugMode) {
print(
">>>>>>>>>>>>>>>>>>>>>>>>> MyHomePage being created. Constructor called.");
}
}
final String? title;
@override
State createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// constructor
_MyHomePageState() : super() {
if (kDebugMode) {
print(
">>>>>>>>>>>>>>>>>>>>>>>>> _MyHomePageState being created. Constructor called.");
}
}
int _counter = 0;
@override
void initState() {
super.initState();
if (kDebugMode) {
print(">>>>>>>>>>>>>>>>>>>>>>>>> _MyHomePageState initState() called.");
}
}
@override
Widget build(BuildContext context) {
if (kDebugMode) {
print(">>>>>>>>>>>>>>>>>>>>>>>>> _MyHomePageState build() called!");
}
return Scaffold(
appBar: AppBar(
title: Text(widget.title ?? ''),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
if (kDebugMode) {
print(
">>>>>>>>>>>>>>>>>>>>>>>>> 'Floating Blue' button pressed. Function setState() called.");
}
setState(() {
_counter++;
});
},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment