zoukankan      html  css  js  c++  java
  • flutter TextField 弹出复制是英文的问题

    1.在 pubspec.yaml 中集成 flutter_localizations;
    dependencies:
      flutter:
        sdk: flutter
      flutter_localizations:
        sdk: flutter
    注意这个会和intl冲突
    2.在 MaterialApp 中设置本地化代理和支持的语言类型; return MaterialApp( localizationsDelegates: [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], supportedLocales: [ const Locale(‘zh‘, ‘CN‘), const Locale(‘en‘, ‘US‘), ] }

     

    接着报了一个出错:长按报错The getter 'cutButtonLabel' was called on null
    新建一个dart文件CupertinoLocalizationsDelegate
    import 'package:flutter/foundation.dart' show SynchronousFuture;
    import 'package:flutter/cupertino.dart';

    class CupertinoLocalizationsDelegate
    extends LocalizationsDelegate<CupertinoLocalizations> {
    const CupertinoLocalizationsDelegate();

    @override
    bool isSupported(Locale locale) =>
    <String>['en', 'zh'].contains(locale.languageCode);

    @override
    SynchronousFuture<_DefaultCupertinoLocalizations> load(Locale locale) {
    return SynchronousFuture<_DefaultCupertinoLocalizations>(
    _DefaultCupertinoLocalizations(locale.languageCode));
    }

    @override
    bool shouldReload(CupertinoLocalizationsDelegate old) => false;
    }

    class _DefaultCupertinoLocalizations extends CupertinoLocalizations {
    _DefaultCupertinoLocalizations(this._languageCode)
    : assert(_languageCode != null);

    final DefaultCupertinoLocalizations _en =
    const DefaultCupertinoLocalizations();
    final String _languageCode;

    final Map<String, Map<String, String>> _dict = <String, Map<String, String>>{
    'en': <String, String>{
    'alert': 'Alert',
    'copy': 'Copy',
    'paste': 'Paste',
    'cut': 'Cut',
    'selectAll': 'Select all',
    'today': 'today'
    },
    'zh': <String, String>{
    'alert': '警告',
    'copy': '复制',
    'paste': '粘贴',
    'cut': '剪切',
    'selectAll': '选择全部',
    'today': '今天'
    }
    };

    @override
    String get alertDialogLabel => _get('alert');

    @override
    String get anteMeridiemAbbreviation => _en.anteMeridiemAbbreviation;

    @override
    String get postMeridiemAbbreviation => _en.postMeridiemAbbreviation;

    @override
    String get copyButtonLabel => _get('copy');

    @override
    String get cutButtonLabel => _get('cut');

    @override
    String get pasteButtonLabel => _get('paste');

    @override
    String get selectAllButtonLabel => _get('selectAll');

    @override
    DatePickerDateOrder get datePickerDateOrder => _en.datePickerDateOrder;

    @override
    DatePickerDateTimeOrder get datePickerDateTimeOrder =>
    _en.datePickerDateTimeOrder;

    @override
    String datePickerDayOfMonth(int dayIndex) =>
    _en.datePickerDayOfMonth(dayIndex);

    @override
    String datePickerHour(int hour) => _en.datePickerHour(hour);

    @override
    String datePickerHourSemanticsLabel(int hour) =>
    _en.datePickerHourSemanticsLabel(hour);

    @override
    String datePickerMediumDate(DateTime date) => _en.datePickerMediumDate(date);

    @override
    String datePickerMinute(int minute) => _en.datePickerMinute(minute);

    @override
    String datePickerMinuteSemanticsLabel(int minute) =>
    _en.datePickerMinuteSemanticsLabel(minute);

    @override
    String datePickerMonth(int monthIndex) => _en.datePickerMonth(monthIndex);

    @override
    String datePickerYear(int yearIndex) => _en.datePickerYear(yearIndex);

    @override
    String timerPickerHour(int hour) => _en.timerPickerHour(hour);

    @override
    String timerPickerHourLabel(int hour) => _en.timerPickerHourLabel(hour);

    @override
    String timerPickerMinute(int minute) => _en.timerPickerMinute(minute);

    @override
    String timerPickerMinuteLabel(int minute) =>
    _en.timerPickerMinuteLabel(minute);

    @override
    String timerPickerSecond(int second) => _en.timerPickerSecond(second);

    @override
    String timerPickerSecondLabel(int second) =>
    _en.timerPickerSecondLabel(second);

    String _get(String key) {
    return _dict[_languageCode][key];
    }

    @override
    String get todayLabel => _get("today");
    }
    使用方法:
    localizationsDelegates: [
              //此处
              CupertinoLocalizationsDelegate(),
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
            ],
            supportedLocales: [
              const Locale('zh'),
              const Locale('en')
            ]);
     

      

     

  • 相关阅读:
    sql in not in 案例用 exists not exists 代替
    根据算法规则进行匹配相似车辆
    随机生成临时车牌号
    无法加载 DLL“ParkCOM.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E) 终结者
    c# 除掉前三个字符,剩下的4个字符全为数字方为特殊车辆
    UI设计文本框解决Placeholder的在IE10 以下 IE 9 IE8 IE 7 的兼容问题
    EF框架 对字段属性为NULL的空值处理 类型前面加上?保证EF列表读取显示数据不会报异常
    boost::property_tree读取解析.xml文件
    C++ URLencode library
    http与中文编码传输
  • 原文地址:https://www.cnblogs.com/wupeng88/p/12722778.html
Copyright © 2011-2022 走看看