-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
587 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:era_connect_i18n/era_connect_i18n.dart'; | ||
import 'package:era_connect_ui/era_connect_ui.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class SetupDialog extends StatelessWidget { | ||
const SetupDialog({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return InteractiveDialog( | ||
title: context.i18n['dialog.setup.01.title'], | ||
description: context.i18n['dialog.setup.01.description'], | ||
logoBoxText: '01', | ||
body: Padding( | ||
padding: | ||
const EdgeInsets.only(top: 45, bottom: 35, left: 45, right: 45), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text( | ||
context.i18n['dialog.setup.01.content.title'], | ||
style: TextStyle( | ||
color: context.theme.textColor, | ||
fontSize: 40, | ||
fontWeight: FontWeight.w700, | ||
), | ||
), | ||
Text( | ||
context.i18n['dialog.setup.01.content.description'], | ||
style: TextStyle( | ||
color: context.theme.tertiaryTextColor, fontSize: 15), | ||
), | ||
const SizedBox(height: 25), | ||
DialogRectangleTab( | ||
title: '選擇方式', | ||
tabs: [ | ||
TabItem( | ||
title: | ||
context.i18n['dialog.setup.01.content.tabs.empty.title'], | ||
icon: 'deployed_code', | ||
content: | ||
const Text('這是從頭開始的頁面', style: TextStyle(fontSize: 30)), | ||
), | ||
TabItem( | ||
title: context | ||
.i18n['dialog.setup.01.content.tabs.import.title'], | ||
icon: 'deployed_code_update', | ||
content: const Text('這是匯入設定的頁面', | ||
style: TextStyle(fontSize: 50))), | ||
], | ||
) | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import 'package:era_connect_i18n/i18n_locale.dart'; | ||
import 'package:era_connect_i18n/i18n_manager.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
import 'i18n_manager_test.mocks.dart'; | ||
|
||
@GenerateNiceMocks( | ||
[MockSpec<AssetBundle>(onMissingStub: OnMissingStub.throwException)]) | ||
void main() { | ||
group('I18nManager', () { | ||
test('loads translations from JSON files', () async { | ||
// Arrange | ||
final i18nManager = I18nManager( | ||
path: 'assets/i18n', | ||
defaultLocale: I18nLocale.americanEnglish, | ||
); | ||
final mockAssetBundle = MockAssetBundle(); | ||
const jsonString = '{"hello": "Hello", "world": "World"}'; | ||
|
||
when(mockAssetBundle.loadString('assets/i18n/en-US.json')) | ||
.thenAnswer((_) => Future.value(jsonString)); | ||
when(mockAssetBundle.loadString('assets/i18n/zh-TW.json')) | ||
.thenAnswer((_) => Future.value('{}')); | ||
|
||
// Act | ||
await i18nManager.load(mockAssetBundle); | ||
|
||
// Assert | ||
expect(i18nManager.defaultLocale, equals(I18nLocale.americanEnglish)); | ||
expect(i18nManager['hello'], equals('Hello')); | ||
expect(i18nManager['world'], equals('World')); | ||
}); | ||
|
||
test('returns the key if no translation is found', () async { | ||
// Arrange | ||
final i18nManager = I18nManager( | ||
path: 'assets/i18n', | ||
defaultLocale: I18nLocale.americanEnglish, | ||
); | ||
|
||
final mockAssetBundle = MockAssetBundle(); | ||
when(mockAssetBundle.loadString('assets/i18n/en-US.json')) | ||
.thenAnswer((_) => Future.value('{}')); | ||
when(mockAssetBundle.loadString('assets/i18n/zh-TW.json')) | ||
.thenAnswer((_) => Future.value('{}')); | ||
|
||
// Act | ||
await i18nManager.load(mockAssetBundle); | ||
|
||
// Assert | ||
expect(i18nManager['missing_key'], equals('missing_key')); | ||
}); | ||
|
||
test('sets the current locale', () { | ||
// Arrange | ||
final i18nManager = I18nManager( | ||
path: 'assets/i18n', | ||
defaultLocale: I18nLocale.americanEnglish, | ||
); | ||
|
||
// Act | ||
i18nManager.setLocale(I18nLocale.traditionalChineseTW); | ||
|
||
// Assert | ||
expect(i18nManager.locale, equals(I18nLocale.traditionalChineseTW)); | ||
}); | ||
|
||
test('notifies listeners when the locale is changed', () { | ||
// Arrange | ||
final i18nManager = I18nManager( | ||
path: 'assets/i18n', | ||
defaultLocale: I18nLocale.americanEnglish, | ||
); | ||
var notified = false; | ||
i18nManager.addListener(() { | ||
notified = true; | ||
}); | ||
|
||
// Act | ||
i18nManager.setLocale(I18nLocale.traditionalChineseTW); | ||
|
||
// Assert | ||
expect(notified, isTrue); | ||
}); | ||
|
||
testWidgets('get i18n manager from build context', (tester) async { | ||
// Arrange | ||
final i18nManager = I18nManager( | ||
path: 'assets/i18n', | ||
defaultLocale: I18nLocale.americanEnglish, | ||
); | ||
final mockAssetBundle = MockAssetBundle(); | ||
const jsonString = '{"hello": "Hello", "world": "World"}'; | ||
|
||
when(mockAssetBundle.loadString('assets/i18n/en-US.json')) | ||
.thenAnswer((_) => Future.value(jsonString)); | ||
when(mockAssetBundle.loadString('assets/i18n/zh-TW.json')) | ||
.thenAnswer((_) => Future.value('{}')); | ||
|
||
// Act | ||
await i18nManager.load(mockAssetBundle); | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: ChangeNotifierProvider( | ||
create: (context) => i18nManager, | ||
child: Builder( | ||
builder: (context) { | ||
final i18nManager = context.i18n; | ||
return Column( | ||
children: [ | ||
Text(i18nManager['hello']), | ||
Text(i18nManager['world']), | ||
], | ||
); | ||
}, | ||
), | ||
)), | ||
); | ||
|
||
// Assert | ||
expect(find.text('Hello'), findsOneWidget); | ||
expect(find.text('World'), findsOneWidget); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.