ADD ALOT OF POLISHING AND UPDATES...

This commit is contained in:
Wowieee4
2026-05-26 05:52:12 +07:00
parent 2e3ecdf1d1
commit b8ad8df993
53 changed files with 3194 additions and 3860 deletions
@@ -9,6 +9,7 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:geolocator/geolocator.dart';
import 'package:latlong2/latlong.dart';
@@ -38,12 +39,14 @@ class _Step {
required this.point});
}
// ─── BLoC-lite state (plain ChangeNotifier to avoid heavy BLoC boilerplate
// while staying consistent with the rest of screens.dart approach) ─────
// Navigation state is kept in a lightweight Cubit so the app uses one
// state-management family consistently.
enum _NavPhase { idle, locating, routing, navigating, error }
class _NavState extends ChangeNotifier {
class _NavState extends Cubit<int> {
_NavState() : super(0);
_NavPhase phase = _NavPhase.idle;
String statusText = 'Ketuk tombol lokasi atau cari tujuan.';
LatLng? currentPosition;
@@ -59,9 +62,11 @@ class _NavState extends ChangeNotifier {
void _set(_NavPhase p, String status) {
phase = p;
statusText = status;
notifyListeners();
_notify();
}
void _notify() => emit(state + 1);
// ── locate ──────────────────────────────────────────────────────────────
Future<bool> locate() async {
_set(_NavPhase.locating, 'Mencari lokasi GPS…');
@@ -85,7 +90,8 @@ class _NavState extends ChangeNotifier {
_set(_NavPhase.error, 'GPS timeout. Pastikan GPS aktif.');
return false;
} catch (e) {
_set(_NavPhase.error, 'GPS error: $e');
_set(_NavPhase.error,
'Lokasi belum bisa dibaca. Pastikan GPS dan izin lokasi aktif.');
return false;
}
}
@@ -211,10 +217,11 @@ class _NavState extends ChangeNotifier {
_set(_NavPhase.navigating,
steps.isNotEmpty ? steps[0].instruction : 'Ikuti rute biru.');
notifyListeners();
_notify();
_startTracking();
} catch (e) {
_set(_NavPhase.error, 'Gagal mendapat rute: $e');
_set(_NavPhase.error,
'Gagal mendapat rute. Periksa koneksi lalu coba lagi.');
}
}
@@ -283,7 +290,7 @@ class _NavState extends ChangeNotifier {
currentPosition = LatLng(pos.latitude, pos.longitude);
_reportToBackend(pos);
_updateStep();
notifyListeners();
_notify();
});
}
@@ -302,7 +309,7 @@ class _NavState extends ChangeNotifier {
final next = steps[currentStepIndex];
statusText = next.instruction;
sl<TtsService>().speak(next.instruction);
notifyListeners();
_notify();
}
}
}
@@ -318,9 +325,9 @@ class _NavState extends ChangeNotifier {
}
@override
void dispose() {
Future<void> close() {
_posStream?.cancel();
super.dispose();
return super.close();
}
}
@@ -339,6 +346,7 @@ class _NavigationModeScreenState extends State<NavigationModeScreen> {
final _searchCtrl = TextEditingController();
final _searchFocus = FocusNode();
StreamSubscription<int>? _navSubscription;
List<_Place> _suggestions = const [];
bool _searchLoading = false;
bool _showSuggestions = false;
@@ -348,7 +356,7 @@ class _NavigationModeScreenState extends State<NavigationModeScreen> {
@override
void initState() {
super.initState();
_navState.addListener(_onStateChange);
_navSubscription = _navState.stream.listen((_) => _onStateChange());
WidgetsBinding.instance.addPostFrameCallback((_) => _init());
}
@@ -433,8 +441,8 @@ class _NavigationModeScreenState extends State<NavigationModeScreen> {
@override
void dispose() {
_debounce?.cancel();
_navState.removeListener(_onStateChange);
_navState.dispose();
_navSubscription?.cancel();
_navState.close();
_searchCtrl.dispose();
_searchFocus.dispose();
super.dispose();