-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.dart
47 lines (42 loc) · 1.28 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import 'dart:io';
import 'data/models/near-by_offers.dart';
import 'data/models/offer.dart';
import 'services/offer_service.dart';
DateTime readUserInput() {
print("Enter your checkin date");
int? year, month, day;
print("Enter year");
year = int.tryParse(stdin.readLineSync()!);
while (year == null || year <= 0) {
print("Ivalid year, please retype");
year = int.tryParse(stdin.readLineSync()!);
}
print("Enter month");
month = int.tryParse(stdin.readLineSync()!);
while (month == null || month < 1 || month > 12) {
print("Ivalid month, please retype");
month = int.tryParse(stdin.readLineSync()!);
}
print("Enter day");
day = int.tryParse(stdin.readLineSync()!);
while (day == null || day < 1 || day > 31) {
print("Ivalid day, please retype");
day = int.tryParse(stdin.readLineSync()!);
}
return DateTime(year, month, day);
}
Future<void> main() async {
List<Offer>? offers = await OfferService.ins.getOffersNearBy();
if (offers == null) {
print("Something went wrong");
return;
}
if (offers == []) {
print("No offer from the third party");
return;
}
DateTime checkinDate = readUserInput();
NearbyOffers nearbyOffers =
NearbyOffers(offers: offers, checkinDate: checkinDate);
print(nearbyOffers.filterOffers());
}