Skip to content

Commit

Permalink
✨ Link user flag judgement with pages and providers.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Feb 11, 2020
1 parent 0ed01df commit 0974587
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
29 changes: 17 additions & 12 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class OpenJMUAppState extends State<OpenJMUApp> with WidgetsBindingObserver {
);

int initAction;

Brightness get _platformBrightness => Screens.mediaQuery.platformBrightness ?? Brightness.light;

@override
Expand All @@ -65,16 +66,28 @@ class OpenJMUAppState extends State<OpenJMUApp> with WidgetsBindingObserver {
tryRecoverLoginInfo();

Instances.eventBus
..on<TicketGotEvent>().listen((event) {
if (!currentUser.isTeacher) {
if (!currentUser.isPostgraduate) {
Provider.of<CoursesProvider>(currentContext, listen: false).initCourses();
Provider.of<ScoresProvider>(currentContext, listen: false).initScore();
}
}
Provider.of<MessagesProvider>(currentContext, listen: false).initMessages();
Provider.of<ReportRecordsProvider>(currentContext, listen: false).initRecords();
Provider.of<WebAppsProvider>(currentContext, listen: false).initApps();
})
..on<LogoutEvent>().listen((event) {
DataUtils.logout();
navigatorState.pushNamedAndRemoveUntil(
Routes.OPENJMU_LOGIN,
(_) => false,
arguments: {'initAction': initAction},
);
if (!currentUser.isTeacher) {
Provider.of<CoursesProvider>(currentContext, listen: false).unloadCourses();
Provider.of<ScoresProvider>(currentContext, listen: false).unloadScore();
if (!currentUser.isPostgraduate) {
Provider.of<CoursesProvider>(currentContext, listen: false).unloadCourses();
Provider.of<ScoresProvider>(currentContext, listen: false).unloadScore();
}
}
Provider.of<MessagesProvider>(currentContext, listen: false).unloadMessages();
Provider.of<ReportRecordsProvider>(currentContext, listen: false).unloadRecords();
Expand All @@ -83,15 +96,7 @@ class OpenJMUAppState extends State<OpenJMUApp> with WidgetsBindingObserver {
Provider.of<ThemesProvider>(currentContext, listen: false).resetTheme();
Provider.of<SettingsProvider>(currentContext, listen: false).reset();
});
})
..on<TicketGotEvent>().listen((event) {
if (!currentUser.isTeacher) {
Provider.of<CoursesProvider>(currentContext, listen: false).initCourses();
Provider.of<ScoresProvider>(currentContext, listen: false).initScore();
}
Provider.of<MessagesProvider>(currentContext, listen: false).initMessages();
Provider.of<ReportRecordsProvider>(currentContext, listen: false).initRecords();
Provider.of<WebAppsProvider>(currentContext, listen: false).initApps();
DataUtils.logout();
})
..on<ActionsEvent>().listen((event) {
initAction = Constants.quickActionsList.keys
Expand Down
6 changes: 3 additions & 3 deletions lib/model/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class UserInfo {
} else {
final int code = int.tryParse(workId.substring(4, 6));
if (code == null) return false;
return code >= 10 && code <= 19;
return (code >= 10 && code <= 19);
}
}

Expand All @@ -89,7 +89,7 @@ class UserInfo {
} else {
final int code = int.tryParse(workId.substring(4, 6));
if (code == null) return false;
return code >= 30 && code <= 39;
return (code >= 30 && code <= 39);
}
}

Expand All @@ -100,7 +100,7 @@ class UserInfo {
} else {
final int code = int.tryParse(workId.substring(4, 6));
if (code == null) return false;
return code >= 41 && code <= 45;
return (code >= 41 && code <= 45);
}
}

Expand Down
33 changes: 19 additions & 14 deletions lib/pages/home/apps_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class AppsPage extends StatefulWidget {

class AppsPageState extends State<AppsPage>
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
static List<String> get tabs => ['课程表', if (!(currentUser?.isTeacher ?? false)) '成绩', '应用'];
static List<String> get tabs => [
if (!(currentUser?.isPostgraduate ?? false)) '课程表',
if (!((currentUser?.isTeacher ?? false) || (currentUser?.isPostgraduate ?? false))) '成绩',
'应用',
];
final refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();

final _scrollController = ScrollController();
Expand Down Expand Up @@ -190,19 +194,20 @@ class AppsPageState extends State<AppsPage>
cacheExtent: 3,
controller: _tabController,
children: <Widget>[
currentUser.isTeacher != null
? currentUser?.isTeacher ?? false
? InAppBrowserPage(
url: '${API.courseScheduleTeacher}'
'?sid=${currentUser.sid}'
'&night=${dark ? 1 : 0}',
title: '课程表',
withAppBar: false,
withAction: false,
keepAlive: true,
)
: CourseSchedulePage(key: Instances.courseSchedulePageStateKey)
: SizedBox.shrink(),
if (tabs.contains('课程表'))
currentUser.isTeacher != null
? currentUser?.isTeacher ?? false
? InAppBrowserPage(
url: '${API.courseScheduleTeacher}'
'?sid=${currentUser.sid}'
'&night=${dark ? 1 : 0}',
title: '课程表',
withAppBar: false,
withAction: false,
keepAlive: true,
)
: CourseSchedulePage(key: Instances.courseSchedulePageStateKey)
: SizedBox.shrink(),
if (tabs.contains('成绩')) ScorePage(),
AppCenterPage(
refreshIndicatorKey: refreshIndicatorKey,
Expand Down

0 comments on commit 0974587

Please sign in to comment.