class Dashboard extends StatefulWidget {
const Dashboard({super.key});
@override
State<Dashboard> createState() => _DashboardState();
}
Lalu rubahlah class isiDashboard beserta isinya menjadi class _DashboardState seperti berikut ini:
class _DashboardState extends State<Dashboard> {
int _indeks = 0;
final List<String> judul = [‘Dashboard’, ‘Tambah Murid’, ‘Daftar Murid’];
final List<Widget> pages = [
Text(‘Halaman Utama’),
Text(‘Halaman Tambah Murid’),
Text(‘Halaman Daftar Murid’),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(judul[_indeks]),
foregroundColor: Colors.white,
backgroundColor: Colors.lightBlue,
),
body: Center(child: pages[_indeks]),
drawer: Drawer(
child: ListView(
children: [
const DrawerHeader(
decoration: BoxDecoration(color: Colors.blue),
child: Text(‘Fahmi’),
),
ListTile(
title: Text(‘Home’),
onTap: () {
setState(() {
_indeks = 0;
});
Navigator.pop(context);
},
),
ListTile(
title: Text(‘Tambah Data Murid’),
onTap: () {
setState(() {
_indeks = 1;
});
Navigator.pop(context);
},
),
ListTile(
title: Text(‘Lihat Data Murid’),
onTap: () {
setState(() {
_indeks = 2;
});
Navigator.pop(context);
},
),
ListTile(
title: Text(‘Close’),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
);
}
}