Browse Source

fix(neon_dashboard): Fix localizations class name

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/1036/head
jld3103 1 year ago
parent
commit
b3c36b2f26
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 1
      packages/neon/neon_dashboard/l10n.yaml
  2. 38
      packages/neon/neon_dashboard/lib/l10n/localizations.dart
  3. 4
      packages/neon/neon_dashboard/lib/l10n/localizations_en.dart
  4. 4
      packages/neon/neon_dashboard/lib/src/app.dart
  5. 2
      packages/neon/neon_dashboard/lib/src/widgets/widget.dart
  6. 4
      packages/neon/neon_dashboard/test/widget_test.dart

1
packages/neon/neon_dashboard/l10n.yaml

@ -2,5 +2,6 @@ arb-dir: lib/l10n
template-arb-file: en.arb template-arb-file: en.arb
output-localization-file: localizations.dart output-localization-file: localizations.dart
synthetic-package: false synthetic-package: false
output-class: DashboardLocalizations
output-dir: lib/l10n output-dir: lib/l10n
nullable-getter: false nullable-getter: false

38
packages/neon/neon_dashboard/lib/l10n/localizations.dart

@ -7,10 +7,10 @@ import 'package:intl/intl.dart' as intl;
import 'localizations_en.dart'; import 'localizations_en.dart';
/// Callers can lookup localized strings with an instance of AppLocalizations /// Callers can lookup localized strings with an instance of DashboardLocalizations
/// returned by `AppLocalizations.of(context)`. /// returned by `DashboardLocalizations.of(context)`.
/// ///
/// Applications need to include `AppLocalizations.delegate()` in their app's /// Applications need to include `DashboardLocalizations.delegate()` in their app's
/// `localizationDelegates` list, and the locales they support in the app's /// `localizationDelegates` list, and the locales they support in the app's
/// `supportedLocales` list. For example: /// `supportedLocales` list. For example:
/// ///
@ -18,8 +18,8 @@ import 'localizations_en.dart';
/// import 'l10n/localizations.dart'; /// import 'l10n/localizations.dart';
/// ///
/// return MaterialApp( /// return MaterialApp(
/// localizationsDelegates: AppLocalizations.localizationsDelegates, /// localizationsDelegates: DashboardLocalizations.localizationsDelegates,
/// supportedLocales: AppLocalizations.supportedLocales, /// supportedLocales: DashboardLocalizations.supportedLocales,
/// home: MyApplicationHome(), /// home: MyApplicationHome(),
/// ); /// );
/// ``` /// ```
@ -56,18 +56,18 @@ import 'localizations_en.dart';
/// Select and expand the newly-created Localizations item then, for each /// Select and expand the newly-created Localizations item then, for each
/// locale your application supports, add a new item and select the locale /// locale your application supports, add a new item and select the locale
/// you wish to add from the pop-up menu in the Value field. This list should /// you wish to add from the pop-up menu in the Value field. This list should
/// be consistent with the languages listed in the AppLocalizations.supportedLocales /// be consistent with the languages listed in the DashboardLocalizations.supportedLocales
/// property. /// property.
abstract class AppLocalizations { abstract class DashboardLocalizations {
AppLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString()); DashboardLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
final String localeName; final String localeName;
static AppLocalizations of(BuildContext context) { static DashboardLocalizations of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations)!; return Localizations.of<DashboardLocalizations>(context, DashboardLocalizations)!;
} }
static const LocalizationsDelegate<AppLocalizations> delegate = _AppLocalizationsDelegate(); static const LocalizationsDelegate<DashboardLocalizations> delegate = _DashboardLocalizationsDelegate();
/// A list of this localizations delegate along with the default localizations /// A list of this localizations delegate along with the default localizations
/// delegates. /// delegates.
@ -96,29 +96,29 @@ abstract class AppLocalizations {
String get noEntries; String get noEntries;
} }
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> { class _DashboardLocalizationsDelegate extends LocalizationsDelegate<DashboardLocalizations> {
const _AppLocalizationsDelegate(); const _DashboardLocalizationsDelegate();
@override @override
Future<AppLocalizations> load(Locale locale) { Future<DashboardLocalizations> load(Locale locale) {
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale)); return SynchronousFuture<DashboardLocalizations>(lookupDashboardLocalizations(locale));
} }
@override @override
bool isSupported(Locale locale) => <String>['en'].contains(locale.languageCode); bool isSupported(Locale locale) => <String>['en'].contains(locale.languageCode);
@override @override
bool shouldReload(_AppLocalizationsDelegate old) => false; bool shouldReload(_DashboardLocalizationsDelegate old) => false;
} }
AppLocalizations lookupAppLocalizations(Locale locale) { DashboardLocalizations lookupDashboardLocalizations(Locale locale) {
// Lookup logic when only language code is specified. // Lookup logic when only language code is specified.
switch (locale.languageCode) { switch (locale.languageCode) {
case 'en': case 'en':
return AppLocalizationsEn(); return DashboardLocalizationsEn();
} }
throw FlutterError('AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely ' throw FlutterError('DashboardLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue ' 'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration ' 'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.'); 'that was used.');

4
packages/neon/neon_dashboard/lib/l10n/localizations_en.dart

@ -1,8 +1,8 @@
import 'localizations.dart'; import 'localizations.dart';
/// The translations for English (`en`). /// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations { class DashboardLocalizationsEn extends DashboardLocalizations {
AppLocalizationsEn([String locale = 'en']) : super(locale); DashboardLocalizationsEn([String locale = 'en']) : super(locale);
@override @override
String get noEntries => 'No entries'; String get noEntries => 'No entries';

4
packages/neon/neon_dashboard/lib/src/app.dart

@ -18,10 +18,10 @@ class DashboardApp extends AppImplementation<DashboardBloc, DashboardAppSpecific
final String id = AppIDs.dashboard; final String id = AppIDs.dashboard;
@override @override
final LocalizationsDelegate<AppLocalizations> localizationsDelegate = AppLocalizations.delegate; final LocalizationsDelegate<DashboardLocalizations> localizationsDelegate = DashboardLocalizations.delegate;
@override @override
final List<Locale> supportedLocales = AppLocalizations.supportedLocales; final List<Locale> supportedLocales = DashboardLocalizations.supportedLocales;
@override @override
late final DashboardAppSpecificOptions options = DashboardAppSpecificOptions(storage); late final DashboardAppSpecificOptions options = DashboardAppSpecificOptions(storage);

2
packages/neon/neon_dashboard/lib/src/widgets/widget.dart

@ -60,7 +60,7 @@ class DashboardWidget extends StatelessWidget {
if (halfEmptyContentMessage != null) halfEmptyContentMessage, if (halfEmptyContentMessage != null) halfEmptyContentMessage,
if (emptyContentMessage != null) emptyContentMessage, if (emptyContentMessage != null) emptyContentMessage,
if (halfEmptyContentMessage == null && emptyContentMessage == null && (items?.items.isEmpty ?? true)) if (halfEmptyContentMessage == null && emptyContentMessage == null && (items?.items.isEmpty ?? true))
_renderMessage(AppLocalizations.of(context).noEntries)!, _renderMessage(DashboardLocalizations.of(context).noEntries)!,
...?items?.items.map( ...?items?.items.map(
(final item) => DashboardWidgetItem( (final item) => DashboardWidgetItem(
item: item, item: item,

4
packages/neon/neon_dashboard/test/widget_test.dart

@ -17,8 +17,8 @@ import 'package:rxdart/rxdart.dart';
class MockAccountsBloc extends Mock implements AccountsBloc {} class MockAccountsBloc extends Mock implements AccountsBloc {}
Widget wrapWidget(final AccountsBloc accountsBloc, final Widget child) => MaterialApp( Widget wrapWidget(final AccountsBloc accountsBloc, final Widget child) => MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates, localizationsDelegates: DashboardLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales, supportedLocales: DashboardLocalizations.supportedLocales,
home: Scaffold( home: Scaffold(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
body: NeonProvider<AccountsBloc>.value( body: NeonProvider<AccountsBloc>.value(

Loading…
Cancel
Save