Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to border radius DatePickerTheme properties #282

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 82 additions & 72 deletions lib/flutter_datetime_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class _DatePickerRoute<T> extends PopupRoute<T> {
locale: this.locale,
route: this,
pickerModel: pickerModel,
borderRadius: theme.pickerBorderRadius,
),
);
return InheritedTheme.captureAll(context, bottomSheet);
Expand All @@ -254,15 +255,18 @@ class _DatePickerComponent extends StatefulWidget {
required this.pickerModel,
this.onChanged,
this.locale,
this.borderRadius,
}) : super(key: key);

final DateChangedCallback? onChanged;

final _DatePickerRoute route;

final BasePickerModel pickerModel;

final DateChangedCallback? onChanged;

final LocaleType? locale;

final BasePickerModel pickerModel;
final BorderRadius? borderRadius;

@override
State<StatefulWidget> createState() {
Expand Down Expand Up @@ -299,7 +303,8 @@ class _DatePickerState extends State<_DatePickerComponent> {
animation: widget.route.animation!,
builder: (BuildContext context, Widget? child) {
final double bottomPadding = MediaQuery.of(context).padding.bottom;
return ClipRect(
return ClipRRect(
borderRadius: widget.borderRadius,
child: CustomSingleChildLayout(
delegate: _BottomPickerLayout(
widget.route.animation!.value,
Expand All @@ -309,6 +314,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
),
child: GestureDetector(
child: Material(
borderRadius: widget.borderRadius,
color: theme.backgroundColor,
child: _renderPickerView(theme),
),
Expand Down Expand Up @@ -397,74 +403,77 @@ class _DatePickerState extends State<_DatePickerComponent> {
}

Widget _renderItemView(DatePickerTheme theme) {
return Container(
color: theme.backgroundColor,
child: Directionality(
textDirection: TextDirection.ltr,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: widget.pickerModel.layoutProportions()[0] > 0
? _renderColumnView(
ValueKey(widget.pickerModel.currentLeftIndex()),
theme,
widget.pickerModel.leftStringAtIndex,
leftScrollCtrl,
widget.pickerModel.layoutProportions()[0], (index) {
widget.pickerModel.setLeftIndex(index);
}, (index) {
setState(() {
refreshScrollOffset();
_notifyDateChanged();
});
})
: null,
),
Text(
widget.pickerModel.leftDivider(),
style: theme.itemStyle,
),
Container(
child: widget.pickerModel.layoutProportions()[1] > 0
? _renderColumnView(
ValueKey(widget.pickerModel.currentLeftIndex()),
theme,
widget.pickerModel.middleStringAtIndex,
middleScrollCtrl,
widget.pickerModel.layoutProportions()[1], (index) {
widget.pickerModel.setMiddleIndex(index);
}, (index) {
setState(() {
refreshScrollOffset();
_notifyDateChanged();
});
})
: null,
),
Text(
widget.pickerModel.rightDivider(),
style: theme.itemStyle,
),
Container(
child: widget.pickerModel.layoutProportions()[2] > 0
? _renderColumnView(
ValueKey(widget.pickerModel.currentMiddleIndex() * 100 +
widget.pickerModel.currentLeftIndex()),
theme,
widget.pickerModel.rightStringAtIndex,
rightScrollCtrl,
widget.pickerModel.layoutProportions()[2], (index) {
widget.pickerModel.setRightIndex(index);
}, (index) {
setState(() {
refreshScrollOffset();
_notifyDateChanged();
});
})
: null,
),
],
return ClipRRect(
borderRadius: theme.pickerBorderRadius,
child: Container(
color: theme.backgroundColor,
child: Directionality(
textDirection: TextDirection.ltr,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: widget.pickerModel.layoutProportions()[0] > 0
? _renderColumnView(
ValueKey(widget.pickerModel.currentLeftIndex()),
theme,
widget.pickerModel.leftStringAtIndex,
leftScrollCtrl,
widget.pickerModel.layoutProportions()[0], (index) {
widget.pickerModel.setLeftIndex(index);
}, (index) {
setState(() {
refreshScrollOffset();
_notifyDateChanged();
});
})
: null,
),
Text(
widget.pickerModel.leftDivider(),
style: theme.itemStyle,
),
Container(
child: widget.pickerModel.layoutProportions()[1] > 0
? _renderColumnView(
ValueKey(widget.pickerModel.currentLeftIndex()),
theme,
widget.pickerModel.middleStringAtIndex,
middleScrollCtrl,
widget.pickerModel.layoutProportions()[1], (index) {
widget.pickerModel.setMiddleIndex(index);
}, (index) {
setState(() {
refreshScrollOffset();
_notifyDateChanged();
});
})
: null,
),
Text(
widget.pickerModel.rightDivider(),
style: theme.itemStyle,
),
Container(
child: widget.pickerModel.layoutProportions()[2] > 0
? _renderColumnView(
ValueKey(widget.pickerModel.currentMiddleIndex() * 100 +
widget.pickerModel.currentLeftIndex()),
theme,
widget.pickerModel.rightStringAtIndex,
rightScrollCtrl,
widget.pickerModel.layoutProportions()[2], (index) {
widget.pickerModel.setRightIndex(index);
}, (index) {
setState(() {
refreshScrollOffset();
_notifyDateChanged();
});
})
: null,
),
],
),
),
),
);
Expand All @@ -479,6 +488,7 @@ class _DatePickerState extends State<_DatePickerComponent> {
height: theme.titleHeight,
decoration: BoxDecoration(
color: theme.headerColor ?? theme.backgroundColor,
borderRadius: theme.headerBorderRadius,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/datetime_picker_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class DatePickerTheme with DiagnosticableTreeMixin {
final double titleHeight;
final double itemHeight;

final BorderRadius? pickerBorderRadius;
final BorderRadius? headerBorderRadius;

const DatePickerTheme({
this.cancelStyle = const TextStyle(color: Colors.black54, fontSize: 16),
this.doneStyle = const TextStyle(color: Colors.blue, fontSize: 16),
Expand All @@ -23,5 +26,7 @@ class DatePickerTheme with DiagnosticableTreeMixin {
this.containerHeight = 210.0,
this.titleHeight = 44.0,
this.itemHeight = 36.0,
this.pickerBorderRadius,
this.headerBorderRadius,
});
}