chore: initial commit Dutra Store POS app
This commit is contained in:
120
lib/screens/home_page.dart
Normal file
120
lib/screens/home_page.dart
Normal file
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'kasir_screen.dart';
|
||||
import 'produk_screen.dart';
|
||||
import 'riwayat_screen.dart';
|
||||
import 'pengaturan_screen.dart';
|
||||
import 'printer_screen.dart';
|
||||
import '../state/app_state.dart';
|
||||
import '../utils/colors.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
int _index = 0;
|
||||
|
||||
List<Widget> _screensForRole(String? role) {
|
||||
final screens = <Widget>[const KasirScreen()];
|
||||
if (role == 'admin') {
|
||||
screens.addAll([
|
||||
const ProdukScreen(),
|
||||
const RiwayatScreen(),
|
||||
const PengaturanScreen(),
|
||||
]);
|
||||
} else {
|
||||
screens.addAll([
|
||||
const RiwayatScreen(),
|
||||
const PrinterScreen(),
|
||||
]);
|
||||
}
|
||||
return screens;
|
||||
}
|
||||
|
||||
List<BottomNavigationBarItem> _navItemsForRole(String? role) {
|
||||
final items = <BottomNavigationBarItem>[
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.point_of_sale),
|
||||
label: 'Kasir',
|
||||
),
|
||||
];
|
||||
if (role == 'admin') {
|
||||
items.addAll([
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.inventory_2),
|
||||
label: 'Produk',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.receipt_long),
|
||||
label: 'Riwayat',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.settings_outlined),
|
||||
label: 'Pengaturan',
|
||||
),
|
||||
]);
|
||||
} else {
|
||||
items.addAll([
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.receipt_long),
|
||||
label: 'Riwayat',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.print_outlined),
|
||||
label: 'Printer',
|
||||
),
|
||||
]);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = context.watch<AppState>();
|
||||
final screens = _screensForRole(state.userRole);
|
||||
final navItems = _navItemsForRole(state.userRole);
|
||||
|
||||
final safeIndex = _index >= screens.length ? 0 : _index;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.storefront_rounded, color: kAccent),
|
||||
const SizedBox(width: 8),
|
||||
const Text('Dutra Store'),
|
||||
],
|
||||
),
|
||||
centerTitle: true,
|
||||
elevation: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout, color: kMuted),
|
||||
onPressed: () async {
|
||||
await context.read<AppState>().logout();
|
||||
},
|
||||
tooltip: 'Logout',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: IndexedStack(
|
||||
index: safeIndex,
|
||||
children: screens,
|
||||
),
|
||||
bottomNavigationBar: navItems.length >= 2
|
||||
? BottomNavigationBar(
|
||||
currentIndex: safeIndex,
|
||||
onTap: (i) => setState(() => _index = i),
|
||||
items: navItems,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user