Created
April 9, 2022 07:03
-
-
Save triyono777/be9858792de97c46960f5144688783c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class CounterScreen extends StatefulWidget { | |
const CounterScreen({Key? key}) : super(key: key); | |
@override | |
State<CounterScreen> createState() => _CounterScreenState(); | |
} | |
class _CounterScreenState extends State<CounterScreen> { | |
int hitungan = 0; | |
hitungTambah(){ | |
setState(() { | |
hitungan++; | |
}); | |
} | |
hitungKurang(){ | |
setState(() { | |
hitungan--; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Counter Screen'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text('Anda sudah klik $hitungan'), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
ElevatedButton( | |
onPressed: () { | |
hitungTambah(); | |
}, | |
child: Text('Tambah'), | |
), | |
SizedBox(width: 10,), | |
ElevatedButton( | |
onPressed: () { | |
hitungKurang(); | |
}, | |
child: Text('Kurang'), | |
), | |
], | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment