Skip to content

Commit

Permalink
chore: add very good analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
shan-shaji committed Sep 22, 2024
1 parent 80a1e4f commit 378b8da
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 96 deletions.
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:very_good_analysis/analysis_options.yaml
linter:
rules:
public_member_api_docs: false
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class HomePage extends StatelessWidget {
Padding(
padding: const EdgeInsets.all(8.0),
child: SelectWeekDays(
width: MediaQuery.of(context).size.width / 2,
width: MediaQuery.of(context).size.width,
fontSize: 14,
fontWeight: FontWeight.w500,
days: _days,
Expand Down
26 changes: 13 additions & 13 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
Expand All @@ -110,18 +110,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.15.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -179,10 +179,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.7.2"
vector_math:
dependency: transitive
description:
Expand All @@ -195,10 +195,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.1"
version: "14.2.5"
sdks:
dart: ">=3.3.0 <4.0.0"
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
2 changes: 1 addition & 1 deletion lib/day_picker.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export 'package:day_picker/src/select_day.dart';
export 'package:day_picker/model/day_in_week.dart';
export 'package:day_picker/src/select_day.dart';
10 changes: 7 additions & 3 deletions lib/model/day_in_week.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
class DayInWeek {
DayInWeek(
this.dayName, {
required this.dayKey,
this.isSelected = false,
});

String dayName;
String dayKey;
bool isSelected = false;

DayInWeek(this.dayName, {required this.dayKey, this.isSelected = false});

void toggleIsSelected() {
this.isSelected = !this.isSelected;
isSelected = !isSelected;
}
}
137 changes: 73 additions & 64 deletions lib/src/select_day.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,31 @@ import 'package:day_picker/model/day_in_week.dart';
import 'package:flutter/material.dart';

class SelectWeekDays extends StatefulWidget {
/// `SelectWeekDays` takes a list of days of type `DayInWeek`.
/// `onSelect` property will return `list` of days that are selected.
const SelectWeekDays({
required this.onSelect,
required this.days,
this.backgroundColor,
this.fontWeight,
this.fontSize,
this.selectedDaysFillColor,
this.unselectedDaysFillColor,
this.selectedDaysBorderColor,
this.unselectedDaysBorderColor,
this.selectedDayTextColor,
this.unSelectedDayTextColor,
this.border = true,
this.boxDecoration,
this.padding = 8.0,
this.width,
this.borderWidth,
this.elevation = 2.0,
super.key,
});

/// [onSelect] callBack to handle the Selected days
final Function onSelect;
final void Function(List<String> days) onSelect;

/// List of days of type `DayInWeek`
final List<DayInWeek> days;
Expand All @@ -17,73 +40,59 @@ class SelectWeekDays extends StatefulWidget {
/// [fontSize] - property to change the size of selected text
final double? fontSize;

/// [selectedDaysFillColor] - property to change the button color of days when the button is selected.
/// [selectedDaysFillColor] - property to change the button color of days
/// when the button is selected.
final Color? selectedDaysFillColor;

/// [unselectedDaysFillColor] - property to change the button color of days when the button is not selected.
/// [unselectedDaysFillColor] - property to change the button color of days
/// when the button is not selected.
final Color? unselectedDaysFillColor;

/// [selectedDaysBorderColor] - property to change the border color of the rounded buttons when day is selected.
/// [selectedDaysBorderColor] - property to change the border color of the
/// rounded buttons when day is selected.
final Color? selectedDaysBorderColor;

/// [unselectedDaysBorderColor] - property to change the border color of the rounded buttons when day is unselected.
/// [unselectedDaysBorderColor] - property to change the border color of
/// the rounded buttons when day is unselected.
final Color? unselectedDaysBorderColor;

/// [selectedDayTextColor] - property to change the color of text when the day is selected.
/// [selectedDayTextColor] - property to change the color of text when the
/// day is selected.
final Color? selectedDayTextColor;

/// [unSelectedDayTextColor] - property to change the text color when the day is not selected.
/// [unSelectedDayTextColor] - property to change the text color when
/// the day is not selected.
final Color? unSelectedDayTextColor;

/// [border] Boolean to handle the day button border by default the border will be true.
/// [border] Boolean to handle the day button border by
/// default the border will be true.
final bool border;

/// [boxDecoration] to handle the decoration of the container.
final BoxDecoration? boxDecoration;

/// [padding] property to handle the padding between the container and buttons by default it is 8.0
/// [padding] property to handle the padding between the
/// container and buttons by default it is 8.0
final double padding;

/// The property that can be used to specify the [width] of the [SelectWeekDays] container.
/// The property that can be used to specify the [width] of
/// the [SelectWeekDays] container.
/// By default this property will take the full width of the screen.
final double? width;

/// [borderWidth] property to handle the width border of the container by default it is 2.0
/// [borderWidth] property to handle the width border of
/// the container by default it is 2.0
final double? borderWidth;

/// [elevation] property to change the elevation of RawMaterialButton by default it is 2.0
final double? elevation;

/// `SelectWeekDays` takes a list of days of type `DayInWeek`.
/// `onSelect` property will return `list` of days that are selected.
SelectWeekDays({
required this.onSelect,
this.backgroundColor,
this.fontWeight,
this.fontSize,
this.selectedDaysFillColor,
this.unselectedDaysFillColor,
this.selectedDaysBorderColor,
this.unselectedDaysBorderColor,
this.selectedDayTextColor,
this.unSelectedDayTextColor,
this.border = true,
this.boxDecoration,
this.padding = 8.0,
this.width,
this.borderWidth,
this.elevation,
required this.days,
super.key,
});
/// [elevation] property to change the elevation of RawMaterialButton
/// by default it is 2.0
final double elevation;

@override
SelectWeekDaysState createState() => SelectWeekDaysState(days);
SelectWeekDaysState createState() => SelectWeekDaysState();
}

class SelectWeekDaysState extends State<SelectWeekDays> {
SelectWeekDaysState(List<DayInWeek> days) : _daysInWeek = days;

// list to insert the selected days.
List<String> selectedDays = [];

Expand All @@ -92,18 +101,19 @@ class SelectWeekDaysState extends State<SelectWeekDays> {

@override
void initState() {
_daysInWeek.forEach((element) {
if (element.isSelected) {
selectedDays.add(element.dayKey);
_daysInWeek = widget.days;
for (final day in _daysInWeek) {
if (day.isSelected) {
selectedDays.add(day.dayKey);
}
});
}
super.initState();
}

/// Set days to new value
// Set days to new value
void setDaysState(List<DayInWeek> newDays) {
selectedDays = [];
for (DayInWeek dayInWeek in newDays) {
for (final dayInWeek in newDays) {
if (dayInWeek.isSelected) {
selectedDays.add(dayInWeek.dayKey);
}
Expand All @@ -123,11 +133,10 @@ class SelectWeekDaysState extends State<SelectWeekDays> {
selectedDays.remove(day);
}
}
// [onSelect] is the callback which passes the Selected days as list.
widget.onSelect(selectedDays.toList());
}

// getter to handle background color of container.
// getter to handle background color of container.
Color? get _handleBackgroundColor {
if (widget.backgroundColor == null) {
return Theme.of(context).colorScheme.secondary;
Expand All @@ -136,13 +145,13 @@ class SelectWeekDaysState extends State<SelectWeekDays> {
}
}

// getter to handle fill color of buttons.
// getter to handle fill color of buttons.
Color? _handleDaysFillColor(bool onSelect) {
if (!onSelect && widget.unselectedDaysFillColor == null) {
return null;
}

return selectedUnselectedLogic(
return _selectedUnselectedLogic(
onSelect: onSelect,
selectedColor: widget.selectedDaysFillColor,
unSelectedColor: widget.unselectedDaysFillColor,
Expand All @@ -151,9 +160,9 @@ class SelectWeekDaysState extends State<SelectWeekDays> {
);
}

//getter to handle border color of days[buttons].
// getter to handle border color of days[buttons].
Color _handleBorderColorOfDays(bool onSelect) {
return selectedUnselectedLogic(
return _selectedUnselectedLogic(
onSelect: onSelect,
selectedColor: widget.selectedDaysBorderColor,
unSelectedColor: widget.unselectedDaysBorderColor,
Expand All @@ -162,9 +171,10 @@ class SelectWeekDaysState extends State<SelectWeekDays> {
);
}

// Handler to change the text color when the button is pressed and not pressed.
// Handler to change the text color when the button is pressed
// and not pressed.
Color? _handleTextColor(bool onSelect) {
return selectedUnselectedLogic(
return _selectedUnselectedLogic(
onSelect: onSelect,
selectedColor: widget.selectedDayTextColor,
unSelectedColor: widget.unSelectedDayTextColor,
Expand All @@ -173,29 +183,28 @@ class SelectWeekDaysState extends State<SelectWeekDays> {
);
}

Color selectedUnselectedLogic({
Color _selectedUnselectedLogic({
required bool onSelect,
required Color? selectedColor,
required Color? unSelectedColor,
required Color defaultSelectedColor,
required Color defaultUnselectedColor,
}) {
if (onSelect) {
return selectedColor != null ? selectedColor : defaultSelectedColor;
return selectedColor ?? defaultSelectedColor;
}
return unSelectedColor != null ? unSelectedColor : defaultUnselectedColor;
return unSelectedColor ?? defaultUnselectedColor;
}

@override
Widget build(BuildContext context) {
return Container(
width: widget.width ?? MediaQuery.of(context).size.width,
decoration: widget.boxDecoration == null
? BoxDecoration(
color: _handleBackgroundColor,
borderRadius: BorderRadius.circular(0),
)
: widget.boxDecoration,
decoration: widget.boxDecoration ??
BoxDecoration(
color: _handleBackgroundColor,
borderRadius: BorderRadius.circular(0),
),
child: Padding(
padding: EdgeInsets.all(widget.padding),
child: Row(
Expand All @@ -213,15 +222,15 @@ class SelectWeekDaysState extends State<SelectWeekDays> {
)
: BorderSide.none,
),
elevation: widget.elevation ?? 2.0,
elevation: widget.elevation,
onPressed: () {
setState(() {
day.toggleIsSelected();
});
_getSelectedWeekDays(day.isSelected, day.dayKey);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
child: Text(
day.dayName.length < 3
? day.dayName
Expand Down
Loading

0 comments on commit 378b8da

Please sign in to comment.