Skip to content

Instantly share code, notes, and snippets.

@supernovel
Created December 2, 2021 11:03
Show Gist options
  • Save supernovel/9daa85552b3f46d689aaaf384e61e708 to your computer and use it in GitHub Desktop.
Save supernovel/9daa85552b3f46d689aaaf384e61e708 to your computer and use it in GitHub Desktop.
Counter
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: const Scaffold(
body: Center(
child: Counter(),
),
),
);
}
}
class Counter extends StatefulWidget {
const Counter({Key? key}) : super(key: key);
@override
ConuterState createState() => ConuterState();
}
class ConuterState extends State<Counter> {
int count = 0;
@override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Text("$count", style: const TextStyle(fontSize: 30)),
const SizedBox(height: 40),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
TextButton(child: const Text("increase"), onPressed: increase),
const SizedBox(width: 40),
TextButton(child: const Text("decrease"), onPressed: decrease)
])
]);
}
void increase() {
setState(() {
count += 1;
});
}
void decrease() {
setState(() {
count -= 1;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment