Teknologi hadir untuk mempermudah kehidupan, termasuk dalam dunia pendidikan. Salah satu kebutuhan utama guru adalah mengelola jadwal mengajar secara praktis dan terorganisir. Bagaimana jika kita bisa membuat aplikasi jadwal sendiri, tanpa perlu koneksi internet dan tanpa menggunakan database rumit?
Melalui artikel ini, Bapak/Ibu guru (atau rekan pengajar) akan diajak memahami dan mempraktikkan pembuatan aplikasi jadwal mengajar guru menggunakan Flutter—sebuah framework pemrograman lintas platform yang kini semakin populer, bahkan bisa dijalankan langsung di browser melalui platform seperti Zapp.run atau VS Code + Android Studio.
Biasanya, aplikasi membutuhkan database seperti SQLite. Namun, untuk kebutuhan jadwal skala kecil (misalnya satu guru atau satu kelas), kita bisa cukup menggunakan shared_preferences
. Ini adalah metode penyimpanan lokal berbasis key–value yang sangat ringan dan cocok untuk pemula.
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';
void main() {
runApp(const JadwalApp());
}
class JadwalApp extends StatelessWidget {
const JadwalApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Jadwal Mengajar Guru',
theme: ThemeData(primarySwatch: Colors.blue),
home: const JadwalScreen(),
debugShowCheckedModeBanner: false,
);
}
}
class Jadwal {
String namaGuru;
String namaMapel;
String kelas;
String jamMulai;
String jamSelesai;
String ruangan;
Jadwal({
required this.namaGuru,
required this.namaMapel,
required this.kelas,
required this.jamMulai,
required this.jamSelesai,
required this.ruangan,
});
Map<String, dynamic> toMap() => {
'namaGuru': namaGuru,
'namaMapel': namaMapel,
'kelas': kelas,
'jamMulai': jamMulai,
'jamSelesai': jamSelesai,
'ruangan': ruangan,
};
static Jadwal fromMap(Map<String, dynamic> map) => Jadwal(
namaGuru: map['namaGuru'],
namaMapel: map['namaMapel'],
kelas: map['kelas'],
jamMulai: map['jamMulai'],
jamSelesai: map['jamSelesai'],
ruangan: map['ruangan'],
);
}
class JadwalScreen extends StatefulWidget {
const JadwalScreen({super.key});
@override
State<JadwalScreen> createState() => _JadwalScreenState();
}
class _JadwalScreenState extends State<JadwalScreen> {
final List<String> hariList = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat'];
int currentIndex = 0;
final PageController _pageController = PageController();
Map<String, List<Jadwal>> jadwalPerHari = {
'Senin': [],
'Selasa': [],
'Rabu': [],
'Kamis': [],
'Jumat': [],
};
final _formKey = GlobalKey<FormState>();
bool isEditing = false;
int? editingIndex;
String editingHari = 'Senin';
final TextEditingController _namaGuru = TextEditingController();
final TextEditingController _namaMapel = TextEditingController();
final TextEditingController _kelas = TextEditingController();
final TextEditingController _jamMulai = TextEditingController();
final TextEditingController _jamSelesai = TextEditingController();
final TextEditingController _ruangan = TextEditingController();
bool showForm = false;
@override
void initState() {
super.initState();
loadData();
}
void saveData() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
Map<String, String> data = {};
jadwalPerHari.forEach((hari, list) {
data[hari] = jsonEncode(list.map((j) => j.toMap()).toList());
});
await prefs.setString('jadwal', jsonEncode(data));
}
void loadData() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String? rawData = prefs.getString('jadwal');
if (rawData != null) {
Map<String, dynamic> data = jsonDecode(rawData);
data.forEach((hari, list) {
List decoded = jsonDecode(list);
jadwalPerHari[hari] = decoded.map((e) => Jadwal.fromMap(e)).toList();
});
setState(() {});
}
}
void clearForm() {
_namaGuru.clear();
_namaMapel.clear();
_kelas.clear();
_jamMulai.clear();
_jamSelesai.clear();
_ruangan.clear();
editingIndex = null;
editingHari = '';
isEditing = false;
}
Future<void> pickTime(TextEditingController controller) async {
TimeOfDay? picked =
await showTimePicker(context: context, initialTime: TimeOfDay.now());
if (picked != null) {
controller.text = picked.format(context);
}
}
@override
Widget build(BuildContext context) {
String hari = hariList[currentIndex];
return Scaffold(
appBar: AppBar(
title: const Text('Jadwal Mengajar Guru'),
actions: [
IconButton(
icon: Icon(showForm ? Icons.close : Icons.add),
onPressed: () {
setState(() {
showForm = !showForm;
if (!showForm) {
clearForm();
}
});
},
)
],
),
body: Column(
children: [
// Tombol Hari
SizedBox(
height: 50,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: hariList.length,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 6),
child: ElevatedButton(
onPressed: () {
setState(() {
currentIndex = index;
});
_pageController.jumpToPage(index);
},
style: ElevatedButton.styleFrom(
backgroundColor: currentIndex == index
? Colors.blue
: Colors.grey.shade400,
),
child: Text(hariList[index]),
),
),
),
),
if (showForm)
Padding(
padding: const EdgeInsets.all(12),
child: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
controller: _namaGuru,
decoration: const InputDecoration(
labelText: 'Nama Guru',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextFormField(
controller: _namaMapel,
decoration: const InputDecoration(
labelText: 'Mata Pelajaran',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
TextFormField(
controller: _kelas,
decoration: const InputDecoration(
labelText: 'Kelas',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: TextFormField(
controller: _jamMulai,
readOnly: true,
onTap: () => pickTime(_jamMulai),
decoration: const InputDecoration(
labelText: 'Jam Mulai',
border: OutlineInputBorder(),
),
),
),
const SizedBox(width: 8),
Expanded(
child: TextFormField(
controller: _jamSelesai,
readOnly: true,
onTap: () => pickTime(_jamSelesai),
decoration: const InputDecoration(
labelText: 'Jam Selesai',
border: OutlineInputBorder(),
),
),
),
],
),
const SizedBox(height: 8),
TextFormField(
controller: _ruangan,
decoration: const InputDecoration(
labelText: 'Ruangan',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
Jadwal newJadwal = Jadwal(
namaGuru: _namaGuru.text,
namaMapel: _namaMapel.text,
kelas: _kelas.text,
jamMulai: _jamMulai.text,
jamSelesai: _jamSelesai.text,
ruangan: _ruangan.text,
);
if (isEditing) {
jadwalPerHari[editingHari]![editingIndex!] =
newJadwal;
} else {
jadwalPerHari[hari]?.add(newJadwal);
}
saveData();
setState(() {
clearForm();
showForm = false;
});
}
},
child: Text(isEditing ? 'Simpan Edit' : 'Tambah'),
),
],
),
),
),
Expanded(
child: PageView.builder(
controller: _pageController,
itemCount: hariList.length,
onPageChanged: (index) {
setState(() {
currentIndex = index;
});
},
itemBuilder: (context, index) {
String hari = hariList[index];
return ListView.builder(
itemCount: jadwalPerHari[hari]!.length,
itemBuilder: (context, i) {
Jadwal j = jadwalPerHari[hari]![i];
return Card(
margin: const EdgeInsets.all(8),
child: ListTile(
title: Text('${j.namaMapel} - ${j.kelas}'),
subtitle: Text(
'${j.jamMulai} - ${j.jamSelesai} | ${j.ruangan}\nGuru: ${j.namaGuru}'),
isThreeLine: true,
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.edit, color: Colors.green),
onPressed: () {
setState(() {
isEditing = true;
editingIndex = i;
editingHari = hari;
showForm = true;
_namaGuru.text = j.namaGuru;
_namaMapel.text = j.namaMapel;
_kelas.text = j.kelas;
_jamMulai.text = j.jamMulai;
_jamSelesai.text = j.jamSelesai;
_ruangan.text = j.ruangan;
});
},
),
IconButton(
icon: const Icon(Icons.delete, color: Colors.red),
onPressed: () {
setState(() {
jadwalPerHari[hari]!.removeAt(i);
saveData();
});
},
),
],
),
),
);
},
);
},
),
),
],
),
);
}
}
name: flutter_app
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1
environment:
sdk: '>=2.18.2 <3.0.0'
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
shared_preferences: ^2.2.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages