Skip to content

Commit

Permalink
fix: use enum OTLNavigatorTransition instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
snaoyam authored and sboh1214 committed Aug 19, 2023
1 parent 783ad65 commit be266bc
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 76 deletions.
7 changes: 2 additions & 5 deletions lib/pages/course_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import 'package:otlplus/widgets/review_block.dart';
import 'package:otlplus/widgets/review_write_block.dart';

class CourseDetailPage extends StatelessWidget {
CourseDetailPage({Key? key, this.fromLectureDetailPage = false})
: super(key: key);
CourseDetailPage({Key? key}) : super(key: key);
static String route = 'course_detail_page';

final bool fromLectureDetailPage;
final _scrollController = ScrollController();

@override
Expand Down Expand Up @@ -326,8 +324,7 @@ class CourseDetailPage extends StatelessWidget {
return LectureGroupSimpleBlock(
lectures: filteredLectures,
semester: semester,
filter: selectedFilter,
fromLectureDetailPage: fromLectureDetailPage);
filter: selectedFilter);
},
).toList(),
),
Expand Down
24 changes: 12 additions & 12 deletions lib/pages/lecture_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ class LectureDetailPage extends StatelessWidget {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Visibility(
visible: fromCourseDetailPage == false,
child: Padding(
padding: EdgeInsets.only(right: 8.0),
child: IconTextButton(
onTap: () {
Padding(
padding: EdgeInsets.only(right: 8.0),
child: IconTextButton(
onTap: () {
if (fromCourseDetailPage) {
OTLNavigator.pop(context);

Check warning on line 164 in lib/pages/lecture_detail_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/lecture_detail_page.dart#L159-L164

Added lines #L159 - L164 were not covered by tests
} else {
context.read<CourseDetailModel>().loadCourse(lecture.course);
OTLNavigator.push(
context, CourseDetailPage(fromLectureDetailPage: false));
},
text: "dictionary.dictionary".tr(),
textStyle: bodyRegular.copyWith(color: OTLColor.pinksMain),
),
OTLNavigator.push(context, CourseDetailPage());

Check warning on line 167 in lib/pages/lecture_detail_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/lecture_detail_page.dart#L166-L167

Added lines #L166 - L167 were not covered by tests
}
},
text: "dictionary.dictionary".tr(),
textStyle: bodyRegular.copyWith(color: OTLColor.pinksMain),

Check warning on line 171 in lib/pages/lecture_detail_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/lecture_detail_page.dart#L170-L171

Added lines #L170 - L171 were not covered by tests
),
),
IconTextButton(
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/liked_review_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class LikedReviewPage extends StatelessWidget {
reviews[index].course.id);
OTLNavigator.push(
context, CourseDetailPage(),

Check warning on line 70 in lib/pages/liked_review_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/liked_review_page.dart#L66-L70

Added lines #L66 - L70 were not covered by tests
transition: 'right-left');
transition: OTLNavigatorTransition
.rightLeft);
},
);
},
Expand Down
12 changes: 7 additions & 5 deletions lib/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class _MainPageState extends State<MainPage> {
trailing: Row(
children: [
IconTextButton(
onTap: () =>
OTLNavigator.push(context, UserPage(), transition: 'down-up'),
onTap: () => OTLNavigator.push(context, UserPage(),

Check warning on line 56 in lib/pages/main_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/main_page.dart#L53-L56

Added lines #L53 - L56 were not covered by tests
transition: OTLNavigatorTransition.downUp),
icon: 'assets/icons/person.svg',
iconSize: 24,
color: OTLColor.pinksMain,
Expand All @@ -63,7 +63,7 @@ class _MainPageState extends State<MainPage> {
),
IconTextButton(
onTap: () => OTLNavigator.push(context, SettingsPage(),

Check warning on line 65 in lib/pages/main_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/main_page.dart#L64-L65

Added lines #L64 - L65 were not covered by tests
transition: 'down-up'),
transition: OTLNavigatorTransition.downUp),
icon: 'assets/icons/gear.svg',
iconSize: 24,
color: OTLColor.pinksMain,
Expand Down Expand Up @@ -241,7 +241,8 @@ class _MainPageState extends State<MainPage> {
children: [
IconTextButton(
onTap: () {
OTLNavigator.push(context, PrivacyPage(), transition: 'down-up');
OTLNavigator.push(context, PrivacyPage(),

Check warning on line 244 in lib/pages/main_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/main_page.dart#L244

Added line #L244 was not covered by tests
transition: OTLNavigatorTransition.downUp);
},
text: 'title.privacy'.tr(),
textStyle: labelRegular.copyWith(color: OTLColor.gray75),
Expand All @@ -250,7 +251,8 @@ class _MainPageState extends State<MainPage> {
),
IconTextButton(
onTap: () {
OTLNavigator.push(context, PeoplePage(), transition: 'down-up');
OTLNavigator.push(context, PeoplePage(),

Check warning on line 254 in lib/pages/main_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/main_page.dart#L254

Added line #L254 was not covered by tests
transition: OTLNavigatorTransition.downUp);
},
text: 'title.credit'.tr(),
textStyle: labelRegular.copyWith(color: OTLColor.gray75),
Expand Down
89 changes: 46 additions & 43 deletions lib/utils/navigator.dart
Original file line number Diff line number Diff line change
@@ -1,97 +1,100 @@
import 'package:flutter/material.dart';

enum OTLNavigatorTransition { rightLeft, downUp, immediate }

enum _TransitionHistory { rightLeft, downUp, immediate, dialog }

class OTLNavigator {
static List<Route> _rightleftTransitionHistory = [];
static List<Route> _downupTransitionHistory = [];
//0 for right-left, 1 for down-up, 2 for immediate, 3 for dialog
static List<int> _history = [];
static List<_TransitionHistory> _history = [];

Check warning on line 10 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L10

Added line #L10 was not covered by tests

static void _removeLastHistory() {
switch (_history.removeLast()) {
case 0:
case _TransitionHistory.rightLeft:
_rightleftTransitionHistory.removeLast();

Check warning on line 15 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L12-L15

Added lines #L12 - L15 were not covered by tests
break;
case 1:
case 2:
case _TransitionHistory.downUp:
case _TransitionHistory.immediate:
_downupTransitionHistory.removeLast();

Check warning on line 19 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L17-L19

Added lines #L17 - L19 were not covered by tests
break;
case 3:
case _TransitionHistory.dialog:

Check warning on line 21 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L21

Added line #L21 was not covered by tests
break;
}
}

static void _removeLastUntil(bool Function(int mode) predicate) {
static void _removeLastUntil(

Check warning on line 26 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L26

Added line #L26 was not covered by tests
bool Function(_TransitionHistory mode) predicate) {
while (!predicate(_history.last)) {
_removeLastHistory();

Check warning on line 29 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L28-L29

Added lines #L28 - L29 were not covered by tests
}
_removeLastHistory();

Check warning on line 31 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L31

Added line #L31 was not covered by tests
}

static Future<T?> push<T extends Object?>(BuildContext context, Widget page,

Check warning on line 34 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L34

Added line #L34 was not covered by tests
{String transition = "right-left"}) {
assert(transition == "down-up" ||
transition == "right-left" ||
transition == "immediate");
{OTLNavigatorTransition transition = OTLNavigatorTransition.rightLeft}) {
Route<T> _route;
if (transition == "right-left") {
_route = buildRightLeftPageRoute<T>(page);
_rightleftTransitionHistory.add(_route);
_history.add(0);
} else if (transition == "down-up") {
_route = buildDownUpPageRoute<T>(page);
_downupTransitionHistory.add(_route);
_history.add(1);
} else {
_route = buildImmediatePageRoute<T>(page);
_downupTransitionHistory.add(_route);
_history.add(2);
switch (transition) {
case OTLNavigatorTransition.rightLeft:
_route = buildRightLeftPageRoute<T>(page);
_rightleftTransitionHistory.add(_route);
_history.add(_TransitionHistory.rightLeft);

Check warning on line 41 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L38-L41

Added lines #L38 - L41 were not covered by tests
break;
case OTLNavigatorTransition.downUp:
_route = buildDownUpPageRoute<T>(page);
_downupTransitionHistory.add(_route);
_history.add(_TransitionHistory.downUp);

Check warning on line 46 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L43-L46

Added lines #L43 - L46 were not covered by tests
break;
case OTLNavigatorTransition.immediate:
_route = buildImmediatePageRoute<T>(page);
_downupTransitionHistory.add(_route);
_history.add(_TransitionHistory.immediate);

Check warning on line 51 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L48-L51

Added lines #L48 - L51 were not covered by tests
break;
}
return Navigator.of(context).push(_route);

Check warning on line 54 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L54

Added line #L54 was not covered by tests
}

static Future<T?> pushRoot<T extends Object?>(

Check warning on line 57 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L57

Added line #L57 was not covered by tests
BuildContext context, Widget page,
{String transition = "immediate"}) {
assert(transition == "down-up" ||
transition == "right-left" ||
transition == "immediate");
{OTLNavigatorTransition transition = OTLNavigatorTransition.immediate}) {
_rightleftTransitionHistory.clear();
_downupTransitionHistory.clear();
_history.clear();

Check warning on line 62 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L60-L62

Added lines #L60 - L62 were not covered by tests
Route<T> _route;
if (transition == "right-left") {
_route = buildRightLeftPageRoute<T>(page);
} else if (transition == "down-up") {
_route = buildDownUpPageRoute<T>(page);
} else {
_route = buildImmediatePageRoute<T>(page);
switch (transition) {
case OTLNavigatorTransition.rightLeft:
_route = buildRightLeftPageRoute<T>(page);

Check warning on line 66 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L65-L66

Added lines #L65 - L66 were not covered by tests
break;
case OTLNavigatorTransition.downUp:
_route = buildDownUpPageRoute<T>(page);

Check warning on line 69 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L68-L69

Added lines #L68 - L69 were not covered by tests
break;
case OTLNavigatorTransition.immediate:
_route = buildImmediatePageRoute<T>(page);

Check warning on line 72 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L71-L72

Added lines #L71 - L72 were not covered by tests
break;
}
return Navigator.of(context)
.pushAndRemoveUntil(_route, (Route<dynamic> route) => false);

Check warning on line 76 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L75-L76

Added lines #L75 - L76 were not covered by tests
}

static void pop<T extends Object?>(BuildContext context,

Check warning on line 79 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L79

Added line #L79 was not covered by tests
{String transition = "none", T? result}) {
assert(transition == "down-up" ||
transition == "right-left" ||
transition == "immediate" ||
transition == "none");
{OTLNavigatorTransition? until, T? result}) {
NavigatorState navigator = Navigator.of(context);
assert(_history.isNotEmpty);

Check warning on line 82 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L81-L82

Added lines #L81 - L82 were not covered by tests
if (transition == "none") {
if (until == null) {
_removeLastHistory();
return navigator.pop(result);
} else if (transition == "right-left") {
} else if (until == OTLNavigatorTransition.rightLeft) {
assert(_rightleftTransitionHistory.isNotEmpty);
navigator.popUntil((Route<dynamic> route) =>
_rightleftTransitionHistory.last == route || route.isFirst);
_removeLastUntil((mode) => mode == 0);
_removeLastUntil((mode) => mode == _TransitionHistory.rightLeft);
return navigator.pop(result);

Check warning on line 91 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L84-L91

Added lines #L84 - L91 were not covered by tests
} else {
assert(_downupTransitionHistory.isNotEmpty);
navigator.popUntil((Route<dynamic> route) =>
_downupTransitionHistory.last == route || route.isFirst);
_removeLastUntil((mode) => (mode == 1 || mode == 2));
_removeLastUntil((mode) => (mode == _TransitionHistory.downUp ||
mode == _TransitionHistory.immediate));
return navigator.pop(result);

Check warning on line 98 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L93-L98

Added lines #L93 - L98 were not covered by tests
}
}
Expand All @@ -113,7 +116,7 @@ class OTLNavigator {
Offset? anchorPoint,
TraversalEdgeBehavior? traversalEdgeBehavior,
}) {
_history.add(3);
_history.add(_TransitionHistory.dialog);
return showDialog(

Check warning on line 120 in lib/utils/navigator.dart

View check run for this annotation

Codecov / codecov/patch

lib/utils/navigator.dart#L119-L120

Added lines #L119 - L120 were not covered by tests
context: context,
builder: builder,
Expand Down
11 changes: 3 additions & 8 deletions lib/widgets/lecture_group_simple_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ class LectureGroupSimpleBlock extends StatelessWidget {
final List<Lecture> lectures;
final int semester;
final String? filter;
final bool fromLectureDetailPage;

LectureGroupSimpleBlock(
{required this.lectures,
required this.semester,
this.filter,
this.fromLectureDetailPage = false});
{required this.lectures, required this.semester, this.filter});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -65,9 +61,8 @@ class LectureGroupSimpleBlock extends StatelessWidget {
context
.read<LectureDetailModel>()
.loadLecture(lecture.id, false);
if (fromLectureDetailPage == false)
OTLNavigator.push(context,
LectureDetailPage(fromCourseDetailPage: true));
OTLNavigator.push(context,
LectureDetailPage(fromCourseDetailPage: true));

Check warning on line 65 in lib/widgets/lecture_group_simple_block.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/lecture_group_simple_block.dart#L64-L65

Added lines #L64 - L65 were not covered by tests
},
child: Padding(
padding: const EdgeInsets.symmetric(
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/otl_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class _OTLLayoutState extends State<OTLLayout> {
IconTextButton(

Check warning on line 165 in lib/widgets/otl_scaffold.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_scaffold.dart#L163-L165

Added lines #L163 - L165 were not covered by tests
icon: Icons.navigate_before,
onTap: () => OTLNavigator.pop(context,

Check warning on line 167 in lib/widgets/otl_scaffold.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_scaffold.dart#L167

Added line #L167 was not covered by tests
transition: 'right-left'),
until: OTLNavigatorTransition.rightLeft),
padding: EdgeInsets.all(16)),

Check warning on line 169 in lib/widgets/otl_scaffold.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_scaffold.dart#L169

Added line #L169 was not covered by tests
if (hasDrawer)
IconTextButton(

Check warning on line 171 in lib/widgets/otl_scaffold.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_scaffold.dart#L171

Added line #L171 was not covered by tests
Expand Down Expand Up @@ -193,7 +193,7 @@ class _OTLLayoutState extends State<OTLLayout> {
IconTextButton(

Check warning on line 193 in lib/widgets/otl_scaffold.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_scaffold.dart#L189-L193

Added lines #L189 - L193 were not covered by tests
icon: Icons.close,
onTap: () => OTLNavigator.pop(context,

Check warning on line 195 in lib/widgets/otl_scaffold.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_scaffold.dart#L195

Added line #L195 was not covered by tests
transition: 'down-up'),
until: OTLNavigatorTransition.downUp),
padding: EdgeInsets.all(16)),

Check warning on line 197 in lib/widgets/otl_scaffold.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_scaffold.dart#L197

Added line #L197 was not covered by tests
],
)
Expand Down

0 comments on commit be266bc

Please sign in to comment.