Skip to content

Commit

Permalink
migrate to null-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehmet Gürol Çay committed Jul 17, 2021
1 parent feef0e7 commit 75ce55a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 56 deletions.
104 changes: 52 additions & 52 deletions lib/flutter_duration_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ const double _kCircleTop = _kPiByTwo;

class _DialPainter extends CustomPainter {
const _DialPainter({
@required this.context,
@required this.labels,
@required this.backgroundColor,
@required this.accentColor,
@required this.theta,
@required this.textDirection,
@required this.selectedValue,
@required this.pct,
@required this.multiplier,
@required this.minuteHand,
required this.context,
required this.labels,
required this.backgroundColor,
required this.accentColor,
required this.theta,
required this.textDirection,
required this.selectedValue,
required this.pct,
required this.multiplier,
required this.minuteHand,
});

final List<TextPainter> labels;
final Color backgroundColor;
final Color? backgroundColor;
final Color accentColor;
final double theta;
final TextDirection textDirection;
final int selectedValue;
final int? selectedValue;
final BuildContext context;

final double pct;
Expand All @@ -65,7 +65,7 @@ class _DialPainter extends CustomPainter {

// Draw the background outer ring
canvas.drawCircle(
centerPoint, radius, new Paint()..color = backgroundColor);
centerPoint, radius, new Paint()..color = backgroundColor!);

// Draw a translucent circle for every hour
for (int i = 0; i < multiplier; i = i + 1) {
Expand Down Expand Up @@ -101,7 +101,7 @@ class _DialPainter extends CustomPainter {
text: '${hours}${minutes}',
style: Theme.of(context)
.textTheme
.headline2
.headline2!
.copyWith(fontSize: size.shortestSide * 0.15)),
textDirection: TextDirection.ltr)
..layout();
Expand Down Expand Up @@ -175,16 +175,16 @@ class _DialPainter extends CustomPainter {

class _Dial extends StatefulWidget {
const _Dial(
{@required this.duration,
@required this.onChanged,
{required this.duration,
required this.onChanged,
this.snapToMins = 1.0})
: assert(duration != null);

final Duration duration;
final ValueChanged<Duration> onChanged;

/// The resolution of mins of the dial, i.e. if snapToMins = 5.0, only durations of 5min intervals will be selectable.
final double snapToMins;
final double? snapToMins;

@override
_DialState createState() => new _DialState();
Expand All @@ -200,10 +200,10 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
);
_thetaTween =
new Tween<double>(begin: _getThetaForDuration(widget.duration));
_theta = _thetaTween.animate(new CurvedAnimation(
parent: _thetaController, curve: Curves.fastOutSlowIn))
_theta = _thetaTween!.animate(new CurvedAnimation(
parent: _thetaController!, curve: Curves.fastOutSlowIn))
..addListener(() => setState(() {}));
_thetaController.addStatusListener((status) {
_thetaController!.addStatusListener((status) {
// if (status == AnimationStatus.completed && _hours != _snappedHours) {
// _hours = _snappedHours;
if (status == AnimationStatus.completed) {
Expand All @@ -219,9 +219,9 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
_minutes = _minuteHand(_turningAngle);
}

ThemeData themeData;
MaterialLocalizations localizations;
MediaQueryData media;
late ThemeData themeData;
MaterialLocalizations? localizations;
MediaQueryData? media;

@override
void didChangeDependencies() {
Expand All @@ -234,13 +234,13 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {

@override
void dispose() {
_thetaController.dispose();
_thetaController!.dispose();
super.dispose();
}

Tween<double> _thetaTween;
Animation<double> _theta;
AnimationController _thetaController;
Tween<double>? _thetaTween;
late Animation<double> _theta;
AnimationController? _thetaController;

double _pct = 0.0;
int _hours = 0;
Expand Down Expand Up @@ -310,7 +310,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {

void _updateThetaForPan() {
setState(() {
final Offset offset = _position - _center;
final Offset offset = _position! - _center!;
final double angle =
(math.atan2(offset.dx, offset.dy) - _kPiByTwo) % _kTwoPi;

Expand All @@ -327,13 +327,13 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
});
}

Offset _position;
Offset _center;
Offset? _position;
Offset? _center;

void _handlePanStart(DragStartDetails details) {
assert(!_dragging);
_dragging = true;
final RenderBox box = context.findRenderObject();
final RenderBox box = context.findRenderObject() as RenderBox;
_position = box.globalToLocal(details.globalPosition);
_center = box.size.center(Offset.zero);

Expand Down Expand Up @@ -424,7 +424,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
}

void _handleTapUp(TapUpDetails details) {
final RenderBox box = context.findRenderObject();
final RenderBox box = context.findRenderObject() as RenderBox;
_position = box.globalToLocal(details.globalPosition);
_center = box.size.center(Offset.zero);
_updateThetaForPan();
Expand All @@ -437,7 +437,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
}

List<TextPainter> _buildMinutes(TextTheme textTheme) {
final TextStyle style = textTheme.subtitle1;
final TextStyle? style = textTheme.subtitle1;

const List<Duration> _minuteMarkerValues = const <Duration>[
const Duration(hours: 0, minutes: 0),
Expand Down Expand Up @@ -467,7 +467,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {

@override
Widget build(BuildContext context) {
Color backgroundColor;
Color? backgroundColor;
switch (themeData.brightness) {
case Brightness.light:
backgroundColor = Colors.grey[200];
Expand All @@ -479,7 +479,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {

final ThemeData theme = Theme.of(context);

int selectedDialValue;
int? selectedDialValue;
_hours = _hourHand(_turningAngle);
_minutes = _minuteHand(_turningAngle);

Expand Down Expand Up @@ -517,17 +517,17 @@ class _DurationPickerDialog extends StatefulWidget {
///
/// [initialTime] must not be null.
const _DurationPickerDialog({
Key key,
@required this.initialTime,
Key? key,
required this.initialTime,
this.snapToMins,
this.boxDecoration,
}) : assert(initialTime != null),
super(key: key);

/// The duration initially selected when the dialog is shown.
final Duration initialTime;
final double snapToMins;
final BoxDecoration boxDecoration;
final double? snapToMins;
final BoxDecoration? boxDecoration;

@override
_DurationPickerDialogState createState() => new _DurationPickerDialogState();
Expand All @@ -546,10 +546,10 @@ class _DurationPickerDialogState extends State<_DurationPickerDialog> {
localizations = MaterialLocalizations.of(context);
}

Duration get selectedDuration => _selectedDuration;
Duration _selectedDuration;
Duration? get selectedDuration => _selectedDuration;
Duration? _selectedDuration;

MaterialLocalizations localizations;
late MaterialLocalizations localizations;

void _handleTimeChanged(Duration value) {
setState(() {
Expand Down Expand Up @@ -577,7 +577,7 @@ class _DurationPickerDialogState extends State<_DurationPickerDialog> {
child: new AspectRatio(
aspectRatio: 1.0,
child: new _Dial(
duration: _selectedDuration,
duration: _selectedDuration!,
onChanged: _handleTimeChanged,
snapToMins: widget.snapToMins,
)));
Expand Down Expand Up @@ -664,11 +664,11 @@ class _DurationPickerDialogState extends State<_DurationPickerDialog> {
/// context: context,
/// );
/// ```
Future<Duration> showDurationPicker(
{@required BuildContext context,
@required Duration initialTime,
double snapToMins,
BoxDecoration boxDecoration}) async {
Future<Duration?> showDurationPicker(
{required BuildContext context,
required Duration initialTime,
double? snapToMins,
BoxDecoration? boxDecoration}) async {
assert(context != null);
assert(initialTime != null);

Expand All @@ -685,14 +685,14 @@ Future<Duration> showDurationPicker(
class DurationPicker extends StatelessWidget {
final Duration duration;
final ValueChanged<Duration> onChange;
final double snapToMins;
final double? snapToMins;

final double width;
final double height;
final double? width;
final double? height;

DurationPicker(
{this.duration = const Duration(minutes: 0),
@required this.onChange,
required this.onChange,
this.snapToMins,
this.width,
this.height});
Expand Down
9 changes: 5 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: flutter_duration_picker
description: A widget for picking durations, inspired by Material Time Picker.
version: 1.0.4
author: Chris Harris <[email protected]>
homepage: https://github.com/cdharris/flutter_duration_picker
version: 2.0.0
author: Mehmet Gürol Çay (Chris Harris <[email protected]>)
homepage: https://github.com/gurolcay/flutter_duration_picker
original project: https://github.com/cdharris/flutter_duration_picker

dependencies:
flutter:
Expand All @@ -14,5 +15,5 @@ dev_dependencies:


environment:
sdk: ">=1.19.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'
flutter: ">=0.1.4 <2.0.0"

0 comments on commit 75ce55a

Please sign in to comment.