【问题标题】:Is there a way to retrieve the language of a phone with Flutter so that the application can detect the default language?有没有办法用 Flutter 检索手机的语言,以便应用程序可以检测默认语言?
【发布时间】:2023-01-24 19:41:15
【问题描述】:

我想通过检索首选项中设置的手机的默认语言来更改我的 flutter 应用程序的语言。怎么做 ?

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    MaterialApp 中,您可以使用 local 属性设置应用程序语言, 本地属性默认为系统语言

    如果您不设置自定义本地语言,如果您的应用程序中提供此语言,则应用程序将使用系统语言

    【讨论】:

      【解决方案2】:

      是的,您可以在应用程序开始时使用 MaterialApp 中的 localeResolutionCallback 检索它

      MaterialApp(
                        title: 'SportsTak',
                        home:Home(),
                        localeListResolutionCallback: ( localeOfDevice, listedLocales){
              
                        //Here is what you can loop through listedLocales and compare from localeOfDevice and return the locale you support
                          
                        },
                        supportedLocales:[ ] , //listofsupportedlocales
                      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-13
        • 2017-01-04
        • 1970-01-01
        • 1970-01-01
        • 2014-08-11
        • 1970-01-01
        • 2011-03-30
        相关资源
        最近更新 更多