Skip to content

Instantly share code, notes, and snippets.

@happyharis
Created December 30, 2020 11:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save happyharis/48d327633d51bc88ad3bc71221043680 to your computer and use it in GitHub Desktop.
Save happyharis/48d327633d51bc88ad3bc71221043680 to your computer and use it in GitHub Desktop.
counter money app
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primarySwatch: Colors.yellow),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int number = 0;
void increment() {
setState(() => number++);
}
void decrement() {
setState(() => number--);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Counter App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'This is how much money I have:',
style: TextStyle(fontSize: 20),
),
Text(
'\$$number',
style: TextStyle(fontSize: 130),
),
],
),
),
floatingActionButton: Row(
mainAxisSize: MainAxisSize.min,
children: [
FloatingActionButton(
onPressed: increment,
child: Icon(Icons.add),
),
SizedBox(width: 10),
FloatingActionButton(
onPressed: decrement,
child: Icon(Icons.remove),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment