Skip to content

Commit

Permalink
Fix #66: update time attributes for time constructor (#75)
Browse files Browse the repository at this point in the history
* Fix #66: update time attributes for time constructor

* Update package documentation
  • Loading branch information
koukibadr committed Nov 12, 2023
1 parent 837e58d commit 60f21d4
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 46 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [2.3.1] - 12/11/2023

- Fix minutes set value in the `time` constructor
- Update `time` constructor to use `Time` class to ease setting hours and minutes values [PR-75](https://github.com/koukibadr/Bottom-Picker/pull/75)

## [2.2.1] - 22/10/2023

- Fix analysis issues
Expand Down
48 changes: 32 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To add bottom picker to your project add this line to your pubspec.yaml file

```yaml
dependencies:
bottom_picker: ^2.2.1
bottom_picker: ^2.3.1
```

## Parameters
Expand Down Expand Up @@ -132,6 +132,16 @@ dependencies:
///
DateTime? initialDateTime;

///The initial time set in the time picker widget
///required only when using the `time` constructor
Time? initialTime;

///The max time can be set in the time picker widget
Time? maxTime;

///The min time can be set in the time picker widget
Time? minTime;

///The gap between two minutes
///by default it's 1 minute
int? minuteInterval;
Expand Down Expand Up @@ -308,21 +318,27 @@ Time picker
```dart
BottomPicker.time(
title: "Set your next meeting time",
titleStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.orange
),
onSubmit: (index) {
print(index);
},
onClose: () {
print("Picker closed");
},
bottomPickerTheme: BOTTOM_PICKER_THEME.orange,
use24hFormat: true
).show(context);
title: 'Set your next meeting time',
titleStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.orange,
),
onSubmit: (index) {
print(index);
},
onClose: () {
print('Picker closed');
},
bottomPickerTheme: BottomPickerTheme.orange,
use24hFormat: true,
initialTime: Time(
minutes: 23,
),
maxTime: Time(
hours: 17,
),
).show(context);
Expand Down
7 changes: 7 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:bottom_picker/bottom_picker.dart';
import 'package:bottom_picker/resources/arrays.dart';
import 'package:bottom_picker/resources/time.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -271,6 +272,12 @@ class ExampleApp extends StatelessWidget {
},
bottomPickerTheme: BottomPickerTheme.orange,
use24hFormat: true,
initialTime: Time(
minutes: 23,
),
maxTime: Time(
hours: 17,
),
).show(context);
}

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.2.1"
version: "2.3.1"
characters:
dependency: transitive
description:
Expand Down
44 changes: 18 additions & 26 deletions lib/bottom_picker.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:bottom_picker/resources/arrays.dart';
import 'package:bottom_picker/resources/context_extension.dart';
import 'package:bottom_picker/resources/time.dart';
import 'package:bottom_picker/widgets/bottom_picker_button.dart';
import 'package:bottom_picker/widgets/close_icon.dart';
import 'package:bottom_picker/widgets/date_picker.dart';
Expand Down Expand Up @@ -172,6 +173,9 @@ class BottomPicker extends StatefulWidget {
BottomPicker.time({
Key? key,
required this.title,
required this.initialTime,
this.maxTime,
this.minTime,
this.description = '',
this.titleStyle = const TextStyle(),
this.titlePadding = const EdgeInsets.all(0),
Expand All @@ -184,10 +188,7 @@ class BottomPicker extends StatefulWidget {
this.bottomPickerTheme = BottomPickerTheme.blue,
this.gradientColors,
this.iconColor = Colors.white,
this.initialDateTime,
this.minuteInterval = 1,
this.minDateTime,
this.maxDateTime,
this.use24hFormat = false,
this.buttonText,
this.buttonPadding,
Expand All @@ -214,27 +215,8 @@ class BottomPicker extends StatefulWidget {
dateOrder = null;
itemExtent = 0;
onSubmitPressed = null;
initialDateTime = null;
assertInitialValues();

// https://github.com/flutter/flutter/issues/60456
if (initialDateTime == null) {
final dateTime = DateTime.now();
initialDateTime = DateTime(
dateTime.year,
dateTime.month,
dateTime.day,
dateTime.hour,
0,
);
} else {
initialDateTime = DateTime(
initialDateTime!.year,
initialDateTime!.month,
initialDateTime!.day,
initialDateTime!.hour,
0,
);
}
}

BottomPicker.range({
Expand Down Expand Up @@ -381,6 +363,16 @@ class BottomPicker extends StatefulWidget {
///
DateTime? initialDateTime;

///The initial time set in the time picker widget
///required only when using the `time` constructor
Time? initialTime;

///The max time can be set in the time picker widget
Time? maxTime;

///The min time can be set in the time picker widget
Time? minTime;

///The gap between two minutes
///by default it's 1 minute
int? minuteInterval;
Expand Down Expand Up @@ -602,10 +594,10 @@ class _BottomPickerState extends State<BottomPicker> {
)
: widget.bottomPickerType == BottomPickerType.dateTime
? DatePicker(
initialDateTime: widget.initialDateTime,
initialDateTime: widget.initialTime.toDateTime,
minuteInterval: widget.minuteInterval ?? 1,
maxDateTime: widget.maxDateTime,
minDateTime: widget.minDateTime,
maxDateTime: widget.maxTime.toDateTime,
minDateTime: widget.minTime.toDateTime,
mode: widget.datePickerMode,
onDateChanged: (DateTime date) {
selectedDateTime = date;
Expand Down
13 changes: 13 additions & 0 deletions lib/resources/extensions.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:bottom_picker/bottom_picker.dart';
import 'package:bottom_picker/resources/arrays.dart';
import 'package:bottom_picker/resources/time.dart';
import 'package:flutter/material.dart';

extension BottomPickerExtension on BottomPicker {
Expand All @@ -24,3 +25,15 @@ extension BottomPickerExtension on BottomPicker {
}
}
}

extension TimeClassExtensions on Time? {
DateTime? get toDateTime => this == null
? null
: DateTime(
DateTime.now().year,
DateTime.now().month,
DateTime.now().day,
this!.hours,
this!.minutes,
);
}
9 changes: 9 additions & 0 deletions lib/resources/time.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Time {
final int hours;
final int minutes;

Time({
this.hours = 0,
this.minutes = 0,
}) : assert(minutes < 60 && minutes >= 0 && hours >= 0 && hours < 24);
}
4 changes: 2 additions & 2 deletions lib/widgets/date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class DatePicker extends StatelessWidget {
Key? key,
required this.initialDateTime,
this.minuteInterval = 1,
required this.maxDateTime,
required this.minDateTime,
this.maxDateTime,
this.minDateTime,
required this.mode,
required this.onDateChanged,
this.use24hFormat = true,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bottom_picker
description: A new flutter package that let you create a bottom item picker or date & time picker with minmum parameters
version: 2.2.1
version: 2.3.1
homepage: 'https://github.com/koukibadr/Bottom-Picker'
environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down

0 comments on commit 60f21d4

Please sign in to comment.