zoukankan      html  css  js  c++  java
  • flutter showDatePicker显示中文日期_Flutter时间控件显示中文

     flutter showDatePicker showTimePicker显示中文日期

    1、配置flutter_localizations依赖

     找到pubspec.yaml配置flutter_localizations

    dependencies:
      flutter:
        sdk: flutter
      flutter_localizations:
        sdk: flutter

    2、导入国际化的包 flutter_localizations

    import 'package:flutter_localizations/flutter_localizations.dart'; 

    3、设置国际化

    void main() {
      runApp(
        new MaterialApp(
          title: 'app',
          theme: new ThemeData(
            primaryColor: Colors.white,
          ),
          home: new MyLoginWidget(),
          localizationsDelegates: [
            //此处
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
          supportedLocales: [
            //此处
            const Locale('zh', 'CH'),
            const Locale('en', 'US'),
          ],
        ),
      );
    }

    4、要显示中文的控件设置:

    _showDatePicker() async{
        var date =await showDatePicker(
          context: context,
          initialDate: _datetime,
          firstDate:DateTime(1900),
          lastDate:DateTime(2050),
          locale: Locale('zh'),    
        );
        if(date==null) return;
        print(date);
        setState(() {
           _datetime=date;
        });
      }
  • 相关阅读:
    InterLockedIncrement and InterLockedDecrement
    bzoj2763
    bzoj1922
    bzoj1705
    bzoj1040
    bzoj3039
    bzoj1801
    bzoj2565
    bzoj1976
    一类最小割bzoj2127,bzoj2132 bzoj3438
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/11542487.html
Copyright © 2011-2022 走看看