Notifikasi transaksi: hanya untuk admin + transaksi dari orang lain (bukan transaksi sendiri)
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import 'config.dart';
|
||||
import 'models/sale.dart';
|
||||
import 'state/app_state.dart';
|
||||
import 'services/printer_service.dart';
|
||||
import 'screens/login_screen.dart';
|
||||
import 'screens/home_page.dart';
|
||||
import 'utils/colors.dart';
|
||||
import 'utils/format.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -25,12 +28,48 @@ class MyApp extends StatefulWidget {
|
||||
|
||||
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
late final AppState _appState;
|
||||
final GlobalKey<ScaffoldMessengerState> _scaffoldKey =
|
||||
GlobalKey<ScaffoldMessengerState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_appState = AppState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
// Dengarkan stream notifikasi transaksi baru (dari HP lain / checkout).
|
||||
_appState.newSaleNotifications.stream.listen(_showSaleNotification);
|
||||
}
|
||||
|
||||
void _showSaleNotification(Sale sale) {
|
||||
final messenger = _scaffoldKey.currentState;
|
||||
if (messenger == null) return;
|
||||
// Getar + bunyi notifikasi.
|
||||
HapticFeedback.heavyImpact();
|
||||
SystemSound.play(SystemSoundType.click);
|
||||
// Banner notifikasi di atas layar.
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
const Icon(Icons.check_circle, color: kSuccess, size: 20),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Transaksi baru: ${sale.items.fold<int>(0, (s, i) => s + i.qty)} item • ${formatRupiah(sale.total)}',
|
||||
style: const TextStyle(color: kText, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor: kSurface,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: const Duration(seconds: 4),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
side: const BorderSide(color: kSuccess, width: 1),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -54,6 +93,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
return ChangeNotifierProvider.value(
|
||||
value: _appState,
|
||||
child: MaterialApp(
|
||||
scaffoldMessengerKey: _scaffoldKey,
|
||||
title: 'Dutra Store',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
|
||||
Reference in New Issue
Block a user