Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The mobile phone system is in Chinese, the app can not be directly changed in other languages for the first time #711

Open
wangzhipeng-vicky opened this issue Sep 12, 2024 · 0 comments

Comments

@wangzhipeng-vicky
Copy link

The mobile phone system is Chinese, if the app comes in in English for the first time, I change it to Chinese, set context.setLocale, and I see it succeeds in the console, but it doesn't change to Chinese in the app; It only worked when I changed to English and then to Chinese again.
Similar: if the mobile phone system is English, just opened the app if it is Chinese, I change to English, but also the console to see the success, the app in fact has not changed.

The console print is as follows:
[🌎 Easy Localization] [DEBUG] Load asset from assets/translations
[🌎 Easy Localization] [INFO] Locale zh changed
[🌎 Easy Localization] [DEBUG] Build
[🌎 Easy Localization] [DEBUG] Init Localization Delegate
[🌎 Easy Localization] [DEBUG] Init provider
[🌎 Easy Localization] [INFO] Locale zh saved

The result is as follows: This is the point that the system is Chinese, the first time to change from English to Chinese, but it does not work
image

my code
`import 'dart:ffi';
import 'dart:ui';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';
import 'package:indonesia_qs_management/res/assets_res.dart';
import 'package:indonesia_qs_management/utils/text_style_config.dart';
import 'package:v_components/v_components.dart';
import 'package:v_components/widgets/radiogroup/radio_group.dart';

import '../../utils/colorConfig.dart';
import '../../utils/common_util.dart';

/// FileName set_locale_page
///
/// @author ThinkPad
/// @Date 2024/9/11 16:42
///
/// @description 更改语言

class SetLocalePage extends BasePage {
@OverRide
CommonBasePageState createBaseState() => _SetLocalePageState();
}

class _SetLocalePageState extends CommonBasePageState {
late String _currentLocaleStr;

List locals = [
// {"name": "language_system", "value": "system"},
{"name": "language_zh", "value": "zh","locale":const Locale("zh","")},
{"name": "language_en", "value": "en","locale":const Locale("en","")},
{"name": "language_id", "value": "id","locale":const Locale("id","")}
];

int currentIndex=-1;
int selectIndex=-1;

@OverRide
Widget buildPageWidget(BuildContext context) {
return Scaffold(
backgroundColor: ColorsUtil.hex2Color(pageBgColor),
appBar: CommonUtils.getAppBar(context,
title: context.tr("multilingual"),
actionView: InkWell(
onTap: ()async{
if(selectIndex==currentIndex)return;

          Locale ll=locals[selectIndex]["locale"];
          await context.setLocale(ll);

          VLog.w(context.locale.toString());
          Get.updateLocale(ll);
          // Get.back();
          setState(() {
            currentIndex=selectIndex;
          });
        },
        child:Padding(
          padding: const EdgeInsets.only(right: 10),
          child:  Text(context.tr("save"),style:currentIndex==selectIndex?style13Hint: style13Black,),
        ),
      )),
  body: Column(
    children: _createLocales(),
  ),
);

}

@OverRide
void initBaseParams() {}

@OverRide
void initPageData() {
_currentLocaleStr = context.locale.toString();
VLog.w(context.deviceLocale.toString());
VLog.w(_currentLocaleStr);

int current = locals.indexWhere((l) {
  return l["value"] == _currentLocaleStr;
});
currentIndex = current;
selectIndex=current;
setState(() {

});

}

_createLocales() {
return List.generate(locals.length, (index) {
return InkWell(
onTap: (){
setState(() {
selectIndex=index;
});
},
child: Container(
height: 50,
padding: const EdgeInsets.only(left: 10, right: 10),
decoration:
BoxDecoration(color: Colors.white, border: Border(bottom: BorderSide(color: ColorsUtil.hex2Color(filedBorderColor), width: 0.5))),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
context.tr(locals[index]["name"]),
style: style13Black,
),
Icon(
Icons.check_rounded,
size: 35,
color: selectIndex != index ? Colors.white : ColorsUtil.hex2Color(primaryColor),
)
],
),
),
);
});
}
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant