mirror of
https://github.com/Iconica-Development/flutter_date_time_picker.git
synced 2025-05-18 18:33:49 +02:00
more theming
This commit is contained in:
parent
287eacb77d
commit
30e208217f
7 changed files with 76 additions and 24 deletions
|
@ -36,19 +36,29 @@ class DatePickerDemo extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DateTimePicker(
|
return DateTimePicker(
|
||||||
dateTimePickerTheme: const DateTimePickerTheme(
|
dateTimePickerTheme: const DateTimePickerTheme(
|
||||||
markedIndicatorColor: Colors.red,
|
backgroundColor: Colors.white,
|
||||||
selectedTheme: DateBoxSelectedTheme(
|
markedIndicatorColor: Colors.red,
|
||||||
Color(0x4BF44336),
|
baseTheme: DateBoxBaseTheme(
|
||||||
TextStyle(
|
Colors.white,
|
||||||
color: Colors.red,
|
TextStyle(color: Colors.black),
|
||||||
),
|
),
|
||||||
|
selectedTheme: DateBoxSelectedTheme(
|
||||||
|
Color(0x4BF44336),
|
||||||
|
TextStyle(
|
||||||
|
color: Colors.red,
|
||||||
),
|
),
|
||||||
highlightTheme: DateBoxHighlightTheme(
|
),
|
||||||
Colors.red,
|
highlightTheme: DateBoxHighlightTheme(
|
||||||
TextStyle(
|
Colors.red,
|
||||||
color: Colors.white,
|
TextStyle(
|
||||||
),
|
color: Colors.white,
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
|
barTheme: DateTimePickerBarTheme(
|
||||||
|
barColor: Colors.black,
|
||||||
|
barOpacity: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
markedDates: [DateTime(2022, 9, 6)],
|
markedDates: [DateTime(2022, 9, 6)],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,5 @@ export 'src/models/date_box_base_theme.dart';
|
||||||
export 'src/models/date_box_disabled_theme.dart';
|
export 'src/models/date_box_disabled_theme.dart';
|
||||||
export 'src/models/date_box_highlight_theme.dart';
|
export 'src/models/date_box_highlight_theme.dart';
|
||||||
export 'src/models/date_box_selected_theme.dart';
|
export 'src/models/date_box_selected_theme.dart';
|
||||||
export 'src/models/date_time_picker_theme.dart';
|
export 'src/models/date_time_picker_theme.dart';
|
||||||
|
export 'src/models/date_time_picker_bar_theme.dart';
|
||||||
|
|
|
@ -238,7 +238,8 @@ class _DateTimePickerState extends State<DateTimePicker> {
|
||||||
padding: const EdgeInsets.only(bottom: 12.5),
|
padding: const EdgeInsets.only(bottom: 12.5),
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color:
|
||||||
|
_dateTimePickerController.theme.backgroundColor,
|
||||||
borderRadius: const BorderRadius.only(
|
borderRadius: const BorderRadius.only(
|
||||||
bottomLeft: Radius.circular(20),
|
bottomLeft: Radius.circular(20),
|
||||||
bottomRight: Radius.circular(20),
|
bottomRight: Radius.circular(20),
|
||||||
|
|
24
lib/src/models/date_time_picker_bar_theme.dart
Normal file
24
lib/src/models/date_time_picker_bar_theme.dart
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class DateTimePickerBarTheme {
|
||||||
|
/// The [DateTimePickerBarTheme] to style bar of the [DateTimePicker] in.
|
||||||
|
/// Define a custom size for the bar and it's color/opacity.
|
||||||
|
const DateTimePickerBarTheme({
|
||||||
|
this.barColor = Colors.grey,
|
||||||
|
this.barOpacity = 0.3,
|
||||||
|
this.barWidth = 50,
|
||||||
|
this.barHeight = 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
/// The color used for the bar shown at the bottom of the date picker.
|
||||||
|
final Color barColor;
|
||||||
|
|
||||||
|
/// The opacity of the color used for the bar that's shown at the bottom of the date picker.
|
||||||
|
final double barOpacity;
|
||||||
|
|
||||||
|
/// The height of the bar shown at the bottom of the date picker.
|
||||||
|
final double barHeight;
|
||||||
|
|
||||||
|
/// The width of the bar shown at the bottom of the date picker.
|
||||||
|
final double barWidth;
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
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';
|
||||||
|
import 'package:flutter_date_time_picker/src/models/date_time_picker_bar_theme.dart';
|
||||||
|
|
||||||
class DateTimePickerTheme {
|
class DateTimePickerTheme {
|
||||||
/// The [DateTimePickerTheme] to style [DateTimePicker] in. Define a custom shape for the dates and specifically style
|
/// The [DateTimePickerTheme] to style [DateTimePicker] in. Define a custom shape for the dates and specifically style
|
||||||
|
@ -13,6 +14,7 @@ class DateTimePickerTheme {
|
||||||
this.monthDateBoxSize = 45,
|
this.monthDateBoxSize = 45,
|
||||||
this.markedIndicatorColor,
|
this.markedIndicatorColor,
|
||||||
this.dateBoxShape = DateBoxShape.roundedRectangle,
|
this.dateBoxShape = DateBoxShape.roundedRectangle,
|
||||||
|
this.backgroundColor = Colors.white,
|
||||||
this.baseTheme = const DateBoxBaseTheme(
|
this.baseTheme = const DateBoxBaseTheme(
|
||||||
Colors.white,
|
Colors.white,
|
||||||
TextStyle(color: Colors.black),
|
TextStyle(color: Colors.black),
|
||||||
|
@ -29,6 +31,7 @@ class DateTimePickerTheme {
|
||||||
Colors.grey,
|
Colors.grey,
|
||||||
TextStyle(color: Colors.white),
|
TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
|
this.barTheme = const DateTimePickerBarTheme(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/// enum to define a shape dor the date. use [DateBoxShape.circle].
|
/// enum to define a shape dor the date. use [DateBoxShape.circle].
|
||||||
|
@ -47,6 +50,9 @@ class DateTimePickerTheme {
|
||||||
/// This theme is used for when a specific date is disabled.
|
/// This theme is used for when a specific date is disabled.
|
||||||
final DateBoxDisabledTheme disabledTheme;
|
final DateBoxDisabledTheme disabledTheme;
|
||||||
|
|
||||||
|
/// This theme is used for the bar of the date picker.
|
||||||
|
final DateTimePickerBarTheme barTheme;
|
||||||
|
|
||||||
/// Size of date box in a week view.
|
/// Size of date box in a week view.
|
||||||
final double weekDateBoxSize;
|
final double weekDateBoxSize;
|
||||||
|
|
||||||
|
@ -55,4 +61,7 @@ class DateTimePickerTheme {
|
||||||
|
|
||||||
/// The color used for a indicator for a marked date.
|
/// The color used for a indicator for a marked date.
|
||||||
final Color? markedIndicatorColor;
|
final Color? markedIndicatorColor;
|
||||||
|
|
||||||
|
/// The color used for a background of the date picker.
|
||||||
|
final Color backgroundColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_date_time_picker/src/extensions/date_time.dart';
|
import 'package:flutter_date_time_picker/src/extensions/date_time.dart';
|
||||||
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
|
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
|
||||||
import 'package:flutter_date_time_picker/src/widgets/month_date_time_picker.dart/month_date_time_picker.dart';
|
import 'package:flutter_date_time_picker/src/widgets/month_date_time_picker/month_date_time_picker.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class MonthDateTimePickerSheet extends StatelessWidget {
|
class MonthDateTimePickerSheet extends StatelessWidget {
|
||||||
|
@ -20,6 +20,8 @@ class MonthDateTimePickerSheet extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var theme = dateTimePickerController.theme;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (dateTimePickerController.header != null)
|
if (dateTimePickerController.header != null)
|
||||||
|
@ -34,7 +36,7 @@ class MonthDateTimePickerSheet extends StatelessWidget {
|
||||||
DateFormat.yMMMM().format(
|
DateFormat.yMMMM().format(
|
||||||
dateTimePickerController.browsingDate,
|
dateTimePickerController.browsingDate,
|
||||||
),
|
),
|
||||||
style: dateTimePickerController.theme.baseTheme.textStyle!
|
style: theme.baseTheme.textStyle!
|
||||||
.copyWith(fontSize: 25),
|
.copyWith(fontSize: 25),
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
|
@ -97,11 +99,13 @@ class MonthDateTimePickerSheet extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
height: 3,
|
height: theme.barTheme.barHeight,
|
||||||
width: 50,
|
width: theme.barTheme.barWidth,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
color: Colors.grey.withOpacity(0.3),
|
color: theme.barTheme.barColor.withOpacity(
|
||||||
|
theme.barTheme.barOpacity,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
|
|
|
@ -36,6 +36,8 @@ class WeekDateTimePickerSheet extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var theme = dateTimePickerController.theme;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (dateTimePickerController.header != null)
|
if (dateTimePickerController.header != null)
|
||||||
|
@ -49,8 +51,7 @@ class WeekDateTimePickerSheet extends StatelessWidget {
|
||||||
if (showHeader) ...[
|
if (showHeader) ...[
|
||||||
Text(
|
Text(
|
||||||
getDateHeader(),
|
getDateHeader(),
|
||||||
style: dateTimePickerController.theme.baseTheme.textStyle!
|
style: theme.baseTheme.textStyle!.copyWith(fontSize: 9),
|
||||||
.copyWith(fontSize: 9),
|
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 10,
|
height: 10,
|
||||||
|
@ -103,11 +104,13 @@ class WeekDateTimePickerSheet extends StatelessWidget {
|
||||||
height: 10,
|
height: 10,
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
height: 3,
|
height: theme.barTheme.barHeight,
|
||||||
width: 50,
|
width: theme.barTheme.barWidth,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
color: Colors.grey.withOpacity(0.3),
|
color: theme.barTheme.barColor.withOpacity(
|
||||||
|
theme.barTheme.barOpacity,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
|
|
Loading…
Reference in a new issue