Add Locale button
- add LocaleButton to intro and menu, toasted placeholder in app_scaffold - add localeLogic.isEnglish helper, used in _results_grid and _scrolling_content
This commit is contained in:
parent
466fe074b8
commit
726cc6d5e7
@ -11,6 +11,8 @@ class LocaleLogic {
|
|||||||
|
|
||||||
bool get isLoaded => _strings != null;
|
bool get isLoaded => _strings != null;
|
||||||
|
|
||||||
|
bool get isEnglish => strings.localeName == 'en';
|
||||||
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
final localeCode = await findSystemLocale();
|
final localeCode = await findSystemLocale();
|
||||||
Locale locale = Locale(localeCode.split('_')[0]);
|
Locale locale = Locale(localeCode.split('_')[0]);
|
||||||
|
@ -5,15 +5,6 @@ class WondersAppScaffold extends StatelessWidget with GetItMixin {
|
|||||||
WondersAppScaffold({Key? key, required this.child}) : super(key: key);
|
WondersAppScaffold({Key? key, required this.child}) : super(key: key);
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
Future<void> _handleSwapLocale() async {
|
|
||||||
final currentLocale = settingsLogic.currentLocale.value;
|
|
||||||
final newLocale = Locale(currentLocale == 'en' ? 'zh' : 'en');
|
|
||||||
settingsLogic.currentLocale.value = newLocale.languageCode;
|
|
||||||
await localeLogic.refreshIfChanged(newLocale);
|
|
||||||
wondersLogic.init();
|
|
||||||
timelineLogic.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Animate.defaultDuration = $styles.times.fast;
|
Animate.defaultDuration = $styles.times.fast;
|
||||||
@ -31,24 +22,6 @@ class WondersAppScaffold extends StatelessWidget with GetItMixin {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
//TODO: just some test UI to check swapping behavior, need to get finalized design and location
|
|
||||||
Align(
|
|
||||||
alignment: Alignment.topRight,
|
|
||||||
child: SafeArea(
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: _handleSwapLocale,
|
|
||||||
child: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: $styles.colors.greyStrong.withOpacity(.7),
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular($styles.corners.md)),
|
|
||||||
),
|
|
||||||
padding: EdgeInsets.all($styles.insets.sm),
|
|
||||||
child: Text($strings.localeSwapButton, style: $styles.text.btn.copyWith(color: $styles.colors.white)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
32
lib/ui/common/controls/locale_button.dart
Normal file
32
lib/ui/common/controls/locale_button.dart
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import 'package:flutter/src/foundation/key.dart';
|
||||||
|
import 'package:flutter/src/widgets/container.dart';
|
||||||
|
import 'package:flutter/src/widgets/framework.dart';
|
||||||
|
import 'package:wonders/common_libs.dart';
|
||||||
|
|
||||||
|
class LocaleButton extends StatelessWidget {
|
||||||
|
const LocaleButton({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
Future<void> _handleSwapLocale() async {
|
||||||
|
final currentLocale = settingsLogic.currentLocale.value;
|
||||||
|
final newLocale = Locale(currentLocale == 'en' ? 'zh' : 'en');
|
||||||
|
settingsLogic.currentLocale.value = newLocale.languageCode;
|
||||||
|
await localeLogic.refreshIfChanged(newLocale);
|
||||||
|
wondersLogic.init();
|
||||||
|
timelineLogic.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return TextButton(
|
||||||
|
onPressed: _handleSwapLocale,
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: $styles.colors.greyStrong.withOpacity(.7),
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular($styles.corners.md)),
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all($styles.insets.sm),
|
||||||
|
child: Text($strings.localeSwapButton, style: $styles.text.btn.copyWith(color: $styles.colors.white)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -31,11 +31,10 @@ class _ResultsGrid extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildLanguageMessage(BuildContext context) {
|
Widget _buildLanguageMessage(BuildContext context) {
|
||||||
bool isEnglish = localeLogic.strings.localeName == 'en';
|
|
||||||
return ValueListenableBuilder<bool>(
|
return ValueListenableBuilder<bool>(
|
||||||
valueListenable: settingsLogic.hasDismissedSearchMessage,
|
valueListenable: settingsLogic.hasDismissedSearchMessage,
|
||||||
builder: (_, value, __) {
|
builder: (_, value, __) {
|
||||||
if (isEnglish || value) return SizedBox();
|
if (localeLogic.isEnglish || value) return SizedBox();
|
||||||
return AppBtn.basic(
|
return AppBtn.basic(
|
||||||
onPressed: () => settingsLogic.hasDismissedSearchMessage.value = true,
|
onPressed: () => settingsLogic.hasDismissedSearchMessage.value = true,
|
||||||
semanticLabel: $strings.resultsSemanticDismiss,
|
semanticLabel: $strings.resultsSemanticDismiss,
|
||||||
|
@ -28,8 +28,7 @@ class _ScrollingContent extends StatelessWidget {
|
|||||||
final String dropChar = value.substring(0, 1);
|
final String dropChar = value.substring(0, 1);
|
||||||
final textScale = MediaQuery.of(context).textScaleFactor;
|
final textScale = MediaQuery.of(context).textScaleFactor;
|
||||||
final double dropCapWidth = StringUtils.measure(dropChar, dropStyle).width * textScale;
|
final double dropCapWidth = StringUtils.measure(dropChar, dropStyle).width * textScale;
|
||||||
final bool isEnglish = localeLogic.strings.localeName == 'en'; //TODO EC: Helper method for localLogic.isEnglish?
|
final bool skipCaps = !localeLogic.isEnglish || MediaQuery.of(context).accessibleNavigation;
|
||||||
final bool skipCaps = !isEnglish || MediaQuery.of(context).accessibleNavigation;
|
|
||||||
return Semantics(
|
return Semantics(
|
||||||
label: value,
|
label: value,
|
||||||
child: !skipCaps
|
child: !skipCaps
|
||||||
|
@ -4,6 +4,7 @@ import 'package:wonders/common_libs.dart';
|
|||||||
import 'package:wonders/logic/data/wonder_data.dart';
|
import 'package:wonders/logic/data/wonder_data.dart';
|
||||||
import 'package:wonders/ui/common/app_backdrop.dart';
|
import 'package:wonders/ui/common/app_backdrop.dart';
|
||||||
import 'package:wonders/ui/common/app_icons.dart';
|
import 'package:wonders/ui/common/app_icons.dart';
|
||||||
|
import 'package:wonders/ui/common/controls/locale_button.dart';
|
||||||
import 'package:wonders/ui/screens/home_menu/about_dialog_content.dart';
|
import 'package:wonders/ui/screens/home_menu/about_dialog_content.dart';
|
||||||
|
|
||||||
class HomeMenu extends StatelessWidget {
|
class HomeMenu extends StatelessWidget {
|
||||||
@ -75,7 +76,17 @@ class HomeMenu extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
Positioned(
|
||||||
|
right: -$styles.insets.xs,
|
||||||
|
top: $styles.insets.xs,
|
||||||
|
child: SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: $styles.insets.lg),
|
||||||
|
child: LocaleButton(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import 'package:flutter_svg/flutter_svg.dart';
|
|||||||
import 'package:wonders/common_libs.dart';
|
import 'package:wonders/common_libs.dart';
|
||||||
import 'package:wonders/ui/common/app_icons.dart';
|
import 'package:wonders/ui/common/app_icons.dart';
|
||||||
import 'package:wonders/ui/common/controls/app_page_indicator.dart';
|
import 'package:wonders/ui/common/controls/app_page_indicator.dart';
|
||||||
|
import 'package:wonders/ui/common/controls/locale_button.dart';
|
||||||
import 'package:wonders/ui/common/static_text_scale.dart';
|
import 'package:wonders/ui/common/static_text_scale.dart';
|
||||||
import 'package:wonders/ui/common/themed_text.dart';
|
import 'package:wonders/ui/common/themed_text.dart';
|
||||||
import 'package:wonders/ui/common/utils/app_haptics.dart';
|
import 'package:wonders/ui/common/utils/app_haptics.dart';
|
||||||
@ -137,6 +138,12 @@ class _IntroScreenState extends State<IntroScreen> {
|
|||||||
child: _buildNavText(context),
|
child: _buildNavText(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
Positioned(
|
||||||
|
right: 0,
|
||||||
|
top: 0,
|
||||||
|
child: LocaleButton(),
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return DefaultTextColor(
|
return DefaultTextColor(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user