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:
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../core/locale/unit_provider.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../shared/models/recipe.dart';
|
||||
import '../../shared/models/saved_recipe.dart';
|
||||
@@ -370,13 +371,13 @@ class _TagsRow extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _IngredientsSection extends StatelessWidget {
|
||||
class _IngredientsSection extends ConsumerWidget {
|
||||
final List<RecipeIngredient> ingredients;
|
||||
|
||||
const _IngredientsSection({required this.ingredients});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
if (ingredients.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
return Padding(
|
||||
@@ -401,7 +402,7 @@ class _IngredientsSection extends StatelessWidget {
|
||||
const SizedBox(width: 10),
|
||||
Expanded(child: Text(ing.name)),
|
||||
Text(
|
||||
'${_formatAmount(ing.amount)} ${ing.unit}',
|
||||
'${_formatAmount(ing.amount)} ${ref.watch(unitsProvider).valueOrNull?[ing.unit] ?? ing.unit}',
|
||||
style: const TextStyle(
|
||||
color: AppColors.textSecondary, fontSize: 13),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user