Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selected dates are not updating when i get from server #1

Closed
AbdulBasitSaleem opened this issue Mar 10, 2020 · 14 comments
Closed

selected dates are not updating when i get from server #1

AbdulBasitSaleem opened this issue Mar 10, 2020 · 14 comments

Comments

@AbdulBasitSaleem
Copy link

AbdulBasitSaleem commented Mar 10, 2020

Hello @agryva

SomeCalendar(
mode: SomeMode.Multi,
startDate: Jiffy().subtract(years: 3),
lastDate: Jiffy().add(months: 9),
selectedDates: selectedDates,
done: (date) {
setState(() {
selectedDates = date;
showSnackbar(selectedDates.toString());
});
},
onTapFunction: (selectedDate) {
print(selectedDate);
},
));

  • I get 'selected dates' from server,when i got these dates and set it to the calendar, with setState(){};
    It did not update the UI. Please also guide me that how can i remove selected date from the list when i tap on that date, If it is already selected

  • I don't want to show it as dialog

Thanks

@agryva
Copy link
Owner

agryva commented Mar 10, 2020

  • Have you entered the "selected date" from the server in the "selectedDates" parameter in the form of a list?

  • UI Calendar without dialog will be present in the next version, please wait 😁`

@AbdulBasitSaleem
Copy link
Author

  • list of date coming from server, I have set it to the selected dates attribute, but it did not update the UI for those dates
  • When next version is coming, waiting for it

Thanks

@AbdulBasitSaleem
Copy link
Author

SomeCalendar(
mode: SomeMode.Multi,
startDate: Jiffy().subtract(months: 3),
lastDate: Jiffy().add(months: 9),
primaryColor: Color(kPrimaryColor),
selectedDates: bookedDates, // these dates are coming from server
onTapFunction: (selectedDate) { // this callback i enabled to get a single date click in multiple mode
if (!_map.containsKey(selectedDate)) {
newAvailability = NewAvailability();
newAvailability.date = dateFormat.format(selectedDate);
newAvailability.startTime = '09:30 AM';
newAvailability.endTime = '05:30 PM';
newAvailability.status = true;
_map[selectedDate] = newAvailability;
} else {
_map[selectedDate].status =
_map[selectedDate].status == true ? false : true;
_map.update(selectedDate, (v) => _map[selectedDate]);
}
setState(() {});

  },
);

It is not showing selected dates coming from server, when ever I hot restart then it comes

@agryva
Copy link
Owner

agryva commented Mar 10, 2020

please update to some_calendar: ^1.1.3 i've fix a bug

@agryva agryva closed this as completed Mar 10, 2020
@AbdulBasitSaleem
Copy link
Author

Thank you i will see this

@AbdulBasitSaleem
Copy link
Author

@agryva I checked that still it is not showing me the dates, if i have already built a calendar and set selected dates after building the calendar, it does not get update ???

@agryva
Copy link
Owner

agryva commented Mar 10, 2020

variable 'bookedDates' is list a datetime ?

@AbdulBasitSaleem
Copy link
Author

AbdulBasitSaleem commented Mar 10, 2020

yes of course it is list of dateTime, but i assign it to selectedDates: when calendar has built.
I am not opening your calendar in dialog

@agryva
Copy link
Owner

agryva commented Mar 10, 2020

"I am not opening your calendar in dialog"
please try opening this library with dialog is it still a bug ?

@AbdulBasitSaleem
Copy link
Author

My friend my requirement is not to open calendar in dialog. Can you help me without dialog.

@agryva
Copy link
Owner

agryva commented Mar 11, 2020

@AbdulBasitSaleem please update to "some_calendar: ^1.2.0" i've fix a bug and please to see the Readme.

Thanks

@AbdulBasitSaleem
Copy link
Author

Good work @agryva. I will give you feedback about this.

Thank you so much

@AbdulBasitSaleem
Copy link
Author

AbdulBasitSaleem commented Mar 11, 2020

@agryva, Thank you for this calendar.

  • There is still one problem that if I set selectedDates (coming from server or you can set delay to add dates) after building calendar then it does not show on the calendar, After hot resetting then it shows the selectedDates

@AbdulBasitSaleem
Copy link
Author

AbdulBasitSaleem commented Mar 11, 2020

@agryva Please see this code, What i am trying to achieve. May be you get to know. It will be highly
appreciable.

@OverRide
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Color(kPrimaryColor),
title: Text('Set Availability'),
centerTitle: true,
),
body: BlocListener(
bloc: _newAvailabilityBloc,
listener: (BuildContext context, state) {
if (state is AvailabilityErrorState) {
Scaffold.of(context)
.showSnackBar(AppGlobal.showMessageInSnackBar(state.error));
}

        if (state is CreatedNewAvailabilityState) {
          Scaffold.of(context).showSnackBar(
              AppGlobal.showMessageInSnackBar('Availability is added'));
        }

        if (state is FetchedGuardAvailabilities) {
          if (state.availabilitiesList != null &&
              state.availabilitiesList.length > 0) {
            newAvailabilitiesList = state.availabilitiesList;
    
              for (NewAvailability newAvailability
                  in newAvailabilitiesList) {
                DateTime dateTime = dateFormat.parse(newAvailability.date);
                listOfAvailabilities.add(dateTime);
                selectedDates.add(dateTime);    // here i am adding server dates to list, then bloc builder rebuilds UI, but your calendar does not show these dates
              }
            
          }
        }
      },
      child: BlocBuilder<NewAvailabilityBloc, NewAvailabilityState>(
        builder: (context, state) {
          return ModalProgressHUD(
            inAsyncCall: state is InitialLoadingState ? true : false,
            child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.all(8.0),
                    child: Column(
                      children: <Widget>[
                        Text(
                          currentDateTime,
                          style: TextStyle(
                            color: Colors.black,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        SizedBox(
                          height: 15.0,
                        ),

                      _buildCalendar(),

                        ListView.builder(
                            shrinkWrap: true,
                            physics: NeverScrollableScrollPhysics(),
                            itemCount: manageListViewDates.length,
                            itemBuilder: (context, index) {
                              return _timeSelectorItem(index);
                            }),
                        SizedBox(
                          height: 20.0,
                        ),
                      ],
                    ),
                  ),
                  StyledButton(
                    color: Color(kPrimaryColor),
                    btnText: 'Save',
                    textColor: Colors.white,
                    borderRadius: 30.0,
                    width: width * 0.65,
                    onPressed: () {
                      List<NewAvailability> data = List();
                      _map.forEach((k, v) => data.add(v));

                      for (int i = 0; i < data.length; i++) {
                        print('date: ${data[i].date}');
                        print('status: ${data[i].status}');
                      }

                      _newAvailabilityBloc.add(AddNewAvailabilityEvent(
                          availabilitiesList: data));
                    },
                  )
                ],
              ),
            ),
          );
        },
      ),
    ),
  ),
);

}

Widget _buildCalendar() {
return SomeCalendar(
mode: SomeMode.Multi,
isWithoutDialog: true,
scrollDirection: Axis.horizontal,
startDate: Jiffy().subtract(years: 3),
lastDate: Jiffy().add(months: 9),
selectedDates: selectedDates,
done: (date) {},
);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants