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';
|
import 'package:wonders/common_libs.dart';
|
||||||
|
|
||||||
class LocaleButton extends StatelessWidget {
|
class LocaleButton extends StatelessWidget with GetItMixin {
|
||||||
const LocaleButton({Key? key}) : super(key: key);
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return TextButton(
|
final locale = watchX((SettingsLogic s) => s.currentLocale);
|
||||||
onPressed: _handleSwapLocale,
|
Future<void> handleSwapLocale() async {
|
||||||
child: Container(
|
final newLocale = Locale(locale == 'en' ? 'zh' : 'en');
|
||||||
decoration: BoxDecoration(
|
await settingsLogic.setLocale(newLocale);
|
||||||
color: $styles.colors.greyStrong.withOpacity(.7),
|
}
|
||||||
borderRadius: BorderRadius.all(Radius.circular($styles.corners.md)),
|
|
||||||
),
|
return AppBtn.from(
|
||||||
padding: EdgeInsets.all($styles.insets.sm),
|
padding: EdgeInsets.symmetric(vertical: $styles.insets.sm, horizontal: $styles.insets.sm),
|
||||||
child: ValueListenableBuilder(
|
text: $strings.localeSwapButton,
|
||||||
valueListenable: settingsLogic.currentLocale,
|
onPressed: handleSwapLocale);
|
||||||
builder: (_, __, ___) {
|
|
||||||
return Text($strings.localeSwapButton, style: $styles.text.btn.copyWith(color: $styles.colors.white));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user