diff --git a/lib/ui/common/controls/locale_button.dart b/lib/ui/common/controls/locale_button.dart index 5d958d95..3f9b3914 100644 --- a/lib/ui/common/controls/locale_button.dart +++ b/lib/ui/common/controls/locale_button.dart @@ -1,37 +1,19 @@ -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 _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(); - } +class LocaleButton extends StatelessWidget with GetItMixin { + LocaleButton({Key? key}) : super(key: key); @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: ValueListenableBuilder( - valueListenable: settingsLogic.currentLocale, - builder: (_, __, ___) { - return Text($strings.localeSwapButton, style: $styles.text.btn.copyWith(color: $styles.colors.white)); - }, - ), - ), - ); + final locale = watchX((SettingsLogic s) => s.currentLocale); + Future handleSwapLocale() async { + final newLocale = Locale(locale == 'en' ? 'zh' : 'en'); + await settingsLogic.setLocale(newLocale); + } + + return AppBtn.from( + padding: EdgeInsets.symmetric(vertical: $styles.insets.sm, horizontal: $styles.insets.sm), + text: $strings.localeSwapButton, + onPressed: handleSwapLocale); } }