2022-11-01 09:43:38 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2022-11-22 11:50:40 +01:00
|
|
|
import 'package:datetime_picker_example/shaped_border.dart';
|
2022-08-26 09:56:44 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
|
2022-11-25 14:58:38 +01:00
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2022-08-26 09:56:44 +02:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2022-09-01 16:09:20 +02:00
|
|
|
const MyApp({super.key});
|
2022-08-26 09:56:44 +02:00
|
|
|
|
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2022-11-25 14:58:38 +01:00
|
|
|
// set locale to dutch
|
|
|
|
localizationsDelegates: const [
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
],
|
|
|
|
supportedLocales: const [
|
|
|
|
Locale('nl', 'NL'),
|
|
|
|
Locale('en', 'US'),
|
|
|
|
],
|
2022-11-16 17:01:05 +01:00
|
|
|
title: 'Demo drag down date time picker',
|
2022-08-26 09:56:44 +02:00
|
|
|
theme: ThemeData(
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
home: const DatePickerDemo(),
|
2022-08-26 09:56:44 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 16:09:20 +02:00
|
|
|
class DatePickerDemo extends StatelessWidget {
|
|
|
|
const DatePickerDemo({Key? key}) : super(key: key);
|
2022-11-25 14:58:38 +01:00
|
|
|
|
2022-08-26 09:56:44 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-25 14:58:38 +01:00
|
|
|
// set locale to Dutch
|
2022-11-16 17:01:05 +01:00
|
|
|
const dateTimePickerTheme = DateTimePickerTheme(
|
|
|
|
dateBoxShape: DateBoxShape.roundedRectangle,
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
markedIndicatorColor: Colors.red,
|
|
|
|
baseTheme: DateBoxBaseTheme(
|
|
|
|
Colors.white,
|
|
|
|
TextStyle(color: Colors.black),
|
|
|
|
),
|
|
|
|
selectedTheme: DateBoxSelectedTheme(
|
|
|
|
Color(0x4BF44336),
|
|
|
|
TextStyle(
|
|
|
|
color: Colors.red,
|
2022-11-11 13:01:28 +01:00
|
|
|
),
|
2022-11-16 17:01:05 +01:00
|
|
|
),
|
|
|
|
highlightTheme: DateBoxHighlightTheme(
|
|
|
|
Colors.red,
|
|
|
|
TextStyle(
|
|
|
|
color: Colors.white,
|
2022-11-11 13:01:28 +01:00
|
|
|
),
|
2022-11-16 17:01:05 +01:00
|
|
|
),
|
|
|
|
barTheme: DateTimePickerBarTheme(
|
|
|
|
barColor: Colors.black,
|
|
|
|
barOpacity: 1,
|
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
paginationSize: 50,
|
2022-11-25 16:04:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const popupDateTimePickerTheme = DateTimePickerTheme(
|
|
|
|
dateBoxShape: DateBoxShape.roundedRectangle,
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
markedIndicatorColor: Colors.red,
|
|
|
|
baseTheme: DateBoxBaseTheme(
|
|
|
|
Colors.white,
|
|
|
|
TextStyle(color: Colors.black),
|
|
|
|
),
|
|
|
|
selectedTheme: DateBoxSelectedTheme(
|
|
|
|
Color(0x4BF44336),
|
|
|
|
TextStyle(
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
highlightTheme: DateBoxHighlightTheme(
|
|
|
|
Colors.red,
|
|
|
|
TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
barTheme: DateTimePickerBarTheme(
|
|
|
|
barColor: Colors.black,
|
|
|
|
barOpacity: 1,
|
|
|
|
),
|
|
|
|
paginationSize: 50,
|
2022-11-22 11:50:40 +01:00
|
|
|
shapeBorder: ArrowedBorder(),
|
2022-11-16 17:01:05 +01:00
|
|
|
);
|
|
|
|
|
2022-11-21 14:53:07 +01:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
automaticallyImplyLeading: true,
|
|
|
|
title: const Text('Demo'),
|
|
|
|
),
|
|
|
|
body: Stack(
|
|
|
|
children: [
|
|
|
|
Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: [
|
|
|
|
OverlayDateTimePicker(
|
|
|
|
theme: dateTimePickerTheme,
|
|
|
|
alignment: Alignment.bottomCenter,
|
2022-11-16 17:01:05 +01:00
|
|
|
child: const Text("Select Day"),
|
2022-11-21 14:53:07 +01:00
|
|
|
onTapDay: (date) {},
|
2022-11-16 17:01:05 +01:00
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
OverlayDateTimePicker(
|
|
|
|
theme: dateTimePickerTheme,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
buttonBuilder: (key, onPressed) => TextButton(
|
|
|
|
key: key,
|
|
|
|
onPressed: onPressed,
|
|
|
|
child: const Text("Select Day"),
|
|
|
|
),
|
|
|
|
dateTimeConstraint: DateTimeConstraint(
|
|
|
|
min: DateConstraint(date: DateTime.now()),
|
2022-11-16 17:01:05 +01:00
|
|
|
),
|
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
OverlayDateTimePicker(
|
2022-11-25 16:04:42 +01:00
|
|
|
theme: popupDateTimePickerTheme,
|
2022-11-21 14:53:07 +01:00
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
buttonBuilder: (key, onPressed) => IconButton(
|
|
|
|
key: key,
|
|
|
|
onPressed: onPressed,
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.schedule,
|
2022-11-18 15:57:03 +01:00
|
|
|
),
|
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
dateTimeConstraint: DateTimeConstraint(
|
|
|
|
min: DateConstraint(date: DateTime.now()),
|
|
|
|
max: DateConstraint(
|
|
|
|
date: DateTime(
|
2022-11-25 16:05:44 +01:00
|
|
|
DateTime.now().year + 1,
|
|
|
|
DateTime.now().month,
|
2022-11-21 14:53:07 +01:00
|
|
|
DateTime.now().day,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onNextPageButtonBuilder: (onPressed) {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: onPressed, icon: const Icon(Icons.add));
|
|
|
|
},
|
|
|
|
onPreviousPageButtonBuilder: (onPressed) {
|
|
|
|
return IconButton(
|
|
|
|
onPressed: onPressed, icon: const Icon(Icons.minimize));
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
2022-11-16 17:01:05 +01:00
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
),
|
|
|
|
DragDownDateTimePicker(
|
2022-11-25 14:58:38 +01:00
|
|
|
onTimerPickerSheetChange: (value) {},
|
|
|
|
alwaysUse24HourFormat: true,
|
2022-11-21 14:53:07 +01:00
|
|
|
dateTimePickerTheme: const DateTimePickerTheme(
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
markedIndicatorColor: Colors.red,
|
|
|
|
baseTheme: DateBoxBaseTheme(
|
|
|
|
Colors.white,
|
|
|
|
TextStyle(color: Colors.black),
|
2022-11-16 17:01:05 +01:00
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
selectedTheme: DateBoxSelectedTheme(
|
|
|
|
Color(0x4BF44336),
|
|
|
|
TextStyle(
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
highlightTheme: DateBoxHighlightTheme(
|
|
|
|
Colors.red,
|
|
|
|
TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
barTheme: DateTimePickerBarTheme(
|
|
|
|
barColor: Colors.black,
|
|
|
|
barOpacity: 1,
|
2022-11-16 17:01:05 +01:00
|
|
|
),
|
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
markedDates: [DateTime(2022, 9, 6)],
|
2022-11-25 14:58:38 +01:00
|
|
|
),
|
2022-11-21 14:53:07 +01:00
|
|
|
],
|
|
|
|
),
|
2022-09-02 17:04:47 +02:00
|
|
|
);
|
2022-08-26 09:56:44 +02:00
|
|
|
}
|
|
|
|
}
|