// ignore_for_file: use_key_in_widget_constructors
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: HomePage(),
);
}
}
class DrawerItem {
String title;
IconData icon;
DrawerItem(this.title, this.icon);
}
class HomePage extends StatefulWidget {
final drawerItems = [
DrawerItem("Dashboard", Icons.home),
DrawerItem("Halaman Data Detail", Icons.money),
];
HomePage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return HomePageState();
}
}
class HomePageState extends State<HomePage> {
bool isLogin = false;
int _selectedDrawerIndex = 0;
_getDrawerItemWidget(int pos) {
switch (pos) {
case 0:
return const CounterPage(
title: 'Hitung',
);
case 1:
return HalamanDataDetail();
default:
return const Text("Error");
}
}
_onSelectItem(int index) {
setState(() => _selectedDrawerIndex = index);
Navigator.of(context).pop(); // close the drawer
}
@override
Widget build(BuildContext context) {
List<Widget> drawerOptions = [];
for (var i = 0; i < widget.drawerItems.length; i++) {
var d = widget.drawerItems[i];
drawerOptions.add(ListTile(
leading: Icon(d.icon),
title: Text(d.title),
selected: i == _selectedDrawerIndex,
onTap: () => _onSelectItem(i),
));
}
return Scaffold(
appBar: AppBar(
title: Text(widget.drawerItems[_selectedDrawerIndex].title),
),
drawer: Drawer(
child: Column(
children: <Widget>[
Container(
height: 100,
color: Colors.teal,
child: const Center(
child: Text(
"Aplikasi Keuangan",
style: TextStyle(fontSize: 15, color: Colors.white),
textAlign: TextAlign.center,
),
)),
Column(children: drawerOptions)
],
),
),
body: _getDrawerItemWidget(_selectedDrawerIndex),
);
}
}
class CounterPage extends StatefulWidget {
const CounterPage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<CounterPage> createState() => _CounterPageState();
}
class _CounterPageState extends State<CounterPage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'HALAMAN DINAMIS, TEKAN TOMBOL UNTUK MERUBAH',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
class HalamanDataDetail extends StatelessWidget {
final String datanya = 'DATA INI DARI VARIABLE';
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(datanya.toString()),
const Text(
'Halaman informasi data static tanpa State, data variable\nTekan tombol dibawah untuk informasi detail data'),
IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
kirimData: datanya,
)),
);
},
icon: const Icon(Icons.arrow_circle_up))
],
),
);
}
}
class DetailPage extends StatelessWidget {
const DetailPage({Key? key, required this.kirimData}) : super(key: key);
final String kirimData;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Halaman Detail"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('data yang dikirim adalah : \n' + kirimData),
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Go back!'),
),
])));
}
}
EmoticonEmoticon