Skip to content

Commit

Permalink
Languages selector in a modal sheet (#6316)
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k authored Jan 30, 2025
1 parent 61585ca commit d8e1016
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 233 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:math' as math;

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -92,6 +93,7 @@ class UserPreferences extends ChangeNotifier {
static const String _TAG_SEARCH_SHOW_PRODUCT_TYPE_FILTER =
'_search_show_product_type_filter';
static const String _TAG_PRODUCT_PAGE_ACTIONS = '_product_page_actions';
static const String _TAG_LANGUAGES_USAGE = '_languages_usage';

/// Camera preferences
Expand Down Expand Up @@ -544,4 +546,30 @@ class UserPreferences extends ChangeNotifier {
);
notifyListeners();
}

void increaseLanguageUsage(final OpenFoodFactsLanguage language) {
final String? usage = _sharedPreferences.getString(_TAG_LANGUAGES_USAGE);
final Map<String, int> languages;
if (usage == null || usage.isEmpty) {
languages = <String, int>{};
} else {
languages = Map<String, int>.from(jsonDecode(usage));
}

languages[language.code] = (languages[language.code] ?? 0) + 1;
unawaited(
_sharedPreferences.setString(
_TAG_LANGUAGES_USAGE,
jsonEncode(languages),
),
);
}

Map<String, int> get languagesUsage {
final String? usage = _sharedPreferences.getString(_TAG_LANGUAGES_USAGE);
if (usage == null || usage.isEmpty) {
return <String, int>{};
}
return Map<String, int>.from(jsonDecode(usage));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ Future<T?> showSmoothModalSheetForTextField<T>({
required BuildContext context,
required SmoothModalSheetHeader header,
required WidgetBuilder bodyBuilder,
double? minHeight,
double? maxHeight,
}) {
return showSmoothModalSheet<T>(
context: context,
minHeight: minHeight,
maxHeight: maxHeight,
builder: (BuildContext context) => SizedBox(
width: double.infinity,
child: ClipRRect(
Expand Down
92 changes: 0 additions & 92 deletions packages/smooth_app/lib/generic_lib/widgets/language_priority.dart

This file was deleted.

Loading

0 comments on commit d8e1016

Please sign in to comment.