Switch LocalBtn to use AppBtn
This commit is contained in:
parent
b080a5b2e9
commit
31be98dd26
@ -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<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();
|
||||
}
|
||||
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<void> 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user