tanutapi / dart_meteor

A Meteor DDP library for Dart/Flutter developers.
Other
37 stars 15 forks source link

pass DateTime.now() to method parameter type date on meteor server side #16

Closed YouSour closed 4 years ago

YouSour commented 4 years ago

hi , @tanutapi , i want to pass my current date time from flutter to meteor method that accept parameter type date , i can't get my current date, i don't know why 🤔

Code : Meteor Method (Server)

export let checkRepayment = new ValidatedMethod({
  name: 'microfis.checkRepayment',
  mixins: [CallPromiseMixin],
  validate: new SimpleSchema({
    id: {
      type: String,
    },
    checkDate: {
      type: Date,
    },
    opts: {
      type: Object,
      optional: true,
      blackbox: true
    }
  }).validator(),
  run({ id, checkDate, opts }) {
  console.log(checkDate);
});

Code : Flutter

void initState() {
 super.initState();
   DateTime now = DateTime.now();
    meteor.call('microfis.checkRepayment', [
      {
        'id': '0001-000004',
        'checkDate': now
      }
    ]);
};
tanutapi commented 4 years ago

Could you try

    meteor.call('microfis.checkRepayment', [
      {
        'id': '0001-000004',
        'checkDate': { '\$date': now.millisecondsSinceEpoch }
      }
    ]);
YouSour commented 4 years ago

thank you , bro , it works @tanutapi