Coder Social home page Coder Social logo

shan-shaji / day_picker Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 11.0 6.54 MB

A simple Flutter widget library that helps us to select days in a week.

Home Page: https://pub.dev/packages/day_picker

License: MIT License

Dart 31.93% Kotlin 0.28% Swift 0.92% Objective-C 0.09% HTML 8.91% CMake 18.02% C++ 38.18% C 1.67%
flutter dart package daypicker widget weekdays dart2 pub select-week-days library dart-package flutter-package hactoberfest hacktoberfest-accepted

day_picker's Introduction

Day Picker

A Flutter widget library which helps us to select days in a week.

Test, Build and deploy Build Status likes popularity pub points

Screenshot

Screenshot week day picker Screenshot week day picker

Usage

Add day_picker to your pubspec.yaml file.

    flutter:
      sdk: flutter
    day_picker: 2.2.0

import the package:

import 'package:day_picker/day_picker.dart';

Constructor for the day_picker is given below.

    SelectWeekDays({
    required this.onSelect,
    this.backgroundColor,
    this.fontWeight,
    this.fontSize,
    this.daysFillColor,
    this.daysBorderColor,
    this.selectedDayTextColor,
    this.unSelectedDayTextColor,
    this.border = true,
    this.boxDecoration,
    this.padding = 8.0,
    required this.days,
    Key? key,
  }) : super(key: key);

Example here creates a day_picker with below style [with Gradient and no borders].

Screenshot week day picker

    List<DayInWeek> _days = [
    DayInWeek(
      "Sun",
    ),
    DayInWeek(
      "Mon",
    ),
    DayInWeek(
      "Tue",
      isSelected: true
    ),
    DayInWeek(
      "Wed",
    ),
    DayInWeek(
      "Thu",
    ),
    DayInWeek(
      "Fri",
    ),
    DayInWeek(
      "Sat",
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Select days in week"),
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: SelectWeekDays(
            fontSize: 14,
            fontWeight: FontWeight.w500,
            days: _days,
            border: false,
            boxDecoration: BoxDecoration(
              borderRadius: BorderRadius.circular(30.0),
              gradient: LinearGradient(
                begin: Alignment.topLeft,
                colors: [const Color(0xFFE55CE4), const Color(0xFFBB75FB)],
                tileMode:
                TileMode.repeated, // repeats the gradient over the canvas
              ),
            ),
            onSelect: (values) { // <== Callback to handle the selected days
              print(values);
            },
          ),
        ),
      ),
    );
  }

Pass a callback to the onSelect property with parameter of type List<String>.


Pass a list of days of type DayInWeek into days property

class DayInWeek {
  String dayName;
  bool isSelected = false;

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

DayInWeek consist of two Properties [dayName] and [isSelected]. By default [isSelected] value will be false


Example:

void handleOnSelect(List<String> value){
    //TODO: Manipulate the List of days selected
    print(value);
}

Customization

Property Type Description
onSelect List<String> Callback invoked when days are selected
days List<DayInWeek> List of days that need to be passed
padding double Padding between container and the buttons [by default it is 8.0]
boxdecoration BoxDecoration provides variety of ways to style the background container[gradient, color, border radius]
backgroundColor Color Property to change the color of the container
fontSize double Property to change size of font
fontWeight FontWeight Property to change the font weight of text
daysFillColor Color Property to change the color of rounded buttons when the days are selected
daysBorderColor Color Property to change the border color of rounded button
selectedDayTextColor Color property to change the text color of the selected days
unSelectedDayTextColor Color property to change the text color when the days are not selected
border bool Set this property to false if border is not needed around the rounded buttons[by default this property will be true]

With the implementation of the setDaysState method, developers can dynamically modify which days are selected within their application's code, even after the SelectWeekDays widget has already been constructed. By utilizing the Global Key that is passed into the widget, one can easily update the selected dates as desired.

Contributions

Contributions of any kind are more than welcome😊! Feel free to fork and improve day_picker or open an issue.

day_picker's People

Contributors

aamilsilawat26 avatar ben8557 avatar guyluz11 avatar joeljo2104 avatar shan-shaji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

day_picker's Issues

RangeError (end): Invalid value: Not in inclusive range 0..2: 3

I'm using the following list of DayInWeek but the widget does not allow these names.

    List<DayInWeek> _days = [
      DayInWeek("Zo", isSelected: schedule.day1!),
      DayInWeek("Ma", isSelected: schedule.day2!),
      DayInWeek("Di", isSelected: schedule.day3!),
      DayInWeek("Wo", isSelected: schedule.day4!),
      DayInWeek("Do", isSelected: schedule.day5!),
      DayInWeek("Vr", isSelected: schedule.day6!),
      DayInWeek("Za", isSelected: schedule.day7!),
    ];

Option to change SelectWeekDays after widget got created

Feature request
I am trying to change selected weekdays from outside after SelectWeekDays got created.

SelectWeekDays widget has its own state so just calling it again with different days will not change anything.

Let's add a way for programmer to change selected days from outside after SelectWeekDays got created, for example add a method to change days which will setState of days.

[FEATURE] selected\unselected Days Border Color option is missing

Describe the bug
Currently there is no way to choose different border color to day selected and unselected

Expected behavior
Instead of daysBorderColor we should have selectedDaysBorderColor and unselectedDaysBorderColor

Additional context
day_picker: ^2.2.0

[BUG]

when using SelectWeekDays in a dialog, close the diolog and enter it again the selected days remain selected unless I leave the page and come back again, I need to somehow reset the selectedDays list

[BUG] selection of a day in one of the widgets selects the day in other widgets

Describe the bug
When using multiple SelectWeekdays Widgets in the same app results in incorrect selections. If you select a day in one widget (say Monday in Widget 1) and go to another widget, say Widget 2 and enable day Tuesday, then the display in widget 2 shows
both Monday and Tuesday as selected. However, onPressed() returns the correct results.

To Reproduce
Steps to reproduce the behavior:
Execute the example code given in this repository.

  • Click on the first circle (Zo) in the first widget
  • Click on the second circle (Ma) in the second widget
  • You can see both Zo and Ma selected in the second widget

Expected behavior
Only 'Ma' selected in the second widget

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: Android emulator emulating Pixel 7
  • OS: Android
  • Version 2.2.0

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.