POLISHING STUFF and Smarter AI, and alot i mean.. ALOT OF BUG FIX AND OPTIMIZE

This commit is contained in:
Wowieee4
2026-05-29 15:50:51 +07:00
parent 1110e5a42d
commit d2b3534dde
65 changed files with 4150 additions and 2974 deletions
@@ -5,7 +5,6 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
@@ -17,16 +16,16 @@ import '../../core/network/api_client.dart';
import '../../core/services/haptic_service.dart';
import '../../core/services/tts_service.dart';
import '../../core/storage/secure_storage.dart';
import '../../core/theme/app_colors.dart';
import '../../core/theme/app_decorations.dart';
import '../../core/theme/app_text_styles.dart';
Dio get _api => sl<ApiClient>().dio;
// ─── Colours (inline, tidak butuh import app_colors.dart) ────────────────────
const _kBlue = Color(0xFF1A56DB);
const _kRed = Color(0xFFDC2626);
const _kSurface = Color(0xFFF8FAFC);
const _kBorder = Color(0xFFE2E8F0);
const _kMuted = Color(0xFF64748B);
const _kText = Color(0xFF0F172A);
// ─── Screen ──────────────────────────────────────────────────────────────────
@@ -53,7 +52,6 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
// Account info (from SecureStorage)
String _displayName = '';
String _uniqueId = '';
// Pairing status
String _pairingStatus = '—';
@@ -75,7 +73,6 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
Future<void> _loadAccount() async {
final storage = sl<SecureStorage>();
_displayName = await storage.getDisplayName() ?? '';
_uniqueId = await storage.getUniqueUserId() ?? '';
}
Future<void> _loadSettings() async {
@@ -91,6 +88,7 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
_ttsSpeed = (data['ttsSpeed'] as num?)?.toDouble() ?? 0.9;
_warnNoGuardian = data['warnNoGuardian'] as bool? ?? true;
_hapticEnabled = data['hapticEnabled'] as bool? ?? true;
sl<HapticService>().setEnabled(_hapticEnabled);
}
},
onError: (_) {},
@@ -126,6 +124,7 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
// Apply TTS locally dulu
await sl<TtsService>().setLanguage(_ttsLanguage);
context.read<AppCubit>().setLocaleCode(_ttsLanguage);
sl<HapticService>().setEnabled(_hapticEnabled);
if (_hapticEnabled) {
await sl<HapticService>().success();
}
@@ -169,290 +168,258 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
// ── build ──────────────────────────────────────────────────────────────────
@override
Widget build(BuildContext context) {
return SafeArea(
child: _loading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(16),
children: [
// ── header ─────────────────────────────────────────────────
Text('Settings',
style: Theme.of(context)
.textTheme
.headlineSmall
?.copyWith(fontWeight: FontWeight.w800)),
const Text('TTS, haptic, pairing, account',
style: TextStyle(color: _kMuted)),
const SizedBox(height: 20),
return DecoratedBox(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [AppColors.softBlueBg, Colors.white],
),
),
child: SafeArea(
child: _loading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(16),
children: [
// ── header ─────────────────────────────────────────────────
Text('Settings',
style: AppTextStyles.heading.copyWith(
fontWeight: FontWeight.w800,
)),
const Text('TTS, haptic, pairing, account',
style: TextStyle(color: AppColors.muted)),
const SizedBox(height: 20),
// ── 1. TTS Settings ────────────────────────────────────────
_SectionHeader('1. TTS Settings', Icons.record_voice_over),
const SizedBox(height: 10),
_Card(
child: Column(
children: [
// Language (editable)
DropdownButtonFormField<String>(
value: _ttsLanguage,
decoration: const InputDecoration(
labelText: 'Bahasa TTS',
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(
horizontal: 12, vertical: 10),
),
items: const [
DropdownMenuItem(
value: 'id-ID', child: Text('Bahasa Indonesia')),
DropdownMenuItem(
value: 'en-US', child: Text('English (US)')),
],
onChanged: (v) =>
setState(() => _ttsLanguage = v ?? _ttsLanguage),
),
const SizedBox(height: 12),
// Pitch — read-only info
_InfoRow(
label: 'Pitch',
value: _ttsPitch.toStringAsFixed(1),
note: 'Diatur oleh Guardian',
icon: Icons.tune,
),
const Divider(height: 20),
// Speed — read-only info
_InfoRow(
label: 'Speed',
value: _ttsSpeed.toStringAsFixed(1),
note: 'Diatur oleh Guardian',
icon: Icons.speed,
),
],
),
),
const SizedBox(height: 20),
// ── 2. Pairing ─────────────────────────────────────────────
_SectionHeader('2. Pairing', Icons.link),
const SizedBox(height: 10),
_Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// unique ID
if (_uniqueId.isNotEmpty) ...[
const Text('Unique User ID',
style: TextStyle(
fontSize: 12,
color: _kMuted,
fontWeight: FontWeight.w600)),
const SizedBox(height: 4),
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: _uniqueId));
_snack('ID disalin ke clipboard.');
},
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: const Color(0xFFEFF6FF),
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
const Icon(Icons.qr_code_2,
color: _kBlue, size: 20),
const SizedBox(width: 10),
Text(
_uniqueId,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w800,
letterSpacing: 2,
color: _kBlue),
),
const Spacer(),
const Icon(Icons.copy,
color: _kMuted, size: 16),
],
),
// ── 1. TTS Settings ────────────────────────────────────────
_SectionHeader('1. TTS Settings', Icons.record_voice_over),
const SizedBox(height: 10),
_Card(
child: Column(
children: [
// Language (editable)
DropdownButtonFormField<String>(
value: _ttsLanguage,
decoration: const InputDecoration(
labelText: 'Bahasa TTS',
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(
horizontal: 12, vertical: 10),
),
items: const [
DropdownMenuItem(
value: 'id-ID',
child: Text('Bahasa Indonesia')),
DropdownMenuItem(
value: 'en-US', child: Text('English (US)')),
],
onChanged: (v) =>
setState(() => _ttsLanguage = v ?? _ttsLanguage),
),
const SizedBox(height: 12),
const Divider(height: 1),
const SizedBox(height: 12),
// Pitch — read-only info
_InfoRow(
label: 'Pitch',
value: _ttsPitch.toStringAsFixed(1),
note: 'Diatur oleh Guardian',
icon: Icons.tune,
),
const Divider(height: 20),
// Speed — read-only info
_InfoRow(
label: 'Speed',
value: _ttsSpeed.toStringAsFixed(1),
note: 'Diatur oleh Guardian',
icon: Icons.speed,
),
],
// pairing status
Row(
children: [
Icon(
_paired ? Icons.link : Icons.link_off,
color: _paired
? const Color(0xFF16A34A)
: const Color(0xFFD97706),
size: 20,
),
const SizedBox(width: 10),
Expanded(
child: Text(_pairingStatus,
style: TextStyle(
color: _paired
? const Color(0xFF166534)
: const Color(0xFF92400E),
fontWeight: FontWeight.w600)),
),
IconButton(
icon: const Icon(Icons.refresh, size: 18),
onPressed: () async {
await _loadPairing();
setState(() {});
},
tooltip: 'Refresh status',
),
],
),
const SizedBox(height: 8),
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: () => context.go('/user/pairing'),
icon: const Icon(Icons.manage_accounts_outlined),
label: const Text('Buka menu Pairing'),
),
),
const SizedBox(height: 20),
// ── 2. Pairing ─────────────────────────────────────────────
_SectionHeader('2. Pairing', Icons.link),
const SizedBox(height: 10),
_Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
_paired ? Icons.link : Icons.link_off,
color: _paired
? const Color(0xFF16A34A)
: const Color(0xFFD97706),
size: 20,
),
const SizedBox(width: 10),
Expanded(
child: Text(_pairingStatus,
style: TextStyle(
color: _paired
? const Color(0xFF166534)
: const Color(0xFF92400E),
fontWeight: FontWeight.w600)),
),
IconButton(
icon: const Icon(Icons.refresh, size: 18),
onPressed: () async {
await _loadPairing();
setState(() {});
},
tooltip: 'Refresh status',
),
],
),
),
],
const SizedBox(height: 8),
const Text(
'Kode pairing dibuat dari menu Pairing dan hanya valid sementara. Jangan pakai Unique User ID untuk pairing.',
style: TextStyle(
color: _kMuted,
fontSize: 12,
height: 1.35,
),
),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: () => context.go('/user/pairing'),
icon: const Icon(Icons.manage_accounts_outlined),
label: const Text('Buka menu Pairing'),
),
),
],
),
),
),
const SizedBox(height: 20),
const SizedBox(height: 20),
// ── 3. Manual / Instructions ───────────────────────────────
_SectionHeader('3. Manual & Instruksi', Icons.menu_book),
const SizedBox(height: 10),
_Card(
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.help_outline, color: _kBlue),
title: const Text('Daftar Voice Commands & Shortcuts'),
subtitle:
const Text('Lihat semua perintah suara yang tersedia'),
trailing: const Icon(Icons.chevron_right),
onTap: () {
// Route /user/manual belum ada di router —
// tambahkan GoRoute('/user/manual', ManualScreen) di router.dart
// lalu ganti baris ini dengan: context.go('/user/manual');
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Manual screen: tambah route /user/manual di router.dart')),
);
},
// ── 3. Manual / Instructions ───────────────────────────────
_SectionHeader('3. Manual & Instruksi', Icons.menu_book),
const SizedBox(height: 10),
_Card(
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: const Icon(Icons.help_outline, color: _kBlue),
title: const Text('Daftar Voice Commands & Shortcuts'),
subtitle: const Text(
'Lihat semua perintah suara yang tersedia'),
trailing: const Icon(Icons.chevron_right),
onTap: () {
context.go('/user/manual');
},
),
),
),
const SizedBox(height: 20),
const SizedBox(height: 20),
// ── 4. Caution Settings ────────────────────────────────────
_SectionHeader('4. Caution Settings', Icons.warning_amber),
const SizedBox(height: 10),
_Card(
child: Column(
children: [
SwitchListTile(
contentPadding: EdgeInsets.zero,
value: _warnNoGuardian,
onChanged: (v) => setState(() => _warnNoGuardian = v),
title: const Text('Peringatan belum paired'),
subtitle: const Text(
'TTS ingatkan jika belum terhubung Guardian'),
secondary: const Icon(
Icons.notifications_active_outlined,
color: _kBlue),
),
const Divider(height: 1),
SwitchListTile(
contentPadding: EdgeInsets.zero,
value: _hapticEnabled,
onChanged: (v) => setState(() => _hapticEnabled = v),
title: const Text('Haptic feedback'),
subtitle:
const Text('Getaran saat obstacle terdeteksi'),
secondary: const Icon(Icons.vibration, color: _kBlue),
),
],
// ── 4. Caution Settings ────────────────────────────────────
_SectionHeader('4. Caution Settings', Icons.warning_amber),
const SizedBox(height: 10),
_Card(
child: Column(
children: [
SwitchListTile(
contentPadding: EdgeInsets.zero,
value: _warnNoGuardian,
onChanged: (v) => setState(() => _warnNoGuardian = v),
title: const Text('Peringatan belum paired'),
subtitle: const Text(
'TTS ingatkan jika belum terhubung Guardian'),
secondary: const Icon(
Icons.notifications_active_outlined,
color: _kBlue),
),
const Divider(height: 1),
SwitchListTile(
contentPadding: EdgeInsets.zero,
value: _hapticEnabled,
onChanged: (v) {
sl<HapticService>().setEnabled(v);
setState(() => _hapticEnabled = v);
},
title: const Text('Haptic feedback'),
subtitle:
const Text('Getaran saat obstacle terdeteksi'),
secondary: const Icon(Icons.vibration, color: _kBlue),
),
],
),
),
),
const SizedBox(height: 20),
const SizedBox(height: 20),
// ── 5. Account ─────────────────────────────────────────────
_SectionHeader('5. Account', Icons.person),
const SizedBox(height: 10),
_Card(
child: Column(
children: [
_InfoRow(
label: 'Display Name',
value: _displayName.isNotEmpty ? _displayName : '—',
icon: Icons.badge_outlined,
),
const Divider(height: 20),
_InfoRow(
label: 'Role',
value: 'User',
icon: Icons.accessibility_new,
),
],
// ── 5. Account ─────────────────────────────────────────────
_SectionHeader('5. Account', Icons.person),
const SizedBox(height: 10),
_Card(
child: Column(
children: [
_InfoRow(
label: 'Display Name',
value: _displayName.isNotEmpty ? _displayName : '—',
icon: Icons.badge_outlined,
),
const Divider(height: 20),
_InfoRow(
label: 'Role',
value: 'User',
icon: Icons.accessibility_new,
),
],
),
),
),
const SizedBox(height: 24),
const SizedBox(height: 24),
// ── Save button ────────────────────────────────────────────
FilledButton.icon(
onPressed: _saving ? null : _save,
icon: _saving
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(
strokeWidth: 2, color: Colors.white))
: const Icon(Icons.save_outlined),
label: Text(_saving ? 'Menyimpan…' : 'Simpan Settings'),
style: FilledButton.styleFrom(
minimumSize: const Size.fromHeight(48),
// ── Save button ────────────────────────────────────────────
FilledButton.icon(
onPressed: _saving ? null : _save,
icon: _saving
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(
strokeWidth: 2, color: Colors.white))
: const Icon(Icons.save_outlined),
label: Text(_saving ? 'Menyimpan…' : 'Simpan Settings'),
style: FilledButton.styleFrom(
minimumSize: const Size.fromHeight(48),
),
),
),
const SizedBox(height: 10),
const SizedBox(height: 10),
// ── Change server ──────────────────────────────────────────
OutlinedButton.icon(
onPressed: _changeServer,
icon: const Icon(Icons.dns_outlined),
label: const Text('Ganti Server'),
style: OutlinedButton.styleFrom(
minimumSize: const Size.fromHeight(44),
// ── Change server ──────────────────────────────────────────
OutlinedButton.icon(
onPressed: _changeServer,
icon: const Icon(Icons.dns_outlined),
label: const Text('Ganti Server'),
style: OutlinedButton.styleFrom(
minimumSize: const Size.fromHeight(44),
),
),
),
const SizedBox(height: 10),
const SizedBox(height: 10),
// ── Logout ─────────────────────────────────────────────────
OutlinedButton.icon(
onPressed: () => _confirmLogout(context),
icon: const Icon(Icons.logout, color: _kRed),
label: const Text('Logout', style: TextStyle(color: _kRed)),
style: OutlinedButton.styleFrom(
minimumSize: const Size.fromHeight(44),
side: const BorderSide(color: _kRed),
// ── Logout ─────────────────────────────────────────────────
OutlinedButton.icon(
onPressed: () => _confirmLogout(context),
icon: const Icon(Icons.logout, color: _kRed),
label: const Text('Logout', style: TextStyle(color: _kRed)),
style: OutlinedButton.styleFrom(
minimumSize: const Size.fromHeight(44),
side: const BorderSide(color: _kRed),
),
),
),
const SizedBox(height: 32),
],
),
const SizedBox(height: 32),
],
),
),
);
}
@@ -489,11 +456,18 @@ class _SectionHeader extends StatelessWidget {
Widget build(BuildContext context) {
return Row(
children: [
Icon(icon, size: 18, color: _kBlue),
Container(
width: 36,
height: 36,
decoration: AppDecorations.iconCircle(color: AppColors.softBlueBg),
child: Icon(icon, size: 18, color: AppColors.primaryBlue),
),
const SizedBox(width: 8),
Text(title,
style: const TextStyle(
fontWeight: FontWeight.w800, fontSize: 14, color: _kBlue)),
fontWeight: FontWeight.w800,
fontSize: 14,
color: AppColors.primaryBlue)),
],
);
}
@@ -510,8 +484,8 @@ class _Card extends StatelessWidget {
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: _kBorder),
borderRadius: BorderRadius.circular(20),
boxShadow: AppDecorations.cardShadow,
),
child: child,
);
@@ -533,16 +507,22 @@ class _InfoRow extends StatelessWidget {
Widget build(BuildContext context) {
return Row(
children: [
Icon(icon, size: 18, color: _kMuted),
Container(
width: 36,
height: 36,
decoration: AppDecorations.iconCircle(color: AppColors.softBlueBg),
child: Icon(icon, size: 18, color: AppColors.primaryBlue),
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: const TextStyle(fontSize: 12, color: _kMuted)),
Text(label,
style: const TextStyle(fontSize: 12, color: AppColors.muted)),
Text(value,
style: const TextStyle(
fontWeight: FontWeight.w700, color: _kText)),
fontWeight: FontWeight.w700, color: AppColors.textDark)),
],
),
),
@@ -550,12 +530,12 @@ class _InfoRow extends StatelessWidget {
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: _kSurface,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: _kBorder),
color: AppColors.softBlueBg,
borderRadius: BorderRadius.circular(50),
border: Border.all(color: AppColors.border),
),
child: Text(note!,
style: const TextStyle(fontSize: 11, color: _kMuted)),
style: const TextStyle(fontSize: 11, color: AppColors.muted)),
),
],
);