This document discusses stateful widgets in Flutter. It provides two examples of stateful widgets. The first example demonstrates updating text when a button is pressed. The second example increments a counter and cycles through a string array when a button is pressed. The document concludes by assigning students a homework task to create a random dice rolling app as a stateful widget project.
1. SMKN 2 JAKARTA
STATEFULL WIDGET
2
Tema :
Statefull Widget
Hardware :
• laptop / pc
Software :
• flutter sdk
• android studio / visual studio code
• flutlab.io
Dokumentasi : https://docs.flutter.dev/development/ui/interactive
Materi :
Example 1
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: const MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
//1. buat default variabel
String _value = "Tulisan ini akan muncul pertama kali di run";
//2 .buat function tekan
void _tekan(){
setState(() {
_value = "Ketika Di klik tulisan ini akan tampil";
});
}
@override
6. Penilaian tugas :
• push project dadu ke github setiap siswa, lalu kirim linknya ke google classroom
• tidak boleh plagiat code
• untuk file asset gambar dadu dapat di download link :
https://github.com/herry88/kumpulangambarjobsheet/tree/master/imagedadu