Skip to content

Commit

Permalink
Added date select on search
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolONEOfficial committed May 6, 2019
1 parent 0665996 commit 79d96c8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
11 changes: 10 additions & 1 deletion lib/prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ Future<SearchItem> showSearchItemSelect(
(searchItem) async {
if (searchItem != null) {
if (primary) {
Timetable.fromDay = Timetable.todayMidnight;
searchItem.toPrefs(PrefsIds.SEARCH_ITEM_PREFIX);
await PlatformChannels.deleteDb();
} else
} else {
Timetable.fromDay = await showDatePicker(
context: ctx,
initialDate: Timetable.fromDay ?? Timetable.todayMidnight,
firstDate: Timetable.todayMidnight,
lastDate: Timetable.todayMidnight.add(Duration(days: 365)),
) ??
Timetable.todayMidnight;
Timetable.selected = searchItem;
}
timetableIdBloc.add(Tuple2<bool, SearchItem>(primary, searchItem));
}
return searchItem;
Expand Down
10 changes: 6 additions & 4 deletions lib/timetable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class Timetable extends StatelessWidget {

static const dayCount = 6;

static DateTime fromDay = todayMidnight;

static DateTime get endCacheMidnight {
var mDate = todayMidnight.add(Duration(days: dayCount - 1));

Expand All @@ -93,8 +95,8 @@ class Timetable extends StatelessWidget {
timetable.clear();
return loadTimetable(
ctx,
Timetable.todayMidnight,
Timetable.todayMidnight.add(Duration(days: dayCount - 1)),
fromDay,
fromDay.add(Duration(days: dayCount - 1)),
searchItem,
updateDb,
);
Expand Down Expand Up @@ -470,7 +472,7 @@ class Timetable extends StatelessWidget {
(ctx, ssDayStyle) {
// Create tabs
final tabs = List<Tab>();
var mDay = todayMidnight.subtract(Duration(days: 1));
var mDay = fromDay.subtract(Duration(days: 1));
for (int mTabId = 0; mTabId < dayCount; mTabId++) {
debugPrint("mTabId: " + mTabId.toString());
mDay = mDay.add(Duration(days: 1));
Expand Down Expand Up @@ -529,7 +531,7 @@ class Timetable extends StatelessWidget {
dayCount,
(dayIndex) =>
MapEntry<DateTime, List<TimelineModel>>(
todayMidnight.add(
fromDay.add(
Duration(days: dayIndex),
),
List<TimelineModel>(),
Expand Down
32 changes: 3 additions & 29 deletions lib/widget_templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,35 +168,9 @@ class WidgetTemplates {
},
);

// static Widget buildFutureBuilder<T>(
// BuildContext ctx, {
// @required Future future,
// @required AsyncWidgetBuilder<T> builder,
// Widget loading,
// Widget error,
// }) {
// var result, error;
//
// future.then((res) {
// result = res;
// }).catchError((e) {
// error = e;
// });
//
// return AnimatedCrossFade(
// firstChild: loading ?? WidgetTemplates.buildLoadingNotification(ctx),
// secondChild: error != null
// ? WidgetTemplates.buildErrorNotification(ctx, "$error" ?? "Unknown")
// : builder(ctx, result),
// crossFadeState: result == null && error == null
// ? CrossFadeState.showFirst
// : CrossFadeState.showSecond,
// duration: Duration(seconds: 1),
// );
// }

static Future<bool> checkInternetConnection(
[String host = 'google.com']) async {
static Future<bool> checkInternetConnection([
String host = 'google.com',
]) async {
try {
final result = await InternetAddress.lookup(host);
return result.isNotEmpty && result[0].rawAddress.isNotEmpty;
Expand Down

0 comments on commit 79d96c8

Please sign in to comment.