Created
April 12, 2022 04:36
-
-
Save triyono777/14ad5fba6253e51ea870a8dc38a8ed7b 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; | |
_hitunganTambah() { | |
setState(() { | |
hitungan++; | |
}); | |
} | |
_hitunganKurang() { | |
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: () { | |
_hitunganKurang(); | |
}, | |
child: Text('Pengurangan'), | |
), | |
SizedBox( | |
width: 20, | |
), | |
ElevatedButton( | |
onPressed: () { | |
_hitunganTambah(); | |
}, | |
child: Text('Penambahan'), | |
), | |
], | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
_hitunganTambah(); | |
}, | |
child: Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment