Skip to content

Commit

Permalink
Merge pull request #327 from DanXi-Dev/fix-326
Browse files Browse the repository at this point in the history
Fix #326
  • Loading branch information
w568w authored Jan 3, 2024
2 parents 9546593 + 18d0ab0 commit 5ac1574
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 135 deletions.
135 changes: 66 additions & 69 deletions lib/page/danke/course_group_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ class CourseGroupDetailState extends State<CourseGroupDetail> {
GlobalKey<RefreshIndicatorState>();

CourseReview? locateReview;
Future<CourseGroup?>? _courseGroupFuture;
Future<List<CourseReview>?>? _reviewListFuture;

/// Reload/load the (new) content
List<CourseReview>? _loadContent() {
Future<List<CourseReview>?> _loadContent() async {
await _courseGroupFuture;

List<CourseReview> result = [];
for (var elem in _courseGroup!.courseList!) {
if (elem.reviewList != null) {
Expand All @@ -108,6 +112,15 @@ class CourseGroupDetailState extends State<CourseGroupDetail> {
}
}

WidgetsBinding.instance.addPostFrameCallback((_) async {
if (locateReview != null && mounted) {
// Scroll to the specific floor
await PagedListViewHelper.scrollToItem(
context, _listViewController, locateReview, ScrollDirection.DOWN);
locateReview = null;
}
});

return result;
}

Expand Down Expand Up @@ -141,7 +154,10 @@ class CourseGroupDetailState extends State<CourseGroupDetail> {

/// Refresh the whole list (excluding the head)
Future<void> refreshList({bool scrollToEnd = false}) async {
await _fetchCourseGroup(forceRefetch: true);
_courseGroupFuture = _fetchCourseGroup(forceRefetch: true);
_reviewListFuture = _loadContent();

await _courseGroupFuture;
await refreshSelf();
if (scrollToEnd) _listViewController.queueScrollToEnd();
return _listViewController.notifyUpdate(
Expand Down Expand Up @@ -196,6 +212,8 @@ class CourseGroupDetailState extends State<CourseGroupDetail> {
@override
Widget build(BuildContext context) {
_backgroundImage = SettingsProvider.getInstance().backgroundImage;
_courseGroupFuture ??= _fetchCourseGroup();
_reviewListFuture ??= _loadContent();

return PlatformScaffold(
iosContentPadding: false,
Expand Down Expand Up @@ -241,73 +259,53 @@ class CourseGroupDetailState extends State<CourseGroupDetail> {
}

Widget _buildBody(BuildContext context) {
return Builder(
// The builder widget updates context so that MediaQuery below can use the correct context (that is, Scaffold considered)
builder: (context) => Container(
decoration: _backgroundImage == null
? null
: BoxDecoration(
image: DecorationImage(
image: _backgroundImage!, fit: BoxFit.cover)),
child: RefreshIndicator(
key: indicatorKey,
edgeOffset: MediaQuery.of(context).padding.top,
color: Theme.of(context).colorScheme.secondary,
backgroundColor: Theme.of(context).dialogBackgroundColor,
onRefresh: () async {
HapticFeedback.mediumImpact();
// Refresh the list...
await refreshList();
},
child: FutureWidget<CourseGroup?>(
future: _fetchCourseGroup(),
successBuilder: (context, snapshot) {
return PagedListView<CourseReview>(
pagedController: _listViewController,
withScrollbar: true,
scrollController: PrimaryScrollController.of(context),
// [_loadContent] does no internet request so it shall be quick
allDataReceiver: Future.value(_loadContent()).then((value) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (locateReview != null && mounted) {
// Scroll to the specific floor
await PagedListViewHelper.scrollToItem(
context,
_listViewController,
locateReview,
ScrollDirection.DOWN);
locateReview = null;
}
});

return value;
}),
builder: _getListItems,
headBuilder: (ctx) => _buildHead(ctx),
loadingBuilder: (BuildContext context) => Container(
padding: const EdgeInsets.all(8),
child: Center(child: PlatformCircularProgressIndicator()),
return Container(
decoration: _backgroundImage == null
? null
: BoxDecoration(
image:
DecorationImage(image: _backgroundImage!, fit: BoxFit.cover)),
child: RefreshIndicator(
key: indicatorKey,
edgeOffset: MediaQuery.of(context).padding.top,
color: Theme.of(context).colorScheme.secondary,
backgroundColor: Theme.of(context).dialogBackgroundColor,
onRefresh: () async {
HapticFeedback.mediumImpact();
// Refresh the list...
await refreshList();
},
child: FutureWidget<CourseGroup?>(
future: _courseGroupFuture,
successBuilder: (context, snapshot) {
return PagedListView<CourseReview>(
pagedController: _listViewController,
withScrollbar: true,
scrollController: PrimaryScrollController.of(context),
// [_loadContent] does no internet request so it shall be quick
allDataReceiver: _reviewListFuture,
builder: _getListItems,
headBuilder: _buildHead,
loadingBuilder: (BuildContext context) => Container(
padding: const EdgeInsets.all(8),
child: Center(child: PlatformCircularProgressIndicator()),
),
emptyBuilder: (context) =>
Center(child: Text(S.of(context).no_course_review)),
endBuilder: (context) => Center(
child: Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Text(S.of(context).end_reached),
),
emptyBuilder: (context) =>
Center(child: Text(S.of(context).no_course_review)),
endBuilder: (context) {
return Center(
child: Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Text(S.of(context).end_reached),
),
);
},
);
},
errorBuilder: (BuildContext context,
AsyncSnapshot<CourseGroup?> snapshot) =>
ErrorPageWidget.buildWidget(context, snapshot.error,
stackTrace: snapshot.stackTrace,
onTap: () => setState(() {})),
loadingBuilder:
Center(child: PlatformCircularProgressIndicator())),
),
),
);
},
errorBuilder:
(BuildContext context, AsyncSnapshot<CourseGroup?> snapshot) =>
ErrorPageWidget.buildWidget(context, snapshot.error,
stackTrace: snapshot.stackTrace,
onTap: () => setState(() {})),
loadingBuilder: Center(child: PlatformCircularProgressIndicator())),
),
);
}
Expand Down Expand Up @@ -427,7 +425,6 @@ class CourseGroupDetailState extends State<CourseGroupDetail> {
locateReview = affectedReview;
}

await _fetchCourseGroup(forceRefetch: true);
indicatorKey.currentState?.show();
},
);
Expand Down
2 changes: 1 addition & 1 deletion lib/page/danke/course_review_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ class CourseRatingWidgetState extends State<CourseRatingWidget> {
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(width: 88, child: Text(widget.label)),
Row(
Expand All @@ -598,7 +599,6 @@ class CourseRatingWidgetState extends State<CourseRatingWidget> {
index < rating ? Icons.star : Icons.star_border,
color: mainColor))),
),
const SizedBox(width: 10),
Text(rating > 0 ? widget.words[rating - 1] : "",
style: TextStyle(color: mainColor))
]));
Expand Down
109 changes: 44 additions & 65 deletions lib/widget/danke/course_review_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,72 +67,51 @@ class CourseReviewWidget extends StatelessWidget {
Expanded(
child: ListTile(
contentPadding: EdgeInsets.zero,
title: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
alignment: WrapAlignment.spaceBetween,
runSpacing: 4,
children: [
Column(
children: [
// course name, department name, course code and credits
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// use Expanded wrap the text to avoid overflow
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// todo add card information style
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 2),
child: ReviewHeader(
userId: review.reviewerId!,
teacher: review.courseInfo.teachers,
time: review.courseInfo.time,
title: review.title!,
),
),
const Divider(),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 2),
child: smartRender(context, review.content!,
null, null, translucent),
),
const Divider(),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 2),
child: Row(children: [
Expanded(
child: ReviewFooter(
overallLevel:
review.rank!.overall! - 1,
styleLevel: review.rank!.content! - 1,
workloadLevel:
review.rank!.workload! - 1,
assessmentLevel:
review.rank!.assessment! - 1,
),
),
if (review.isMe!)
ModifyMenuWidget(
originalReview: review,
courseGroup: courseGroup,
reviewOperationCallback: reviewOperationCallback ?? (rev){},
)
])),
],
),
),
],
),
],
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// todo add card information style
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
child: ReviewHeader(
userId: review.reviewerId!,
teacher: review.courseInfo.teachers,
time: review.courseInfo.time,
title: review.title!,
),
]),
),
const Divider(),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
child: smartRender(
context, review.content!, null, null, translucent),
),
const Divider(),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
child: Row(children: [
Expanded(
child: ReviewFooter(
overallLevel: review.rank!.overall! - 1,
styleLevel: review.rank!.content! - 1,
workloadLevel: review.rank!.workload! - 1,
assessmentLevel: review.rank!.assessment! - 1,
),
),
if (review.isMe!)
ModifyMenuWidget(
originalReview: review,
courseGroup: courseGroup,
reviewOperationCallback:
reviewOperationCallback ?? (rev) {},
)
])),
],
),
),
)
]),
Expand Down

0 comments on commit 5ac1574

Please sign in to comment.