当前位置: 首页 > news >正文

通过网站做跳板免费s站推广网站

通过网站做跳板,免费s站推广网站,红酒商城网站建设方案,卖线面网站3、 Flutter Intl 多语言国际化 在Android Studio中菜单Tools找到flutter intl创建多语言配置。 创建后会在pubspec.yaml出现 flutter_intl:enabled: true 在工程的lib会生成l10n与generated文件夹 l10n包含 intl_en.arb intl_zn.arb 我们在intl_en.arb添加 { home: &quo…

3、 Flutter Intl

多语言国际化

 在Android Studio中菜单Tools找到flutter intl创建多语言配置。

创建后会在pubspec.yaml出现

flutter_intl:enabled: true

在工程的lib会生成l10n与generated文件夹

l10n包含
intl_en.arb
intl_zn.arb

我们在intl_en.arb添加

{
'home': "Home",
}

在intl_zn.arb添加

{
'home': "首页",
}

注意:每次修改完arb文件保存一下即可生效

三、编写代码

创建LocalModel

// 共享状态
class SessionChangeNotifier with ChangeNotifier {Session get session => Global.session;String? get getToken => Global.session.token;@overridevoid notifyListeners() {// 保存Profile变更Global.saveProfile();//通知依赖的Widget更新super.notifyListeners();}
}
class LocaleModel extends SessionChangeNotifier {// 获取当前用户的APP语言配置Locale类,如果为null,则语言跟随系统语言Locale? getLocale() {if (session.locale == null) return null;var t = session.locale?.split("_");LoggerManager().debug("getLocale t:${t}");if (t != null && t.length == 2) {LoggerManager().debug("Locale t:${t}");return Locale(t[0], t[1]);}return null;}// 获取当前Locale的字符串表示String get locale => session.locale ?? "";// 用户改变APP语言后,通知依赖项更新,新语言会立即生效set locale(String locale) {LoggerManager().debug("locale:${locale}, profile.locale:${session.locale}");if (locale != session.locale) {session.locale = locale;notifyListeners();}}
}

在Main的入口中设置

class MyApp extends StatelessWidget {const MyApp({Key? key}) : super(key: key);// This widget is the root of your application.@overrideWidget build(BuildContext context) {return MultiProvider(providers: providers,child: Consumer3<ThemeModel, LocaleModel, UserModel>(builder: (context, themeModel, localeModel, userModel, child) {return RefreshConfiguration(hideFooterWhenNotFull: false, //列表数据不满一页,不触发加载更多child: ScreenUtilInit(designSize: const Size(375.0, 667.0),minTextAdapt: true,splitScreenMode: true,builder: (context, child) {return child ??buildMaterialApp(context, localeModel, themeModel, userModel);},child:buildMaterialApp(context, localeModel, themeModel, userModel),),);},),);}Widget buildMaterialApp(BuildContext context, LocaleModel localeModel,ThemeModel themeModel, UserModel userModel) {return MaterialApp(theme: ThemeData(fontFamily: "PingFang SC",primarySwatch: themeModel.theme,),navigatorKey: OneContext().key,debugShowCheckedModeBanner: false,supportedLocales: S.delegate.supportedLocales,locale: localeModel.getLocale(),initialRoute: buildInitialRoute(appModel: Provider.of<AppModel>(context, listen: false),userModel: userModel,),onGenerateRoute: RouterManager.generateRoute,navigatorObservers: buildObservers(),localizationsDelegates: const [S.delegate,RefreshLocalizations.delegate, //下拉刷新GlobalCupertinoLocalizations.delegate,GlobalMaterialLocalizations.delegate,GlobalWidgetsLocalizations.delegate],localeResolutionCallback: (_locale, supportedLocales) {if (localeModel.getLocale() != null) {//如果已经选定语言,则不跟随系统return localeModel.getLocale();} else {//跟随系统LoggerManager().debug("_locale:${_locale}");Locale locale;if (supportedLocales.contains(_locale)) {locale = _locale!;} else {//如果系统语言不是中文简体或美国英语,则默认使用美国英语locale = Locale('en', 'US');}return locale;}},builder: EasyLoading.init(builder: (BuildContext context, Widget? child) {return OneContext().builder(context,child,observers: buildObservers(),);}),home: buildGlobalGesture(context),);}Widget buildGlobalGesture(BuildContext context) {return GestureDetector(onTap: () {FocusScopeNode currentFocus = FocusScope.of(context);if (!currentFocus.hasPrimaryFocus &&currentFocus.focusedChild != null) {FocusManager.instance.primaryFocus?.unfocus();// 也可以使用如下方式隐藏键盘:// SystemChannels.textInput.invokeMethod('TextInput.hide');}},);}List<NavigatorObserver> buildObservers() {return [MyNavigatorObserver()];}String? buildInitialRoute({required AppModel appModel, required UserModel userModel}) {String? initialRoute;// String? isAgree = localeModel.isAgree;String? isAgree = "1";if ("1" == isAgree) {if (userModel.isLogin) {initialRoute = RouterName.main;} else {initialRoute = RouterName.login;}} else {initialRoute = RouterName.agreement;}return initialRoute;}
}

 之后我们可以在具体使用的地方这个配置的home。

return Scaffold(appBar: MyAppBar(label: S.of(context).home,isBackButton: false,),
body:Container(),);

更换语言环境页面

class LanguagePage extends StatefulWidget {const LanguagePage({Key? key, this.arguments}) : super(key: key);final Object? arguments;@overrideState<LanguagePage> createState() => _LanguagePageState();
}class _LanguagePageState extends State<LanguagePage> {@overrideWidget build(BuildContext context) {var color = Theme.of(context).primaryColor;var localeModel = Provider.of<LocaleModel>(context);Widget _buildLanguageItem(String lan, value) {LoggerManager().debug("_buildLanguageItem:${lan}, value:${value}");return SettingCheckItemWidget(title: lan,content: "",checkColor: color,isSelected: localeModel.locale == value,onPressed: () {// 此行代码会通知MaterialApp重新buildlocaleModel.locale = value;},);}return Scaffold(appBar: MyAppBar(onPressed: () {navigatorBack();},label: S.of(context).language,isBackButton: true,),body: ListView.builder(padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 10.0),addRepaintBoundaries: false,addAutomaticKeepAlives: false,itemCount: 3,itemBuilder: (context, index) {if (index == 0) {return _buildLanguageItem("中文简体", "zh_CN");}if (index == 1) {return _buildLanguageItem("English", "en_US");}if (index == 2) {return _buildLanguageItem(S.of(context).autoBySystem, null);}return Container();},),);}void userEnterApp() {// 点击进入appNavigatorPageRouter.pushReplacementNamed(RouterName.main);}void navigatorBack() {NavigatorPageRouter.pop();}
}

http://www.tj-hxxt.cn/news/117249.html

相关文章:

  • 南宁网站建设推广服务关键词排名优化流程
  • 免费空间网站怎么做的百度关键词seo排名软件
  • 教务系统登录入口网站推广优化技巧
  • 建设网站的获客渠道建站模板平台
  • 做网站都要用到框架吗今天的热点新闻
  • 自己做微网站网页开发教程
  • 网站建设必备条件精准营销策略都有哪些
  • 太原视频剪辑培训机构哪个好亚马逊关键词优化怎么做
  • 大连手机自适应网站制作公司百度入驻绍兴
  • 上海成品网站seo技术服务外包公司
  • 做301跳转会影响之前网站排名吗排名优化工具下载
  • 一个网站 两个域名今日新闻摘抄十条简短
  • 帮助做职业规划的网站可以发广告的100个网站
  • 做一个网站西安网站推广
  • 有没有免费做企业网站的百度收录查询接口
  • 德泰诺科技的团队介绍宁波谷歌优化
  • 金环建设集团网站湖南竞价优化专业公司
  • 网站开发开源软件网络营销比较常用的营销模式
  • 做二手车网站需要什么手续费常见的网络营销方法
  • 广东深圳网站建设方便seo网站关键词优化多少钱
  • wordpress调用首页标签搜索引擎优化的主题
  • 网站出现 503怎么了阻断艾滋病的药有哪些
  • 那些网站分享pr做的视频优化措施最新回应
  • 网上做兼职网站正规石家庄疫情最新情况
  • 广东建设厅的网站查询网站如何优化一个关键词
  • 中国建设会计协会网站网站seo排名培训
  • 德州成交型网站建设百度云网盘网页版
  • 网站主机 分为十大少儿编程教育品牌
  • 免费模板网站推荐百度搜索引擎平台
  • 青岛响应式网站设计百度广告点击软件源码