Merge remote-tracking branch 'origin/master' into feature/Improve_README

This commit is contained in:
Thomas Klein Langenhorst 2022-11-25 15:58:35 +01:00
commit 0835102dbd
13 changed files with 83 additions and 194 deletions

10
.gitignore vendored
View file

@ -19,7 +19,7 @@ migrate_working_dir/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
@ -28,3 +28,11 @@ migrate_working_dir/
.dart_tool/
.packages
build/
example/web
example/android
example/ios
example/macos
example/windows
example/linux

View file

@ -1,3 +1,10 @@
## 2.1.0
* Fixed internalization of the package
* Added dragcallback to the draggablesheet
## 2.0.0
* Added overlay variant of datetimepicker
## 1.2.0
* Made date time picker height customizable

View file

@ -4,7 +4,7 @@
# This file should be version controlled.
version:
revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
channel: stable
project_type: app
@ -13,26 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: android
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: ios
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: linux
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: macos
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: web
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
- platform: windows
create_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
base_revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
# User provided section

View file

@ -5,6 +5,7 @@
import 'package:datetime_picker_example/shaped_border.dart';
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/flutter_date_time_picker.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() {
runApp(const MyApp());
@ -17,6 +18,17 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// set locale to dutch
localizationsDelegates: const [
GlobalWidgetsLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
locale: const Locale('nl', 'NL'),
supportedLocales: const [
Locale('nl', 'NL'),
Locale('en', 'US'),
],
title: 'Demo drag down date time picker',
theme: ThemeData(
primarySwatch: Colors.blue,
@ -28,8 +40,10 @@ class MyApp extends StatelessWidget {
class DatePickerDemo extends StatelessWidget {
const DatePickerDemo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
// set locale to Dutch
const dateTimePickerTheme = DateTimePickerTheme(
dateBoxShape: DateBoxShape.roundedRectangle,
backgroundColor: Colors.white,
@ -120,6 +134,8 @@ class DatePickerDemo extends StatelessWidget {
),
),
DragDownDateTimePicker(
onTimerPickerSheetChange: (value) {},
alwaysUse24HourFormat: true,
dateTimePickerTheme: const DateTimePickerTheme(
backgroundColor: Colors.white,
markedIndicatorColor: Colors.red,
@ -145,7 +161,7 @@ class DatePickerDemo extends StatelessWidget {
),
),
markedDates: [DateTime(2022, 9, 6)],
)
),
],
),
);

View file

@ -61,7 +61,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.0"
version: "2.1.0"
flutter_lints:
dependency: "direct dev"
description:
@ -69,13 +69,18 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
intl:
dependency: transitive
dependency: "direct main"
description:
name: intl
url: "https://pub.dartlang.org"

View file

@ -1,7 +1,7 @@
name: datetime_picker_example
description: DateTimePicker Widget
publish_to: 'none'
publish_to: "none"
version: 1.0.0+1
@ -12,13 +12,15 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
flutter_date_time_picker:
flutter_date_time_picker:
path: ../
flutter_localizations:
sdk: flutter
intl: ^0.17.0 # Add this line
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
uses-material-design: true

View file

@ -2,8 +2,6 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_date_time_picker/src/models/date_time_picker_theme.dart';
import 'package:flutter_date_time_picker/src/utils/date_time_picker_controller.dart';
@ -15,110 +13,15 @@ class DragDownDateTimePicker extends StatefulWidget {
/// A widget that displays a date picker from a sheet form the top of the screen.
/// This sheet displays initially displays a week but can be dragged down to show a full month.
/// Both views can be dragged sideways to show the next or previous week/month.
///
/// Example:
/// ```dart
/// DatePicker(
/// dateTimePickerTheme: const DateTimePickerTheme()
/// initialDate: selectedDate,
/// highlightToday: true,
/// onTapDay: (date) {
/// setState(() {
/// selectedDate = date;
/// });
/// },
/// markedDates: [
/// DateTime(2022, 3, 14),
/// ],
/// wrongTimeDialog:
/// AlertDialog(
/// title: const Text('Invalid Time'),
/// content: SingleChildScrollView(
/// child: ListBody(
/// children: const <Widget>[
/// Text(
/// 'The time you try to choose is disabled, try to pick another time.'),
/// ],
/// ),
/// ),
/// actions: <Widget>[
/// TextButton(
/// child: const Text('OK'),
/// onPressed: () {
/// Navigator.pop(context);
/// },
/// ),
/// ],
/// ),
/// header: Container(
/// height: 100,
/// width: MediaQuery.of(context).size.width,
/// padding: const EdgeInsets.only(bottom: 10),
/// child: Row(
/// crossAxisAlignment: CrossAxisAlignment.end,
/// mainAxisAlignment: MainAxisAlignment.center,
/// children: [
/// const SizedBox(
/// width: 160,
/// height: 34,
/// child: Center(
/// child: Text(
/// 'Personal calendar',
/// style: TextStyle(
/// fontSize: 16,
/// fontWeight: FontWeight.w900,
/// ),
/// ),
/// ),
/// ),
/// const SizedBox(
/// width: 4,
/// ),
/// Container(
/// width: 160,
/// height: 34,
/// decoration: BoxDecoration(
/// color: const Color(0xFF00273D),
/// borderRadius: const BorderRadius.all(
/// Radius.circular(10),
/// ),
/// boxShadow: [
/// BoxShadow(
/// color: const Color(0xFF000000).withOpacity(0.50),
/// offset: const Offset(0, 6),
/// blurRadius: 9,
/// ),
/// ],
/// ),
/// child: const Center(
/// child: Text(
/// 'Work calendar',
/// style: TextStyle(
/// color: Colors.white,
/// fontSize: 16,
/// fontWeight: FontWeight.w900,
/// ),
/// ),
/// ),
/// ),
/// ],
/// ),
/// ),
/// child: Container(
/// margin: const EdgeInsets.only(
/// top: 195,
/// ),
/// child: HolidayRoster(),
/// ),
/// ),
///```
DragDownDateTimePicker({
const DragDownDateTimePicker({
this.dateTimePickerTheme = const DateTimePickerTheme(),
this.header,
this.onTimerPickerSheetChange,
this.onTapDay,
this.highlightToday = true,
this.wrongTimeDialog,
bool? use24HourFormat,
this.alwaysUse24HourFormat,
this.pickTime = false,
this.initialDate,
this.markedDates,
@ -126,9 +29,7 @@ class DragDownDateTimePicker extends StatefulWidget {
this.disabledTimes,
this.child,
super.key,
}) {
alwaysUse24HourFormat = use24HourFormat ?? _useTimeFormatBasedOnLocale();
}
});
/// The child contained by the DatePicker.
final Widget? child;
@ -149,8 +50,8 @@ class DragDownDateTimePicker extends StatefulWidget {
final bool highlightToday;
/// a [bool] to set de clock on [TimePickerDialog] to a fixed 24 or 12-hour format.
/// By default this gets determined by the [Locale] on the device.
late final bool alwaysUse24HourFormat;
/// By default this gets determined by the settings on the user device.
final bool? alwaysUse24HourFormat;
/// [pickTime] is a [bool] that determines if the user is able to pick a time after picking a date using the [TimePickerDialog].
final bool pickTime;
@ -167,6 +68,10 @@ class DragDownDateTimePicker extends StatefulWidget {
/// a [List] of [TimeOfDay] objects that cannot be picked in the [TimePickerDialog].
final List<TimeOfDay>? disabledTimes;
/// Function that gets called when the view changes from week to month or vice versa.
/// The value is the amount of scrolledpixels.
final Function(double)? onTimerPickerSheetChange;
@override
State<StatefulWidget> createState() => _DragDownDateTimePickerState();
}
@ -199,6 +104,9 @@ class _DragDownDateTimePickerState extends State<DragDownDateTimePicker> {
_dateTimePickerController.addListener(() {
setState(() {});
});
_dragController.addListener(() {
widget.onTimerPickerSheetChange?.call(_dragController.pixels);
});
}
@override
@ -279,24 +187,3 @@ class _DragDownDateTimePickerState extends State<DragDownDateTimePicker> {
);
}
}
bool _useTimeFormatBasedOnLocale() {
// Get LocaleName of current platform and split language- and countryCode in 2 List values.
List<String> deviceLocale = Platform.localeName.split('_');
// Make LocaleName of current platform in a Locale Object
Locale defaultLocale = Locale.fromSubtags(
languageCode: deviceLocale[0],
countryCode: deviceLocale[1],
);
// Determine Country.
switch (defaultLocale.countryCode) {
case 'NL':
return true;
case 'US':
return false;
default:
return true;
}
}

View file

@ -31,31 +31,9 @@ extension DateTimeExtension on DateTime {
bool get isLeapYear =>
(year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
/// Returns the amount of days in the current month of the [DateTime] object
int daysInMonth() {
late int amountOfDays;
switch (month) {
case DateTime.january:
case DateTime.march:
case DateTime.may:
case DateTime.july:
case DateTime.august:
case DateTime.october:
case DateTime.december:
amountOfDays = 31;
break;
case DateTime.april:
case DateTime.june:
case DateTime.september:
case DateTime.november:
amountOfDays = 30;
break;
case DateTime.february:
amountOfDays = isLeapYear ? 29 : 28;
break;
}
return amountOfDays;
return DateTime(year, month + 1, 0).day;
}
}

View file

@ -9,10 +9,10 @@ class DateTimePickerController extends ChangeNotifier {
DateTimePickerController({
required this.theme,
required this.highlightToday,
required this.alwaysUse24HourFormat,
required this.pickTime,
required this.browsingDate,
required this.selectedDate,
this.alwaysUse24HourFormat,
this.header,
this.wrongTimeDialog,
this.markedDates,

View file

@ -33,11 +33,11 @@ class MonthDateTimePickerSheet extends StatelessWidget {
height: 10,
),
Text(
DateFormat.yMMMM().format(
// use localization to get the month name
DateFormat.yMMMM(Localizations.localeOf(context).toString()).format(
dateTimePickerController.browsingDate,
),
style: theme.baseTheme.textStyle!
.copyWith(fontSize: 25),
style: theme.baseTheme.textStyle!.copyWith(fontSize: 25),
),
SizedBox(
width: MediaQuery.of(context).size.width,

View file

@ -43,7 +43,7 @@ class WeekDateTimePicker extends StatelessWidget {
: () async {
TimeOfDay? timeOfDay;
DateTime selectedDate = date.daysOfWeek()[index];
var selectedDate = date.daysOfWeek()[index];
timeOfDay = const TimeOfDay(hour: 0, minute: 0);
@ -65,7 +65,7 @@ class WeekDateTimePicker extends StatelessWidget {
}
}
DateTime selectedDateTime = DateTime(
var selectedDateTime = DateTime(
selectedDate.year,
selectedDate.month,
selectedDate.day,
@ -82,7 +82,7 @@ class WeekDateTimePicker extends StatelessWidget {
children: [
const Spacer(),
Text(
DateFormat.E()
DateFormat.E(Localizations.localeOf(context).toString())
.format(
date.daysOfWeek().elementAt(index),
)

View file

@ -20,16 +20,17 @@ class WeekDateTimePickerSheet extends StatelessWidget {
final bool showHeader;
final double weekDateBoxSize;
String getDateHeader() {
List<DateTime> weekDays =
String _getDateHeader(BuildContext context) {
var weekDays =
dateTimePickerController.browsingDate.daysOfWeek();
String firstDay = weekDays.first.day.toString();
var firstDay = weekDays.first.day.toString();
String lastDay = weekDays.last.day.toString();
var lastDay = weekDays.last.day.toString();
String monthYear =
DateFormat("MMMM, yyyy").format(dateTimePickerController.browsingDate);
var monthYear =
DateFormat("MMMM, yyyy", Localizations.localeOf(context).toString())
.format(dateTimePickerController.browsingDate);
return '$firstDay - $lastDay $monthYear';
}
@ -50,7 +51,7 @@ class WeekDateTimePickerSheet extends StatelessWidget {
),
if (showHeader) ...[
Text(
getDateHeader(),
_getDateHeader(context),
style: theme.baseTheme.textStyle!.copyWith(fontSize: 9),
),
const SizedBox(

View file

@ -1,6 +1,6 @@
name: flutter_date_time_picker
description: A new Flutter package project.
version: 2.0.0
description: A Flutter package for date and time picker.
version: 2.1.0
homepage: https://iconica.nl/
environment: