Skip to content

Commit

Permalink
Merge pull request #325 from DanXi-Dev/typeahead-fix
Browse files Browse the repository at this point in the history
Fix #226 and upgrade dependencies (Fixed)
  • Loading branch information
ivanfei-1 authored Jan 3, 2024
2 parents babad14 + 5ac1574 commit d5e2cdc
Show file tree
Hide file tree
Showing 90 changed files with 660 additions and 748 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ dmg 硬盘映像,挂载拷贝即可。
## 我们当前使用的 Flutter 编译版本

```shell
Flutter 3.13.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 6c4930c4ac (9 days ago) • 2023-10-18 10:57:55 -0500
Engine • revision 767d8c75e8
Tools • Dart 3.1.4 • DevTools 2.25.0
Flutter 3.16.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b0366e0a3f (2 周前) • 2023-12-05 19:46:39 -0800
Engine • revision 54a7145303
Tools • Dart 3.2.3 • DevTools 2.28.4
```

## 编译说明
Expand Down
9 changes: 4 additions & 5 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ mount it.
## Flutter version that we're using

```shell
$ flutter --version
Flutter 3.13.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 6c4930c4ac (9 days ago) • 2023-10-18 10:57:55 -0500
Engine • revision 767d8c75e8
Tools • Dart 3.1.4 • DevTools 2.25.0
Flutter 3.16.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b0366e0a3f (2 weeks ago) • 2023-12-05 19:46:39 -0800
Engine • revision 54a7145303
Tools • Dart 3.2.3 • DevTools 2.28.4
```

## Notes on compilation
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import 'dart:async';
import 'dart:ui';

import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:bitsdojo_window_v3/bitsdojo_window_v3.dart';
import 'package:dan_xi/feature/feature_map.dart';
import 'package:dan_xi/generated/l10n.dart';
import 'package:dan_xi/page/danke/course_group_detail.dart';
Expand Down Expand Up @@ -196,7 +196,7 @@ class DanxiApp extends StatelessWidget {
CourseReviewEditorPage(arguments: arguments)
};

const DanxiApp({Key? key}) : super(key: key);
const DanxiApp({super.key});

Widget errorBuilder(FlutterErrorDetails details) => Builder(
builder: (context) =>
Expand Down
139 changes: 68 additions & 71 deletions lib/page/danke/course_group_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'package:dan_xi/util/noticing.dart';
import 'package:dan_xi/util/opentreehole/paged_listview_helper.dart';
import 'package:dan_xi/util/platform_universal.dart';
import 'package:dan_xi/util/public_extension_methods.dart';
import 'package:dan_xi/util/stream_listener.dart';
import 'package:dan_xi/widget/danke/course_review_widget.dart';
import 'package:dan_xi/widget/danke/course_widgets.dart';
import 'package:dan_xi/widget/libraries/error_page_widget.dart';
Expand All @@ -42,7 +43,6 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:dan_xi/util/stream_listener.dart';

enum FilterType { TEACHER_FILTER, TIME_FILTER }

Expand All @@ -57,7 +57,7 @@ class RefreshFilterEvent {
class CourseGroupDetail extends StatefulWidget {
final Map<String, dynamic>? arguments;

const CourseGroupDetail({Key? key, this.arguments}) : super(key: key);
const CourseGroupDetail({super.key, this.arguments});

@override
CourseGroupDetailState createState() => CourseGroupDetailState();
Expand Down 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
9 changes: 4 additions & 5 deletions lib/page/danke/course_review_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,11 @@ class CourseReviewEditorWidget extends StatefulWidget {
final CourseReviewEditorText review;

const CourseReviewEditorWidget(
{Key? key,
{super.key,
this.fullscreen = false,
required this.courseGroup,
required this.review,
this.focusContent = false})
: super(key: key);
this.focusContent = false});

final CourseGroup courseGroup;

Expand Down Expand Up @@ -580,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 @@ -599,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 All @@ -617,7 +616,7 @@ class CourseRatingWidgetState extends State<CourseRatingWidget> {
class CourseReviewEditorPage extends StatefulWidget {
final Map<String, dynamic>? arguments;

const CourseReviewEditorPage({Key? key, this.arguments}) : super(key: key);
const CourseReviewEditorPage({super.key, this.arguments});

@override
CourseReviewEditorPageState createState() => CourseReviewEditorPageState();
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/aao_notices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AAONoticesList extends StatefulWidget {
@override
AAONoticesListState createState() => AAONoticesListState();

const AAONoticesList({Key? key, this.arguments}) : super(key: key);
const AAONoticesList({super.key, this.arguments});
}

class AAONoticesListState extends State<AAONoticesList> {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/announcement_notices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AnnouncementList extends StatefulWidget {
@override
AnnouncementListState createState() => AnnouncementListState();

const AnnouncementList({Key? key, this.arguments}) : super(key: key);
const AnnouncementList({super.key, this.arguments});
}

class AnnouncementListState extends State<AnnouncementList> {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/bus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BusPage extends StatefulWidget {
@override
BusPageState createState() => BusPageState();

const BusPage({Key? key, this.arguments}) : super(key: key);
const BusPage({super.key, this.arguments});
}

class BusPageState extends State<BusPage> {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/card_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CardDetailPage extends StatefulWidget {
@override
CardDetailPageState createState() => CardDetailPageState();

const CardDetailPage({Key? key, this.arguments}) : super(key: key);
const CardDetailPage({super.key, this.arguments});
}

class CardDetailPageState extends State<CardDetailPage> {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/card_traffic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CardCrowdData extends StatefulWidget {
@override
CardCrowdDataState createState() => CardCrowdDataState();

const CardCrowdData({Key? key, this.arguments}) : super(key: key);
const CardCrowdData({super.key, this.arguments});
}

class CardCrowdDataState extends State<CardCrowdData> {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/dashboard_reorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DashboardReorderPage extends StatefulWidget {
/// 'items': A list of [LicenseItem] to display on the page
final Map<String, dynamic>? arguments;

const DashboardReorderPage({Key? key, this.arguments}) : super(key: key);
const DashboardReorderPage({super.key, this.arguments});

@override
DashboardReorderPageState createState() => DashboardReorderPageState();
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/empty_classroom_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EmptyClassroomDetailPage extends StatefulWidget {
EmptyClassroomDetailPageState createState() =>
EmptyClassroomDetailPageState();

const EmptyClassroomDetailPage({Key? key, this.arguments}) : super(key: key);
const EmptyClassroomDetailPage({super.key, this.arguments});
}

class EmptyClassroomDetailPageState extends State<EmptyClassroomDetailPage> {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/exam_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ExamList extends StatefulWidget {
@override
ExamListState createState() => ExamListState();

const ExamList({Key? key, this.arguments}) : super(key: key);
const ExamList({super.key, this.arguments});
}

class ExamListState extends State<ExamList> {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/dashboard/gpa_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GpaTablePage extends StatefulWidget {
@override
GpaTablePageState createState() => GpaTablePageState();

const GpaTablePage({Key? key, this.arguments}) : super(key: key);
const GpaTablePage({super.key, this.arguments});
}

class GpaTablePageState extends State<GpaTablePage> {
Expand Down
2 changes: 1 addition & 1 deletion lib/page/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const QuickActions quickActions = QuickActions();
/// The main page of DanXi.
/// It is a container for [PlatformSubpage].
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
const HomePage({super.key});

@override
HomePageState createState() => HomePageState();
Expand Down
2 changes: 1 addition & 1 deletion lib/page/opentreehole/hole_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ String preprocessContentForDisplay(String content) {
class BBSPostDetail extends StatefulWidget {
final Map<String, dynamic>? arguments;

const BBSPostDetail({Key? key, this.arguments}) : super(key: key);
const BBSPostDetail({super.key, this.arguments});

@override
BBSPostDetailState createState() => BBSPostDetailState();
Expand Down
Loading

0 comments on commit d5e2cdc

Please sign in to comment.