flutter 如何设置边框半径和删除标题栏以显示DatePicker?

sgtfey8w  于 2023-04-07  发布在  Flutter
关注(0)|答案(2)|浏览(126)

我正在使用showDatePicker()方法在flutter应用程序中显示日期选择器。如何设置边框半径并删除标题栏?
下面是我的代码:

showDatePicker(
  locale: Locale('ja'),
  context: context,
  initialDate: _dateTime,
  firstDate:
      DateTime(DateTime.now().year - 5),
  lastDate: DateTime(DateTime.now().year + 5),
  builder: (context, child) {
    return Theme(
      data: ThemeData.light().copyWith(
        primaryColor:
            helper.hexColor('#007AFF'),
        accentColor:
            helper.hexColor('#007AFF'),
        colorScheme: ColorScheme.light(
            primary:
                helper.hexColor('#007AFF')),
        buttonTheme: ButtonThemeData(
            textTheme: ButtonTextTheme
                .primary), // This will change to light theme.
      ),
      child: child,
    );
  },
);
ie3xauqp

ie3xauqp1#

您可以在ThemeData中设置边框半径:

ThemeData(
      dialogTheme: const DialogTheme(
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(16)))),
)
bq9c1y66

bq9c1y662#

此代码用于控制showDatePicker和borderRadius的大小

Future _selectDate(BuildContext context, BoxConstraints constraints) async {
final DateTime? picked = await showDatePicker(
  context: context,
  initialDate: DateTime.now(),
  firstDate: DateTime(1900),
  lastDate: DateTime(2100),
  builder: (context, child) {
    return Column(
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.only(top: 50.0),
          child: Container(
            height: constraints.maxHeight * 0.9,
            width: constraints.maxWidth * 0.6,
            decoration: BoxDecoration(
              border: Border.all(color: Colors.black12),
              borderRadius: BorderRadius.circular(10),
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Colors.blue.shade200,
                  blurRadius: 1,
                  offset: const Offset(2, 2), // Shadow position
                ),
              ],
            ),
            child: Material(
                borderRadius: BorderRadius.circular(10),
                clipBehavior: Clip.antiAliasWithSaveLayer,
                child: child),
          ),
        ),
      ],
    );
  },
);

}

相关问题