Files
FlClash/lib/common/app_localizations.dart
T
chen08209 f14e6f1460 feat(ui): rework the profile, provider, and subscription surfaces
Refines the profile, provider, and configuration interactions, virtualizes
the provider lists so a large subscription no longer builds every row, syncs
updates through the path the list reads, and expands the subscription
details with full usage.

Paged sheets are scoped locally and sized to the page in view instead of the
tallest one, so a sheet no longer reserves space it never uses.

Changelog: Provider lists scroll smoothly, subscriptions show full usage details, and sheets size to the page in view
2026-08-28 10:07:17 +08:00

51 lines
1.4 KiB
Dart

import 'package:dio/dio.dart';
import 'package:fl_clash/core/method.dart';
import 'package:fl_clash/l10n/l10n.dart';
import 'dart:ui';
final currentAppLocalizations = AppLocalizations.current;
String? networkErrorMessage(Object error, AppLocalizations appLocalizations) {
if (error case CoreMethodException(:final code)) {
return switch (code) {
'request_bad_response' => appLocalizations.networkException,
'request_error' => appLocalizations.unknownNetworkError,
_ => null,
};
}
if (error is DioException) {
return error.type == DioExceptionType.badResponse
? appLocalizations.networkException
: appLocalizations.unknownNetworkError;
}
return null;
}
String userFacingErrorMessage(Object error, AppLocalizations appLocalizations) {
return networkErrorMessage(error, appLocalizations) ??
switch (error) {
CoreMethodException(:final message) => message,
_ => error.toString(),
};
}
Locale? getLocaleForString(String? localString) {
if (localString == null) return null;
final localSplit = localString.split('_');
if (localSplit.length == 1) {
return Locale(localSplit[0]);
}
if (localSplit.length == 2) {
return Locale(localSplit[0], localSplit[1]);
}
if (localSplit.length == 3) {
return Locale.fromSubtags(
languageCode: localSplit[0],
scriptCode: localSplit[1],
countryCode: localSplit[2],
);
}
return null;
}