Skip to content

Commit

Permalink
Update: Lints
Browse files Browse the repository at this point in the history
  • Loading branch information
AmosHuKe committed Jun 8, 2024
1 parent 847d217 commit 0e8f507
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 102 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Windows:

macOS:
```
[✓] Flutter (Channel stable, 3.22.0, on macOS 14.4.1 23E224 darwin-x64, locale zh-Hans-CN)
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.4.1 23E224 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Android Studio (version 2023.3)
Expand Down
32 changes: 31 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ includes: package:flutter_lints/flutter.yaml

analyzer:
exclude: [lib/l10n/gen/**]
errors:
always_declare_return_types: error
avoid_renaming_method_parameters: error
avoid_void_async: error
camel_case_types: error
constant_identifier_names: error
deprecated_member_use_from_same_package: ignore
non_constant_identifier_names: error
prefer_single_quotes: warning
require_trailing_commas: warning
todo: ignore

linter:
rules:
rules:
always_declare_return_types: true
avoid_renaming_method_parameters: true
avoid_unnecessary_containers: true
avoid_void_async: true
curly_braces_in_flow_control_structures: true
library_annotations: false
prefer_const_constructors: true
prefer_const_constructors_in_immutables: false
prefer_final_fields: true
prefer_final_in_for_each: true
prefer_final_locals: true
prefer_single_quotes: true
require_trailing_commas: true
sort_constructors_first: true
sort_unnamed_constructors_first: true
unnecessary_await_in_return: true
unnecessary_breaks: true
unnecessary_late: true
unnecessary_parenthesis: true
25 changes: 17 additions & 8 deletions lib/common/local_auth_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ class LocalAuthUtils {
/// 识别图标
IconData? localAuthIcon(List<BiometricType> localAuthList) {
IconData? authIcon;
if (localAuthList.contains(BiometricType.weak))
if (localAuthList.contains(BiometricType.weak)) {
authIcon = Remix.body_scan_line;
if (localAuthList.contains(BiometricType.iris)) authIcon = Remix.eye_line;
if (localAuthList.contains(BiometricType.face))
}
if (localAuthList.contains(BiometricType.iris)) {
authIcon = Remix.eye_line;
}
if (localAuthList.contains(BiometricType.face)) {
authIcon = Remix.body_scan_line;
if (localAuthList.contains(BiometricType.fingerprint))
}
if (localAuthList.contains(BiometricType.fingerprint)) {
authIcon = Remix.fingerprint_line;
}
return authIcon;
}

Expand All @@ -95,14 +100,18 @@ class LocalAuthUtils {
List<BiometricType> localAuthList,
) {
String authText = '';
if (localAuthList.contains(BiometricType.weak))
if (localAuthList.contains(BiometricType.weak)) {
authText = S.of(context).app_setting_security_biometric_weak;
if (localAuthList.contains(BiometricType.iris))
}
if (localAuthList.contains(BiometricType.iris)) {
authText = S.of(context).app_setting_security_biometric_iris;
if (localAuthList.contains(BiometricType.face))
}
if (localAuthList.contains(BiometricType.face)) {
authText = S.of(context).app_setting_security_biometric_face;
if (localAuthList.contains(BiometricType.fingerprint))
}
if (localAuthList.contains(BiometricType.fingerprint)) {
authText = S.of(context).app_setting_security_biometric_fingerprint;
}
return authText;
}
}
4 changes: 2 additions & 2 deletions lib/db/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DB {
Future close() async => _db?.close();

/// 创建
void _onCreate(Database db, int newVersion) async {
Future<void> _onCreate(Database db, int newVersion) async {
print('_onCreate 新版本:$newVersion');
final batch = db.batch();

Expand All @@ -52,7 +52,7 @@ class DB {
}

/// 升级
void _onUpgrade(Database db, int oldVersion, int newVersion) async {
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
print('_onUpgrade 旧版本:$oldVersion');
print('_onUpgrade 新版本:$newVersion');

Expand Down
10 changes: 5 additions & 5 deletions lib/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _InitState extends State<Init> {
}

/// 应用初始化
void init() async {
Future<void> init() async {
final MoodProvider moodProvider = context.read<MoodProvider>();
final ApplicationProvider applicationProvider =
context.read<ApplicationProvider>();
Expand Down Expand Up @@ -110,13 +110,13 @@ class _InitState extends State<Init> {
}

/// 锁屏
void runLockScreen() async {
Future<void> runLockScreen() async {
if (!mounted) return;
lockScreen(context);
}

/// 通知权限判断显示
void allowedNotification() async {
Future<void> allowedNotification() async {
bool isAllowed = await AwesomeNotifications().isNotificationAllowed();
if (!isAllowed) {
if (!mounted) return;
Expand All @@ -125,7 +125,7 @@ class _InitState extends State<Init> {
}

/// 发送普通通知
void sendNotification() async {
Future<void> sendNotification() async {
final bool isAllowed = await AwesomeNotifications().isNotificationAllowed();
if (!isAllowed) return;
if (!mounted) return;
Expand All @@ -142,7 +142,7 @@ class _InitState extends State<Init> {
}

/// 发送定时计划通知
void sendScheduleNotification() async {
Future<void> sendScheduleNotification() async {
final String localTimeZone =
await AwesomeNotifications().getLocalTimeZoneIdentifier();
final bool isAllowed = await AwesomeNotifications().isNotificationAllowed();
Expand Down
12 changes: 6 additions & 6 deletions lib/providers/application/application_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ApplicationProvider extends ChangeNotifier {
bool _keyBiometric = false;

/// 获取-主题模式
void loadThemeMode() async {
Future<void> loadThemeMode() async {
_themeMode = await PreferencesDB.db.getAppThemeDarkMode();
notifyListeners();
}
Expand All @@ -39,7 +39,7 @@ class ApplicationProvider extends ChangeNotifier {
}

/// 获取-多主题模式
void loadMultipleThemesMode() async {
Future<void> loadMultipleThemesMode() async {
_multipleThemesMode = await PreferencesDB.db.getMultipleThemesMode();
notifyListeners();
}
Expand All @@ -52,7 +52,7 @@ class ApplicationProvider extends ChangeNotifier {
}

/// 获取-语言是否跟随系统
void loadLocaleSystem() async {
Future<void> loadLocaleSystem() async {
_localeSystem = await PreferencesDB.db.getAppIsLocaleSystem();
notifyListeners();
}
Expand All @@ -65,7 +65,7 @@ class ApplicationProvider extends ChangeNotifier {
}

/// 获取-语言
void loadLocale() async {
Future<void> loadLocale() async {
_locale = await PreferencesDB.db.getAppLocale();
notifyListeners();
}
Expand All @@ -79,7 +79,7 @@ class ApplicationProvider extends ChangeNotifier {
}

/// 获取-安全-密码内容
void loadKeyPassword() async {
Future<void> loadKeyPassword() async {
_keyPassword = await PreferencesDB.db.getAppKeyPassword();
notifyListeners();
}
Expand All @@ -92,7 +92,7 @@ class ApplicationProvider extends ChangeNotifier {
}

/// 获取-安全-生物特征识别是否开启
void loadKeyBiometric() async {
Future<void> loadKeyBiometric() async {
_keyBiometric = await PreferencesDB.db.getAppKeyBiometric();
notifyListeners();
}
Expand Down
14 changes: 7 additions & 7 deletions lib/providers/mood/mood_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MoodProvider extends ChangeNotifier {
}

/// 获取所有心情类别数据列表
void loadMoodCategoryAllList() async {
Future<void> loadMoodCategoryAllList() async {
/// 设置心情类别默认值
final bool setMoodCategoryDefaultresult =
await MoodProvider.setMoodCategoryDefault();
Expand All @@ -53,35 +53,35 @@ class MoodProvider extends ChangeNotifier {
}

/// 根据日期获取详细数据列表
void loadMoodDataList(String datetime) async {
Future<void> loadMoodDataList(String datetime) async {
_moodDataLoading = true;
notifyListeners();
moodDataList = await MoodService.getMoodData(datetime);
}

/// 所有心情详细数据列表
void loadMoodDataAllList() async {
Future<void> loadMoodDataAllList() async {
moodAllDataList = await MoodService.getMoodAllData();
}

/// 获取所有记录心情的日期
void loadMoodRecordDateAllList() async {
Future<void> loadMoodRecordDateAllList() async {
moodRecordDate = await MoodService.getMoodRecordDate();
}

/// 添加心情详细数据
Future<bool> addMoodData(MoodData moodData) async {
return await MoodService.addMoodData(moodData);
return MoodService.addMoodData(moodData);
}

/// 修改心情详细数据
Future<bool> editMoodData(MoodData moodData) async {
return await MoodService.editMood(moodData);
return MoodService.editMood(moodData);
}

/// 删除心情详细数据
Future<bool> deleteMoodData(MoodData moodData) async {
return await MoodService.delMood(moodData);
return MoodService.delMood(moodData);
}

/// 赋值心情数据列表
Expand Down
10 changes: 5 additions & 5 deletions lib/providers/statistic/statistic_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ class StatisticProvider extends ChangeNotifier {
List<StatisticDateMoodCountData> _dateMoodCount = [];

/// 获取APP累计使用天数
void loadDaysCount() async {
Future<void> loadDaysCount() async {
daysCount = await StatisticService.getAPPUsageDays();
}

/// 获取APP累计记录条数
void loadMoodCount() async {
Future<void> loadMoodCount() async {
moodCount = await StatisticService.getAPPMoodCount();
}

/// 获取平均情绪波动
void loadMoodScoreAverage() async {
Future<void> loadMoodScoreAverage() async {
moodScoreAverage = await StatisticService.getMoodScoreAverage();
}

/// 获取近日情绪波动
void loadMoodScoreAverageRecently({int days = 7}) async {
Future<void> loadMoodScoreAverageRecently({int days = 7}) async {
moodScoreAverageRecently =
await StatisticService.getMoodScoreAverageRecently(days: days);
}

/// 获取近日心情数量统计
void loadDateMoodCount({int days = 7}) async {
Future<void> loadDateMoodCount({int days = 7}) async {
dateMoodCount = await StatisticService.getDateMoodCount(days: days);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Routes {
);
static final Handler _moodContentHandle = Handler(
handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
final MoodData moodData = moodDataFromJson((params['moodData'][0]));
final MoodData moodData = moodDataFromJson(params['moodData'][0]);
return MoodContent(moodData: moodData);
},
);
Expand Down
2 changes: 1 addition & 1 deletion lib/services/mood/mood_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MoodService {
/// 设置心情类别默认值
static Future<void> setCategoryDefault() async {
/// 默认值
final List<MoodCategoryData> moodCategoryData = [
const List<MoodCategoryData> moodCategoryData = [
MoodCategoryData(icon: '😊', title: '开心'),
MoodCategoryData(icon: '🎉', title: '惊喜'),
MoodCategoryData(icon: '🤡', title: '滑稽'),
Expand Down
2 changes: 1 addition & 1 deletion lib/services/statistic/statistic_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StatisticService {
final List<StatisticMoodScoreAverageRecentlyData> dataList = [];
final nowDate = DateTime.parse(getDatetimeNow('yyyy-MM-dd'));
// 获取近日日期
for (int i = (days - 1); i >= 0; i--) {
for (int i = days - 1; i >= 0; i--) {
final String date =
DateFormat('yyyy-MM-dd').format(nowDate.subtract(Duration(days: i)));
// 查询
Expand Down
Loading

0 comments on commit 0e8f507

Please sign in to comment.