Skip to content

Commit

Permalink
Merge pull request #75 from NKUST-ITC/develop
Browse files Browse the repository at this point in the history
Update to v3.2.5
  • Loading branch information
abc873693 authored Sep 12, 2019
2 parents fccdb53 + 1d3280e commit c469378
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 143 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main() async {
Preferences.getString(Constants.PREF_ICON_STYLE_CODE, AppIcon.OUTLINED);
AppTheme.code =
Preferences.getString(Constants.PREF_THEME_CODE, AppTheme.LIGHT);
if (kIsWeb) {
if (kIsWeb || Constants.isInDebugMode) {
} else if (Platform.isIOS || Platform.isAndroid) {
Crashlytics.instance.enableInDevMode = true;
// Pass all uncaught errors from the framework to Crashlytics.
Expand Down
4 changes: 4 additions & 0 deletions lib/models/announcements_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Announcements {
int id;
int nextId;
int lastId;
int weight;
String imgUrl;
String url;
String description;
Expand All @@ -43,6 +44,7 @@ class Announcements {
this.id,
this.nextId,
this.lastId,
this.weight,
this.imgUrl,
this.url,
this.description,
Expand All @@ -59,6 +61,7 @@ class Announcements {
id: json["id"],
nextId: json["nextId"],
lastId: json["lastId"],
weight: json["weight"],
imgUrl: json["imgUrl"],
url: json["url"],
description: json["description"],
Expand All @@ -70,6 +73,7 @@ class Announcements {
"id": id,
"nextId": nextId,
"lastId": lastId,
"weight": weight,
"imgUrl": imgUrl,
"url": url,
"description": description,
Expand Down
2 changes: 2 additions & 0 deletions lib/models/semester_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Semester {
String value;
String text;

String get code => '$year$value';

Semester({
this.year,
this.value,
Expand Down
46 changes: 39 additions & 7 deletions lib/pages/home/bus/bus_reservations_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import 'package:nkust_ap/widgets/hint_content.dart';
import 'package:nkust_ap/widgets/progress_dialog.dart';
import 'package:nkust_ap/widgets/yes_no_dialog.dart';

enum _State { loading, finish, error, empty, offlineEmpty }
enum _State {
loading,
finish,
error,
empty,
campusNotSupport,
userNotSupport,
offlineEmpty,
}

class BusReservationsPage extends StatefulWidget {
static const String routerName = "/bus/reservations";
Expand Down Expand Up @@ -68,23 +76,39 @@ class BusReservationsPageState extends State<BusReservationsPage>
);
}

String get errorText {
switch (state) {
case _State.error:
return app.clickToRetry;
case _State.empty:
return app.busEmpty;
case _State.campusNotSupport:
return app.campusNotSupport;
case _State.userNotSupport:
return app.userNotSupport;
default:
return '';
}
}

Widget _body() {
switch (state) {
case _State.loading:
return Container(
child: CircularProgressIndicator(), alignment: Alignment.center);
return Center(
child: CircularProgressIndicator(),
);
case _State.error:
case _State.empty:
case _State.campusNotSupport:
case _State.userNotSupport:
return FlatButton(
onPressed: () {
_getBusReservations();
FA.logAction('retry', 'click');
},
child: HintContent(
icon: AppIcon.assignment,
content: state == _State.error
? app.clickToRetry
: app.busReservationEmpty,
content: errorText,
),
);
case _State.offlineEmpty:
Expand Down Expand Up @@ -231,12 +255,20 @@ class BusReservationsPageState extends State<BusReservationsPage>
switch (e.type) {
case DioErrorType.RESPONSE:
if (e.response.statusCode == 401) {
setState(() {
state = _State.userNotSupport;
});
} else if (e.response.statusCode == 403) {
setState(() {
state = _State.campusNotSupport;
});
} else {
setState(() {
state = _State.error;
});
} else
Utils.handleResponseError(
context, 'getBusReservations', mounted, e);
}
break;
case DioErrorType.DEFAULT:
if (e.message.contains("HttpException")) {
Expand Down
198 changes: 117 additions & 81 deletions lib/pages/home/bus/bus_reserve_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ import 'package:nkust_ap/widgets/hint_content.dart';
import 'package:nkust_ap/widgets/progress_dialog.dart';
import 'package:nkust_ap/widgets/yes_no_dialog.dart';

enum _State { loading, finish, error, empty, offline }
enum _State {
loading,
finish,
error,
empty,
campusNotSupport,
userNotSupport,
offline
}
enum Station { janGong, yanchao }

class BusReservePage extends StatefulWidget {
Expand Down Expand Up @@ -56,89 +64,92 @@ class BusReservePageState extends State<BusReservePage>
super.build(context);
app = AppLocalizations.of(context);
return Scaffold(
body: OrientationBuilder(builder: (_, orientation) {
return NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
leading: Container(),
expandedHeight: orientation == Orientation.portrait
? MediaQuery.of(context).size.height * 0.20
: MediaQuery.of(context).size.width * 0.19,
floating: true,
backgroundColor: Colors.transparent,
flexibleSpace: FlexibleSpaceBar(
background: Column(
children: <Widget>[
Container(
color: Colors.transparent,
padding: EdgeInsets.symmetric(
horizontal: 16.0, vertical: 0.0),
child: Calendar(
isExpandable: false,
showTodayAction: false,
showCalendarPickerIcon: true,
showChevronsToChangeRange: true,
onDateSelected: (DateTime datetime) {
dateTime = datetime;
_getBusTimeTables();
FA.logAction('date_select', 'click');
},
initialCalendarDateOverride: dateTime,
dayChildAspectRatio:
orientation == Orientation.portrait ? 1.5 : 3,
weekdays: app.weekdays,
body: OrientationBuilder(
builder: (_, orientation) {
return NestedScrollView(
headerSliverBuilder:
(BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
leading: Container(),
expandedHeight: orientation == Orientation.portrait
? MediaQuery.of(context).size.height * 0.20
: MediaQuery.of(context).size.width * 0.19,
floating: true,
backgroundColor: Colors.transparent,
flexibleSpace: FlexibleSpaceBar(
background: Column(
children: <Widget>[
Container(
color: Colors.transparent,
padding: EdgeInsets.symmetric(
horizontal: 16.0, vertical: 0.0),
child: Calendar(
isExpandable: false,
showTodayAction: false,
showCalendarPickerIcon: true,
showChevronsToChangeRange: true,
onDateSelected: (DateTime datetime) {
dateTime = datetime;
_getBusTimeTables();
FA.logAction('date_select', 'click');
},
initialCalendarDateOverride: dateTime,
dayChildAspectRatio:
orientation == Orientation.portrait ? 1.5 : 3,
weekdays: app.weekdays,
),
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: Divider(color: Colors.grey),
),
],
Container(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: Divider(color: Colors.grey),
),
],
),
),
),
),
];
},
body: Column(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: double.infinity),
child: CupertinoSegmentedControl(
selectedColor: Resource.Colors.blueAccent,
borderColor: Resource.Colors.blueAccent,
unselectedColor: Resource.Colors.segmentControlUnSelect,
groupValue: selectStartStation,
children: {
Station.janGong: Container(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Text(app.fromJiangong),
),
Station.yanchao: Container(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Text(app.fromYanchao),
)
},
onValueChanged: (Station text) {
if (mounted) {
setState(() {
selectStartStation = text;
});
}
FA.logAction('segment', 'click');
},
];
},
body: Column(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: double.infinity),
child: CupertinoSegmentedControl(
selectedColor: Resource.Colors.blueAccent,
borderColor: Resource.Colors.blueAccent,
unselectedColor: Resource.Colors.segmentControlUnSelect,
groupValue: selectStartStation,
children: {
Station.janGong: Container(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Text(app.fromJiangong),
),
Station.yanchao: Container(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Text(app.fromYanchao),
)
},
onValueChanged: (Station text) {
if (mounted) {
setState(() {
selectStartStation = text;
});
}
FA.logAction('segment', 'click');
},
),
),
),
),
Expanded(
child: _body(),
),
],
),
);
}),
Expanded(
child: _body(),
),
],
),
);
},
),
);
}

Expand All @@ -147,21 +158,38 @@ class BusReservePageState extends State<BusReservePage>
fontSize: 18.0,
decorationColor: Colors.grey);

String get errorText {
switch (state) {
case _State.error:
return app.clickToRetry;
case _State.empty:
return app.busEmpty;
case _State.campusNotSupport:
return app.campusNotSupport;
case _State.userNotSupport:
return app.userNotSupport;
default:
return '';
}
}

Widget _body() {
switch (state) {
case _State.loading:
return Container(
child: CircularProgressIndicator(), alignment: Alignment.center);
case _State.error:
case _State.empty:
case _State.campusNotSupport:
case _State.userNotSupport:
return FlatButton(
onPressed: () {
_getBusTimeTables();
FA.logAction('retry', 'click');
},
child: HintContent(
icon: AppIcon.assignment,
content: state == _State.error ? app.clickToRetry : app.busEmpty,
content: errorText,
),
);
case _State.offline:
Expand Down Expand Up @@ -366,12 +394,20 @@ class BusReservePageState extends State<BusReservePage>
switch (e.type) {
case DioErrorType.RESPONSE:
if (e.response.statusCode == 401) {
setState(() {
state = _State.userNotSupport;
});
} else if (e.response.statusCode == 403) {
setState(() {
state = _State.campusNotSupport;
});
} else {
setState(() {
state = _State.error;
});
} else
Utils.handleResponseError(
context, 'getBusTimeTables', mounted, e);
}
break;
case DioErrorType.DEFAULT:
if (e.message.contains("HttpException")) {
Expand Down
Loading

0 comments on commit c469378

Please sign in to comment.