fixed rouded corners not showing and added custom shapeborder

This commit is contained in:
Brighton van den End 2022-11-22 11:50:40 +01:00
parent 104ed426b5
commit 0bfd255ffd
4 changed files with 64 additions and 10 deletions

View file

@ -2,6 +2,7 @@
// //
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
import 'package:datetime_picker_example/shaped_border.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart'; import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
@ -54,6 +55,7 @@ class DatePickerDemo extends StatelessWidget {
barOpacity: 1, barOpacity: 1,
), ),
paginationSize: 50, paginationSize: 50,
shapeBorder: ArrowedBorder(),
); );
return Scaffold( return Scaffold(

View file

@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
class ArrowedBorder extends ShapeBorder {
const ArrowedBorder();
@override
EdgeInsetsGeometry get dimensions => EdgeInsets.zero;
@override
Path getInnerPath(Rect rect, {TextDirection? textDirection}) {
rect = Rect.fromPoints(rect.topLeft, rect.bottomRight);
return Path()..addRect(rect);
}
@override
Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
rect = Rect.fromPoints(rect.topLeft, rect.bottomRight);
return Path()
..addRRect(RRect.fromRectAndRadius(
rect,
const Radius.circular(16),
))
..moveTo(rect.bottomCenter.dx - 15, rect.bottomCenter.dy)
..relativeLineTo(15, 20)
..relativeLineTo(15, -20)
..close();
}
@override
void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {}
@override
ShapeBorder scale(double t) {
return this;
}
}

View file

@ -18,6 +18,7 @@ class DateTimePickerTheme {
this.weekViewSize = 0.2, this.weekViewSize = 0.2,
this.monthViewSize = 0.6, this.monthViewSize = 0.6,
this.weekMonthTriggerSize = 0.3, this.weekMonthTriggerSize = 0.3,
this.shapeBorder,
this.baseTheme = const DateBoxBaseTheme( this.baseTheme = const DateBoxBaseTheme(
Colors.white, Colors.white,
TextStyle(color: Colors.black), TextStyle(color: Colors.black),
@ -79,4 +80,7 @@ class DateTimePickerTheme {
/// The size of the buttons for navigation the different pages /// The size of the buttons for navigation the different pages
final double paginationSize; final double paginationSize;
/// The shape of the border using a [ShapeBorder]
final ShapeBorder? shapeBorder;
} }

View file

@ -119,6 +119,7 @@ class _OverlayDateTimePickerState extends State<OverlayDateTimePicker> {
top: offset.dy, top: offset.dy,
left: offset.dx, left: offset.dx,
child: Material( child: Material(
color: Colors.transparent,
child: _buildOverlay(context), child: _buildOverlay(context),
), ),
); );
@ -210,16 +211,27 @@ class _OverlayDateTimePickerState extends State<OverlayDateTimePicker> {
Widget _buildOverlay(BuildContext context) { Widget _buildOverlay(BuildContext context) {
return Container( return Container(
decoration: BoxDecoration( decoration: (widget.theme.shapeBorder == null)
color: widget.theme.backgroundColor, ? BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(16)), color: widget.theme.backgroundColor,
boxShadow: [ borderRadius: const BorderRadius.all(Radius.circular(16)),
BoxShadow( boxShadow: [
blurRadius: 5, BoxShadow(
color: Colors.black.withOpacity(0.25), blurRadius: 5,
), color: Colors.black.withOpacity(0.25),
], ),
), ],
)
: ShapeDecoration(
shape: widget.theme.shapeBorder!,
color: widget.theme.backgroundColor,
shadows: [
BoxShadow(
blurRadius: 5,
color: Colors.black.withOpacity(0.25),
),
],
),
child: SizedBox( child: SizedBox(
width: widget.size.width, width: widget.size.width,
height: widget.size.height, height: widget.size.height,