feat: sync order

This commit is contained in:
efrilm
2025-08-03 14:39:15 +07:00
parent 3d1ae25bcf
commit 051b64e3a6
25 changed files with 1422 additions and 333 deletions
@@ -46,6 +46,8 @@ class _DashboardPageState extends State<DashboardPage> {
setState(() {});
}
late StreamSubscription<List<ConnectivityResult>> _connectivitySubscription;
@override
void initState() {
super.initState();
@@ -63,24 +65,19 @@ class _DashboardPageState extends State<DashboardPage> {
const SettingsPage(),
];
// ignore: unused_local_variable
StreamSubscription<List<ConnectivityResult>> subscription = Connectivity()
_connectivitySubscription = Connectivity()
.onConnectivityChanged
.listen((List<ConnectivityResult> connectivityResult) {
// Received changes in available connectivity types!
if (!mounted) return; // <-- Tambahkan ini!
if (connectivityResult.contains(ConnectivityResult.mobile)) {
// Mobile network available.
context
.read<OnlineCheckerBloc>()
.add(const OnlineCheckerEvent.check(true));
} else if (connectivityResult.contains(ConnectivityResult.wifi)) {
// Wi-fi is available.
context
.read<OnlineCheckerBloc>()
.add(const OnlineCheckerEvent.check(true));
// Note for Android:
// When both mobile and Wi-Fi are turned on system will return Wi-Fi only as active network type
} else {
// Neither mobile network nor Wi-fi available.
context
.read<OnlineCheckerBloc>()
.add(const OnlineCheckerEvent.check(false));
@@ -88,6 +85,12 @@ class _DashboardPageState extends State<DashboardPage> {
});
}
@override
void dispose() {
_connectivitySubscription.cancel(); // <-- Cancel subscription di dispose
super.dispose();
}
@override
Widget build(BuildContext context) {
return SafeArea(
@@ -37,7 +37,9 @@ class HomeRightTitle extends StatelessWidget {
width: 180.0,
height: 40,
elevation: 0,
onPressed: () => context.push(SalesPage()),
onPressed: () => context.push(SalesPage(
status: 'pending',
)),
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
icon: Icon(