Files
submanager/lib/providers/navigation_provider.dart
JiWoong Sul 0f0b02bf08 feat: 다국어 지원 및 다중 통화 환율 변환 기능 확대
- ExchangeRateService에 JPY, CNY 환율 지원 추가
- 구독 서비스별 다국어 표시 이름 지원
- 분석 화면 차트 및 UI/UX 개선
- 설정 화면 전면 리팩토링
- SMS 스캔 기능 사용성 개선
- 전체 앱 다국어 번역 확대

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 17:34:32 +09:00

106 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
class NavigationProvider extends ChangeNotifier {
int _currentIndex = 0;
final List<int> _navigationHistory = [0];
String _currentRoute = '/';
String _currentTitle = 'home';
int get currentIndex => _currentIndex;
List<int> get navigationHistory => List.unmodifiable(_navigationHistory);
String get currentRoute => _currentRoute;
String get currentTitle => _currentTitle;
static const Map<String, int> routeToIndex = {
'/': 0,
'/add-subscription': -1,
'/sms-scanner': 3,
'/analysis': 1,
'/settings': 4,
'/subscription-detail': -1,
};
static const Map<int, String> indexToRoute = {
0: '/',
1: '/analysis',
3: '/sms-scanner',
4: '/settings',
};
static const Map<int, String> indexToTitle = {
0: 'home',
1: 'analysis',
3: 'smsScanLabel',
4: 'settings',
};
void updateCurrentIndex(int index, {bool addToHistory = true}) {
if (_currentIndex == index) return;
_currentIndex = index;
_currentRoute = indexToRoute[index] ?? '/';
_currentTitle = indexToTitle[index] ?? 'home';
if (addToHistory && index >= 0) {
_navigationHistory.add(index);
if (_navigationHistory.length > 10) {
_navigationHistory.removeAt(0);
}
}
notifyListeners();
}
void updateByRoute(String route) {
final index = routeToIndex[route] ?? 0;
_currentRoute = route;
if (index >= 0) {
_currentIndex = index;
_currentTitle = indexToTitle[index] ?? 'home';
} else {
switch (route) {
case '/add-subscription':
_currentTitle = 'addSubscription';
break;
case '/subscription-detail':
_currentTitle = 'subscriptionDetail';
break;
default:
_currentTitle = 'home';
}
}
notifyListeners();
}
bool canPop() {
return _navigationHistory.length > 1;
}
void pop() {
if (_navigationHistory.length > 1) {
_navigationHistory.removeLast();
final previousIndex = _navigationHistory.last;
updateCurrentIndex(previousIndex, addToHistory: false);
}
}
void reset() {
_currentIndex = 0;
_currentRoute = '/';
_currentTitle = 'home';
_navigationHistory.clear();
_navigationHistory.add(0);
notifyListeners();
}
void clearHistoryAndGoHome() {
_currentIndex = 0;
_currentRoute = '/';
_currentTitle = 'home';
_navigationHistory.clear();
_navigationHistory.add(0);
notifyListeners();
}
}