Skip to content

Commit

Permalink
🎨 Update code format according to analysis options.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Feb 18, 2020
1 parent 052ec43 commit 2db1bc1
Show file tree
Hide file tree
Showing 51 changed files with 261 additions and 213 deletions.
14 changes: 14 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
# - camel_case_types

analyzer:
# exclude:
# - path/to/excluded/files/**
44 changes: 19 additions & 25 deletions lib/api/user_api.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:extended_image/extended_image.dart';
Expand All @@ -16,12 +15,12 @@ class UserAPI {

static List<Cookie> cookiesForJWGL;

static Future login(Map<String, dynamic> params) async {
return NetUtils.tokenDio.post(API.login, data: params);
static Future<Response<T>> login<T>(Map<String, dynamic> params) async {
return NetUtils.tokenDio.post<T>(API.login, data: params);
}

static void logout(context) async {
final confirm = await ConfirmationBottomSheet.show(
static Future<void> logout(BuildContext context) async {
final bool confirm = await ConfirmationBottomSheet.show(
context,
title: '退出登录',
showConfirm: true,
Expand All @@ -32,7 +31,7 @@ class UserAPI {
}
}

static UserTag createUserTag(tagData) => UserTag(
static UserTag createUserTag(Map<String, dynamic> tagData) => UserTag(
id: tagData['id'],
name: tagData['tagname'],
);
Expand Down Expand Up @@ -74,13 +73,13 @@ class UserAPI {
avatarLastModified = DateTime.now().millisecondsSinceEpoch;
}

static Future getUserInfo({int uid}) async {
static Future<dynamic> getUserInfo<T>({int uid}) async {
if (uid == null) {
return currentUser;
} else {
return NetUtils.getWithCookieAndHeaderSet(
API.userInfo,
data: {'uid': uid},
data: <String, dynamic>{'uid': uid},
);
}
}
Expand Down Expand Up @@ -124,27 +123,22 @@ class UserAPI {
static Future getNotifications() async => NetUtils.getWithCookieAndHeaderSet(API.postUnread);

static Future follow(int uid) async {
NetUtils.postWithCookieAndHeaderSet('${API.userRequestFollow}$uid').then((response) {
return NetUtils.postWithCookieAndHeaderSet(
API.userFollowAdd,
data: {'fid': uid, 'tagid': 0},
);
}).catchError((e) {
debugPrint(e.toString());
showCenterErrorToast('关注失败,${jsonDecode(e.response.data)['msg']}');
});
try {
await NetUtils.postWithCookieAndHeaderSet('${API.userRequestFollow}$uid');
await NetUtils.postWithCookieAndHeaderSet(API.userFollowAdd, data: {'fid': uid, 'tagid': 0});
} catch (e) {
debugPrint('Failed when folloe: $e');
}
}

static Future unFollow(int uid, {bool fromBlacklist = false}) async {
NetUtils.deleteWithCookieAndHeaderSet('${API.userRequestFollow}$uid').then((response) {
return NetUtils.postWithCookieAndHeaderSet(
API.userFollowDel,
data: {'fid': uid},
);
}).catchError((e) {
try {
await NetUtils.deleteWithCookieAndHeaderSet('${API.userRequestFollow}$uid');
await NetUtils.postWithCookieAndHeaderSet(API.userFollowAdd, data: {'fid': uid});
} catch (e) {
debugPrint('Failed when unfollow $uid: $e');
if (!fromBlacklist) showCenterErrorToast('取消关注失败,${e.response.data['msg']}');
});
if (!fromBlacklist) showCenterErrorToast('取消关注失败');
}
}

static Future setSignature(content) async {
Expand Down
2 changes: 2 additions & 0 deletions lib/constants/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:openjmu/constants/constants.dart';

export 'package:dartx/dartx.dart';
export 'package:dio/dio.dart' show Response;
export 'package:ff_annotation_route/ff_annotation_route.dart' show FFRoute, PageRouteType;
export 'package:oktoast/oktoast.dart' hide showToast;
export 'package:pedantic/pedantic.dart';
export 'package:url_launcher/url_launcher.dart';

export 'package:openjmu/api/api.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/constants/hive_boxes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class HiveBoxes {
changelogBox = await Hive.openBox<ChangeLog>('openjmu_changelog');
}

static void clearBoxes({context}) async {
static Future<void> clearBoxes({context}) async {
bool confirm = true;
if (context != null) {
confirm = await ConfirmationBottomSheet.show(
Expand All @@ -72,7 +72,7 @@ class HiveBoxes {
await settingsBox?.clear();
await startWeekBox?.clear();
debugPrint('Boxes cleared');
if (kReleaseMode) SystemNavigator.pop();
if (kReleaseMode) unawaited(SystemNavigator.pop());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/comment_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class CommentListInPostState extends State<CommentListInPost> with AutomaticKeep
Routes.OPENJMU_ADD_COMMENT,
arguments: {
'post': widget.post,
'comment': _comments?.elementAt(index) ?? null,
'comment': _comments?.elementAt(index),
},
);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/model/special_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class MentionText extends SpecialText {
int getUidFromContent(content) {
Iterable<Match> matches = mTagStartReg.allMatches(content);
String result;
for (Match m in matches) result = m.group(0);
for (Match m in matches) {
result = m.group(0);
}
return int.parse(result.substring(3, result.length - 1));
}

Expand Down Expand Up @@ -286,8 +288,8 @@ class StackSpecialTextSpanBuilder extends SpecialTextSpanBuilder {
final List<InlineSpan> suffixSpans;

StackSpecialTextSpanBuilder({
this.builderType: BuilderType.extendedText,
this.widgetType: WidgetType.post,
this.builderType = BuilderType.extendedText,
this.widgetType = WidgetType.post,
this.prefixSpans,
this.suffixSpans,
});
Expand Down Expand Up @@ -333,7 +335,7 @@ class StackSpecialTextSpanBuilder extends SpecialTextSpanBuilder {
if (specialText != null) {
if (textStack.length - specialText.startFlag.length >= 0) {
textStack = textStack.substring(0, textStack.length - specialText.startFlag.length);
if (textStack.length > 0) {
if (textStack.isNotEmpty) {
inlineList.add(TextSpan(text: textStack, style: textStyle));
}
}
Expand All @@ -346,7 +348,7 @@ class StackSpecialTextSpanBuilder extends SpecialTextSpanBuilder {
text: specialText.startFlag + specialText.getContent(),
style: textStyle,
));
} else if (textStack.length > 0) {
} else if (textStack.isNotEmpty) {
inlineList.add(TextSpan(text: textStack, style: textStyle));
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class User {
nickname: json['nickname'] ?? json['username'] ?? json['name'] ?? json['uid'].toString(),
gender: json['gender'] ?? 0,
topics: json['topics'] ?? 0,
latestTid: json['latest_tid'] ?? null,
latestTid: json['latest_tid'],
fans: json['fans'] ?? 0,
idols: json['idols'] ?? 0,
isFollowing: json['is_following'] == 1,
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/chat/chat_app_message_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ class _ChatAppMessagePageState extends State<ChatAppMessagePage> {
final content = jsonDecode(message.content);
message.content = content['content'];
if (mounted) setState(() {});
} catch (e) {}
} catch (e) {
return;
}
}

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/chat/chat_person_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ class _ChatPersonPageState extends State<ChatPersonPage> {
} else {
if (MediaQuery.of(context).viewInsets.bottom != 0.0) {
SystemChannels.textInput.invokeMethod('TextInput.hide').whenComplete(
() async {
Future.delayed(const Duration(milliseconds: 300), () {}).whenComplete(change);
() {
Future.delayed(300.milliseconds, () {}).whenComplete(change);
},
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/home/add_button_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class _AddingButtonPageState extends State<AddingButtonPage> with TickerProvider
final List<String> itemTitles = ['广场', '集市'];
final List<Color> itemColors = [Colors.orange, Colors.indigoAccent];
final List<Function> itemOnTap = [
(context) async {
(context) {
navigatorState.pushNamed(Routes.OPENJMU_PUBLISH_POST);
},
(context) async {
(context) {
navigatorState.pushNamed(Routes.OPENJMU_PUBLISH_TEAM_POST);
},
];
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/home/app_center_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class AppCenterPage extends StatelessWidget {
content: '是否使用浏览器打开该应用?',
showConfirm: true,
);
if (confirm) launch(webApp.replacedUrl, forceSafariVC: false);
if (confirm) {
unawaited(launch(webApp.replacedUrl, forceSafariVC: false));
}
},
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/home/course_schedule_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ class CourseSchedulePageState extends State<CourseSchedulePage> with AutomaticKe
void scrollToWeek(int week) {
currentWeek = week;
if (mounted) setState(() {});
if (weekScrollController?.hasClients ?? false)
if (weekScrollController?.hasClients ?? false) {
weekScrollController.animateTo(
math.max(0, (week - 0.5) * suSetWidth(weekSize) - Screens.width / 2),
duration: const Duration(milliseconds: 300),
curve: Curves.ease,
);
}
}

void showRemarkDetail(context) {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/home/post_square_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class PostSquareListPageState extends State<PostSquareListPage>
[PermissionGroup.camera],
);
if (permissions[PermissionGroup.camera] == PermissionStatus.granted) {
navigatorState.pushNamed(Routes.OPENJMU_SCAN_QRCODE);
unawaited(navigatorState.pushNamed(Routes.OPENJMU_SCAN_QRCODE));
}
},
);
Expand Down
11 changes: 6 additions & 5 deletions lib/pages/home/scan_qrcode_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ class _ScanQrCodePageState extends State<ScanQrCodePage> {
Future<void> onScan(context, String data) async {
if (data == null) {
showCenterErrorToast('没有识别到二维码~换一张试试');
return;
}
if (API.urlReg.stringMatch(data) != null) {
API.launchWeb(url: '$data');
unawaited(API.launchWeb(url: '$data'));
} else if (API.schemeUserPage.stringMatch(data) != null) {
Navigator.of(context).pushReplacementNamed(
unawaited(Navigator.of(context).pushReplacementNamed(
Routes.OPENJMU_USER,
arguments: {'uid': int.parse(data.substring(API.schemeUserPage.pattern.length - 2))},
);
));
} else {
final needCopy = await ConfirmationDialog.show(
context,
Expand All @@ -35,7 +34,9 @@ class _ScanQrCodePageState extends State<ScanQrCodePage> {
confirmLabel: '复制',
cancelLabel: '返回',
);
if (needCopy) Clipboard.setData(ClipboardData(text: '$data'));
if (needCopy) {
unawaited(Clipboard.setData(ClipboardData(text: '$data')));
}
_key.currentState.startScan();
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class LoginPageState extends State<LoginPage> with SingleTickerProviderStateMixi
void usernameListener() {
_username = _usernameController.text;
if (this.mounted) {
if (_usernameController.text.length > 0 && !_usernameCanClear) {
if (_usernameController.text.isNotEmpty && !_usernameCanClear) {
setState(() {
_usernameCanClear = true;
});
} else if (_usernameController.text.length == 0 && _usernameCanClear) {
} else if (_usernameController.text.isEmpty && _usernameCanClear) {
setState(() {
_usernameCanClear = false;
});
Expand Down Expand Up @@ -476,11 +476,11 @@ class LoginPageState extends State<LoginPage> with SingleTickerProviderStateMixi
showConfirm: true,
);
if (confirm) {
API.launchWeb(
unawaited(API.launchWeb(
url: 'https://net.jmu.edu.cn/info/1309/2476.htm',
title: '网页链接',
withCookie: false,
);
));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class MainPageState extends State<MainPage> with AutomaticKeepAliveClientMixin {
super.dispose();
}

void initPushService() async {
void initPushService() {
try {
final data = <String, dynamic>{
'token': DeviceUtils.devicePushToken,
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/notification/notification_entry_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _NotificationEntryPageState extends State<NotificationEntryPage>
currentContext,
listen: false,
).notifications,
'onTap': (context) async {
'onTap': (context) {
navigatorState.pushNamed(Routes.OPENJMU_NOTIFICATIONS);
},
},
Expand All @@ -39,7 +39,7 @@ class _NotificationEntryPageState extends State<NotificationEntryPage>
currentContext,
listen: false,
).teamNotifications,
'onTap': (context) async {
'onTap': (context) {
navigatorState.pushNamed(Routes.OPENJMU_TEAM_NOTIFICATIONS);
},
},
Expand Down
11 changes: 6 additions & 5 deletions lib/pages/post/post_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class PostDetailPageState extends State<PostDetailPage> {
onPressed: () => postExtraActions(context),
);

void confirmDelete(context) async {
Future<void> confirmDelete(context) async {
final confirm = await ConfirmationDialog.show(
context,
title: '删除动态',
Expand All @@ -205,14 +205,15 @@ class PostDetailPageState extends State<PostDetailPage> {
text: '正在删除动态',
isGlobal: false,
);
PostAPI.deletePost(widget.post.id).then((response) {
try {
await PostAPI.deletePost(widget.post.id);
_loadingDialogController.changeState('success', '动态删除成功');
Instances.eventBus.fire(PostDeletedEvent(widget.post.id, widget.fromPage, widget.index));
}).catchError((e) {
} catch (e) {
debugPrint(e.toString());
debugPrint(e.response?.toString());
_loadingDialogController.changeState('failed', '动态删除失败');
});
}
}
}

Expand Down Expand Up @@ -254,7 +255,7 @@ class PostDetailPageState extends State<PostDetailPage> {
final provider = Provider.of<ReportRecordsProvider>(context, listen: false);
final canReport = await provider.addRecord(widget.post.id);
if (canReport) {
PostAPI.reportPost(widget.post);
unawaited(PostAPI.reportPost(widget.post));
showToast('举报成功');
navigatorState.pop();
}
Expand Down
Loading

0 comments on commit 2db1bc1

Please sign in to comment.