如何更改日期范围选择器的样式?

时间:2019-11-29 11:51:13

标签: datetime flutter

在flutter中添加了this插件。这是我的代码

onPressed:() async {
    final List<DateTime> picked = await DateRagePicker.showDatePicker(
        context: context,
        initialFirstDate: DateTime.now(),
        initialLastDate: DateTime.now()).add(Duration(days: 7),
        firstDate: DateTime(2018),
        lastDate: DateTime(2022),
    );
    if (picked != null && picked.length == 2) {
        print(picked);
    }
},

这是结果Ds。 那么如何更改此插件的样式和语言?

1 个答案:

答案 0 :(得分:1)

对于语言,您可以设置locale。我也建议您调查https://flutter.dev/docs/development/accessibility-and-localization/internationalization

要更改小部件颜色,ant字体等,必须将元素包装到Theme中:

Widget returnRangePicker(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(
          accentColor: Colors.green,
          primaryColor: Colors.blue,
          buttonTheme: ButtonThemeData(
              highlightColor: Colors.green,
              buttonColor: Colors.green,
              colorScheme: Theme.of(context).colorScheme.copyWith(
                  secondary: epapGreen,
                  background: Colors.white,
                  primary: Colors.green,
                  primaryVariant: Colors.green,
                  brightness: Brightness.dark,
                  onBackground: Colors.green),
              textTheme: ButtonTextTheme.accent)),
      child: Builder(
        builder: (context) => FlatButton(
          onPressed: () async {
            final List<DateTime> picked = await DateRangePicker.showDatePicker(
                context: context,
                initialFirstDate: DateTime.now(),
                initialLastDate:
                    DateTime.now()).add(Duration(days: 7),
                firstDate: DateTime(2015),
                lastDate: DateTime(2020));
            if (picked != null && picked.length == 2) {
              print(picked);
            }
          },
          child: Text(
            "Choose range",
            style: TextStyle(color: Colors.green),
          ),
        ),
      ),
    );
  }