feat: dynamic units table with localized names via GET /units
- Add units + unit_translations tables with FK constraints on products and ingredient_mappings - Normalize products.unit from Russian strings (г, кг) to English codes (g, kg) - Load units at startup (in-memory registry) and serve via GET /units (language-aware) - Replace hardcoded _units lists and _mapUnit() functions in Flutter with unitsProvider FutureProvider - Re-fetches automatically when language changes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
12
client/lib/core/locale/unit_provider.dart
Normal file
12
client/lib/core/locale/unit_provider.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../api/unit_repository.dart';
|
||||
import 'language_provider.dart';
|
||||
|
||||
/// Fetches and caches units with localized names.
|
||||
/// Returns map of code → localized name (e.g. {'g': 'г', 'kg': 'кг'}).
|
||||
/// Re-fetches automatically when languageProvider changes.
|
||||
final unitsProvider = FutureProvider<Map<String, String>>((ref) {
|
||||
ref.watch(languageProvider); // invalidate when language changes
|
||||
return ref.read(unitRepositoryProvider).fetchUnits();
|
||||
});
|
||||
Reference in New Issue
Block a user