首页 > 解决方案 > How to change language of system clipboard text (Copy, Paste etc.,) to Chinese in Flutter?

问题描述

I tried this, but it does not seem to work:

new MaterialApp(
  title: 'Mian',
  localizationsDelegates: [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
  ],
  supportedLocales: [
    const Locale('zh','HK')
  ],

I want to change the Paste to 粘贴,Select All to 选择全部

enter image description here

标签: flutterflutter-layoutflutter-dependencies

解决方案


  1. add flutter_localizations into pubspec.yaml
dependencies:
  flutter:
    sdk: flutter

  flutter_localizations:
    sdk: flutter
  1. import flutter_localizations into main.dart
import 'package:flutter_localizations/flutter_localizations.dart';
  1. use supportedLocales
class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter',
      home: new HomePage(title: ''),
      localizationsDelegates: [                             
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        DefaultCupertinoLocalizations.delegate
      ],
      supportedLocales: [
        const Locale('zh','CH'),
      ],
    );
  }
}

推荐阅读