英文,简体中文zh_CN,繁体中文zh_HK

MaterialApp里面
localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: S.delegate.supportedLocales,
      locale: Locale("zh","HK"),
S.of(context).title

时间日期

 TextButton(
    child: Text('弹出日期组件'),
    onPressed: () async {
      var result =await showDatePicker(
        context: context,
        initialDate: DateTime.now(),//初始日期
        firstDate: DateTime(2010),
        lastDate: DateTime(2025),
        initialEntryMode: DatePickerEntryMode.input,//对话框模式
        initialDatePickerMode: DatePickerMode.year,//弹出年份先选
        selectableDayPredicate: (date) {//今天之后不可选
    return date.difference(DateTime.now()).inMilliseconds < 0;
  },
      );
      BrnToast.show(result.toString(), context);
    })

     TextButton(
              child: Text('范围日期'),
              onPressed: () async {
                var date =await showDateRangePicker(context: context, firstDate: DateTime(2010), lastDate: DateTime(2025));
                BrnToast.show(date.toString(), context);
              },
            ),
    显示在页面上
    CalendarDatePicker(
              initialDate: DateTime.now(),
              firstDate: DateTime(2010),
              lastDate: DateTime(2025),
              onDateChanged: (d) {
                print('$d');
              },
            ),
            菜单
PopupMenuButton<String>(
              tooltip: '点击显示菜单选择',
              icon: Icon(Icons.more_horiz),
              onSelected: (value){
                print('$value');
              },
              onCanceled: (){
                print('onCanceled');
              },
              itemBuilder: (context) {
                return <PopupMenuEntry<String>>[
                  PopupMenuItem<String>(
                    value: '语文',
                    child: Text('语文'),
                  ),
                  PopupMenuItem<String>(
                    value: '数学',
                    child: Text('数学'),
                  ),
                  PopupMenuItem<String>(
                    value: '英语',
                    child: Text('英语'),
                  ),
                  PopupMenuItem<String>(
                    value: '生物',
                    child: Text('生物'),
                  ),
                  PopupMenuItem<String>(
                    value: '化学',
                    child: Text('化学'),
                  ),
                ];
              },
            ),
作者:Yoby  创建时间:2022-11-15 19:48
 更新时间:2024-12-05 13:26
上一篇:
下一篇: