diff --git a/packages/ap_common/analysis_options.yaml b/analysis_options.yaml similarity index 86% rename from packages/ap_common/analysis_options.yaml rename to analysis_options.yaml index a369171a..5ff32c2b 100644 --- a/packages/ap_common/analysis_options.yaml +++ b/analysis_options.yaml @@ -3,15 +3,14 @@ include: package:lint/strict.yaml analyzer: exclude: # l10n generated code - - lib/l10n/intl/*.dart - - lib/l10n/l10n.dart - - example/lib/l10n/intl/*.dart - - example/lib/l10n/l10n.dart + - packages/ap_common/lib/l10n/intl/*.dart + - packages/ap_common/lib/l10n/l10n.dart + - apps/example/lib/l10n/intl/*.dart + - apps/example/lib/l10n/l10n.dart # example # - example/** # other generated files - - lib/models/*.g.dart - - lib/**/*.g.dart + - '**/*.g.dart' linter: rules: diff --git a/packages/ap_common/pubspec.yaml b/packages/ap_common/pubspec.yaml index 37beb536..8223cedf 100644 --- a/packages/ap_common/pubspec.yaml +++ b/packages/ap_common/pubspec.yaml @@ -61,7 +61,6 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - lint: ^2.1.2 build_runner: ^2.0.3 json_serializable: ^6.3.0 spider: ^4.2.2 diff --git a/packages/ap_common_core/analysis_options.yaml b/packages/ap_common_core/analysis_options.yaml deleted file mode 100644 index 8a312e70..00000000 --- a/packages/ap_common_core/analysis_options.yaml +++ /dev/null @@ -1,45 +0,0 @@ -include: package:lint/strict.yaml - -analyzer: - exclude: - # generated files - - lib/src/models/*.g.dart - - lib/src/**/*.g.dart - -linter: - rules: - # ------ Disable individual rules ----- # - # --- # - # Turn off what you don't like. # - # ------------------------------------- # - - # Use parameter order as in json response - always_put_required_named_parameters_first: false - - # Util classes are awesome! - avoid_classes_with_only_static_members: false - - - # ------ Enable individual rules ------ # - # --- # - # These rules here are good but too # - # opinionated to enable them by default # - # ------------------------------------- # - - # Make constructors the first thing in every class - sort_constructors_first: true - - # The new tabs vs. spaces. Choose wisely - prefer_single_quotes: true - prefer_double_quotes: false - - # Good packages document everything - public_member_api_docs: false - - # Blindly follow the Flutter code style, which prefers types everywhere - always_specify_types: true - - # Back to the 80s - lines_longer_than_80_chars: false - - sort_pub_dependencies: false \ No newline at end of file diff --git a/packages/ap_common_core/pubspec.yaml b/packages/ap_common_core/pubspec.yaml index c48d8b61..92605d23 100644 --- a/packages/ap_common_core/pubspec.yaml +++ b/packages/ap_common_core/pubspec.yaml @@ -20,6 +20,5 @@ dependencies: injector: ^4.0.0 dev_dependencies: - lint: ^2.1.2 build_runner: ^2.0.3 json_serializable: ^6.3.0 \ No newline at end of file diff --git a/packages/ap_common_firebase/lib/apcommonfirebase.dart b/packages/ap_common_firebase/lib/apcommonfirebase.dart index 96f7c23e..298576d8 100644 --- a/packages/ap_common_firebase/lib/apcommonfirebase.dart +++ b/packages/ap_common_firebase/lib/apcommonfirebase.dart @@ -1,5 +1,3 @@ -library apcommonfirebase; - /// A Calculator. class Calculator { /// Returns [value] plus 1. diff --git a/packages/ap_common_firebase/lib/utils/firebase_analytics_utils.dart b/packages/ap_common_firebase/lib/utils/firebase_analytics_utils.dart index dbfd7829..8722c4bc 100644 --- a/packages/ap_common_firebase/lib/utils/firebase_analytics_utils.dart +++ b/packages/ap_common_firebase/lib/utils/firebase_analytics_utils.dart @@ -3,30 +3,31 @@ import 'dart:io'; import 'package:ap_common/resources/ap_theme.dart'; import 'package:ap_common_core/ap_common_core.dart'; +import 'package:ap_common_firebase/utils/firebase_utils.dart'; import 'package:firebase_analytics/firebase_analytics.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'firebase_utils.dart'; - export 'package:firebase_analytics/firebase_analytics.dart'; class FirebaseAnalyticsUtils extends AnalyticsUtil { + FirebaseAnalyticsUtils() { + if (isSupported) analytics = FirebaseAnalytics.instance; + } + static FirebaseAnalyticsUtils? _instance; static bool get isSupported => - (kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS); + kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS; + //ignore: prefer_constructors_over_static_methods static FirebaseAnalyticsUtils get instance { return _instance ??= FirebaseAnalyticsUtils(); } - FirebaseAnalyticsUtils() { - if (isSupported) analytics = FirebaseAnalytics.instance; - } - FirebaseAnalytics? analytics; + @override Future setCurrentScreen( String screenName, String screenClassOverride, @@ -37,11 +38,13 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil { ); } + @override Future setUserId(String id) async { await analytics?.setUserId(id: id); debugPrint('setUserId succeeded'); } + @override Future setUserProperty( String name, String? value, @@ -53,6 +56,7 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil { debugPrint('setUserProperty $name succeeded'); } + @override Future logEvent( String name, { Map? parameters, @@ -63,6 +67,7 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil { ); } + @override Future logUserInfo(UserInfo? userInfo) async { if (userInfo == null) return; if (userInfo.department != null && userInfo.department!.isNotEmpty) { @@ -93,8 +98,12 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil { debugPrint('logUserInfo succeeded'); } - Future logApiEvent(String type, int status, - {String message = ''}) async { + @override + Future logApiEvent( + String type, + int status, { + String message = '', + }) async { await analytics?.logEvent( name: 'ap_api', parameters: { @@ -116,6 +125,7 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil { debugPrint('log CalculateUnits succeeded'); } + @override Future logTimeEvent(String name, double seconds) async { await analytics?.logEvent( name: name, diff --git a/packages/ap_common_firebase/lib/utils/firebase_crashlytics_utils.dart b/packages/ap_common_firebase/lib/utils/firebase_crashlytics_utils.dart index 88193ad2..aa0d6f14 100644 --- a/packages/ap_common_firebase/lib/utils/firebase_crashlytics_utils.dart +++ b/packages/ap_common_firebase/lib/utils/firebase_crashlytics_utils.dart @@ -9,8 +9,13 @@ import 'package:flutter/foundation.dart'; export 'package:firebase_crashlytics/firebase_crashlytics.dart'; class FirebaseCrashlyticsUtils extends CrashlyticsUtil { + FirebaseCrashlyticsUtils() { + if (isSupported) crashlytics = FirebaseCrashlytics.instance; + } + static FirebaseCrashlyticsUtils? _instance; + //ignore: prefer_constructors_over_static_methods static FirebaseCrashlyticsUtils get instance { return _instance ??= FirebaseCrashlyticsUtils(); } @@ -18,10 +23,6 @@ class FirebaseCrashlyticsUtils extends CrashlyticsUtil { static bool get isSupported => !kIsWeb && (Platform.isAndroid || Platform.isIOS || Platform.isMacOS); - FirebaseCrashlyticsUtils() { - if (isSupported) crashlytics = FirebaseCrashlytics.instance; - } - FirebaseCrashlytics? crashlytics; @override @@ -31,13 +32,13 @@ class FirebaseCrashlyticsUtils extends CrashlyticsUtil { @override Future recordError( - exception, + dynamic exception, StackTrace stack, { - reason, + dynamic reason, Iterable? information, bool? printDetails, }) async { - information ??= const []; + information ??= const []; await crashlytics?.recordError( exception, stack, diff --git a/packages/ap_common_firebase/lib/utils/firebase_message_utils.dart b/packages/ap_common_firebase/lib/utils/firebase_message_utils.dart index e7251e2c..bacffd7b 100644 --- a/packages/ap_common_firebase/lib/utils/firebase_message_utils.dart +++ b/packages/ap_common_firebase/lib/utils/firebase_message_utils.dart @@ -1,38 +1,39 @@ +import 'dart:developer'; import 'dart:io'; import 'package:ap_common_core/ap_common_core.dart'; +import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart'; import 'package:ap_common_firebase/utils/firebase_utils.dart'; import 'package:flutter/foundation.dart'; import 'package:url_launcher/url_launcher.dart'; -import 'firebase_analytics_utils.dart'; - export 'package:firebase_messaging/firebase_messaging.dart'; -const NOTIFY_ID = 9919; -const NOTIFY_ANDROID_CHANNEL_ID = '1000'; -const androidChannelDescription = 'FCM'; +const int notifyId = 9919; +const String notifyAndroidChannelId = '1000'; +const String androidChannelDescription = 'FCM'; class FirebaseMessagingUtils { + FirebaseMessagingUtils() { + if (isSupported) { + messaging = FirebaseMessaging.instance; + } + } + static FirebaseMessagingUtils? _instance; + //ignore: prefer_constructors_over_static_methods static FirebaseMessagingUtils get instance { return _instance ??= FirebaseMessagingUtils(); } static bool get isSupported => - (kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS); + kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS; Future isBrowserSupported() async { return FirebaseMessaging.instance.isSupported(); } - FirebaseMessagingUtils() { - if (isSupported) { - messaging = FirebaseMessaging.instance; - } - } - FirebaseMessaging? messaging; Future init({ @@ -45,10 +46,10 @@ class FirebaseMessagingUtils { } FirebaseMessaging.onMessage.listen((RemoteMessage message) async { if (message.notification != null) { - debugPrint("onMessage: $message"); + debugPrint('onMessage: $message'); NotificationUtil.instance.show( - id: NOTIFY_ID, - androidChannelId: NOTIFY_ANDROID_CHANNEL_ID, + id: notifyId, + androidChannelId: notifyAndroidChannelId, androidChannelDescription: androidChannelDescription, title: message.notification!.title ?? '', content: message.notification!.body ?? '', @@ -63,7 +64,7 @@ class FirebaseMessagingUtils { } }); FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async { - debugPrint("onMessageOpenedApp: $message"); + debugPrint('onMessageOpenedApp: $message'); await navigateToItemDetail( message, onClick, @@ -71,26 +72,18 @@ class FirebaseMessagingUtils { ); }); FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async { - debugPrint("onBackgroundMessage: $message"); + debugPrint('onBackgroundMessage: $message'); await navigateToItemDetail( message, onClick, customOnClickAction, ); }); - final value = await messaging?.requestPermission( - alert: true, - announcement: false, - badge: true, - carPlay: false, - criticalAlert: false, - provisional: false, - sound: true, - ); + final NotificationSettings? value = await messaging?.requestPermission(); if (value?.authorizationStatus == AuthorizationStatus.authorized) { messaging?.getToken(vapidKey: vapidKey).then((String? token) { if (token != null && kDebugMode) { - print("Push Messaging token: $token"); + log('Push Messaging token: $token', name: 'firebase'); } }); FirebaseAnalyticsUtils.instance.setUserProperty( @@ -106,12 +99,12 @@ class FirebaseMessagingUtils { Function(RemoteMessage)? onClick, bool customOnClickAction, ) async { - final data = message.data; + final Map data = message.data; if (customOnClickAction) { onClick?.call(message); - } else if (data['type'] == "1") { + } else if (data['type'] == '1') { launchUrl( - Uri.parse(data['url']), + Uri.parse(data['url'] as String), ); } else { onClick?.call(message); diff --git a/packages/ap_common_firebase/lib/utils/firebase_performance_utils.dart b/packages/ap_common_firebase/lib/utils/firebase_performance_utils.dart index 0a312ad0..be236c1e 100644 --- a/packages/ap_common_firebase/lib/utils/firebase_performance_utils.dart +++ b/packages/ap_common_firebase/lib/utils/firebase_performance_utils.dart @@ -6,20 +6,19 @@ import 'package:flutter/foundation.dart'; export 'package:firebase_performance/firebase_performance.dart'; class FirebasePerformancesUtils { + FirebasePerformancesUtils() { + if (isSupported) { + performance = FirebasePerformance.instance; + } + } static FirebasePerformancesUtils? _instance; + //ignore: prefer_constructors_over_static_methods static FirebasePerformancesUtils get instance { return _instance ??= FirebasePerformancesUtils(); } - static bool get isSupported => - kIsWeb || Platform.isAndroid || Platform.isIOS; - - FirebasePerformancesUtils() { - if (isSupported) { - performance = FirebasePerformance.instance; - } - } + static bool get isSupported => kIsWeb || Platform.isAndroid || Platform.isIOS; FirebasePerformance? performance; diff --git a/packages/ap_common_firebase/lib/utils/firebase_remote_config_utils.dart b/packages/ap_common_firebase/lib/utils/firebase_remote_config_utils.dart index 1204506d..996732c9 100644 --- a/packages/ap_common_firebase/lib/utils/firebase_remote_config_utils.dart +++ b/packages/ap_common_firebase/lib/utils/firebase_remote_config_utils.dart @@ -7,20 +7,20 @@ import 'package:flutter/foundation.dart'; export 'package:firebase_remote_config/firebase_remote_config.dart'; class FirebaseRemoteConfigUtils { + FirebaseRemoteConfigUtils() { + if (isSupported) remoteConfig = FirebaseRemoteConfig.instance; + } static FirebaseRemoteConfigUtils? _instance; + //ignore: prefer_constructors_over_static_methods static FirebaseRemoteConfigUtils get instance { return _instance ??= FirebaseRemoteConfigUtils(); } - FirebaseRemoteConfigUtils() { - if (isSupported) remoteConfig = FirebaseRemoteConfig.instance; - } - FirebaseRemoteConfig? remoteConfig; static bool get isSupported => - (kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS); + kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS; } extension RemoteConfigExtension on FirebaseRemoteConfig { diff --git a/packages/ap_common_firebase/lib/utils/firebase_utils.dart b/packages/ap_common_firebase/lib/utils/firebase_utils.dart index 37483f5f..4bf34837 100644 --- a/packages/ap_common_firebase/lib/utils/firebase_utils.dart +++ b/packages/ap_common_firebase/lib/utils/firebase_utils.dart @@ -3,10 +3,9 @@ import 'dart:io'; import 'package:ap_common_core/ap_common_core.dart'; import 'package:ap_common_firebase/utils/firebase_analytics_utils.dart'; import 'package:ap_common_firebase/utils/firebase_crashlytics_utils.dart'; +import 'package:ap_common_firebase/utils/firebase_performance_utils.dart'; import 'package:flutter/foundation.dart'; -import 'firebase_performance_utils.dart'; - export 'package:firebase_analytics/firebase_analytics.dart'; export 'package:firebase_core/firebase_core.dart'; export 'package:firebase_crashlytics/firebase_crashlytics.dart'; @@ -14,8 +13,9 @@ export 'package:firebase_messaging/firebase_messaging.dart'; class FirebaseUtils { static FirebaseAnalytics? init() { - if (FirebaseCrashlyticsUtils.isSupported) + if (FirebaseCrashlyticsUtils.isSupported) { CrashlyticsUtil.instance = FirebaseCrashlyticsUtils.instance; + } if (FirebaseAnalyticsUtils.isSupported) { AnalyticsUtil.instance = FirebaseAnalyticsUtils.instance; return FirebaseAnalyticsUtils.instance.analytics; @@ -25,5 +25,5 @@ class FirebaseUtils { } static bool get isSupportCore => - (kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS); + kIsWeb || Platform.isAndroid || Platform.isIOS || Platform.isMacOS; } diff --git a/packages/ap_common_plugin/lib/ap_common_plugin.dart b/packages/ap_common_plugin/lib/ap_common_plugin.dart index 5ce57925..d998c2d7 100644 --- a/packages/ap_common_plugin/lib/ap_common_plugin.dart +++ b/packages/ap_common_plugin/lib/ap_common_plugin.dart @@ -3,8 +3,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; class ApCommonPlugin { - static const MethodChannel _channel = - const MethodChannel('ap_common_plugin'); + static const MethodChannel _channel = MethodChannel('ap_common_plugin'); static Future get platformVersion async { final String? version = await _channel.invokeMethod('getPlatformVersion'); diff --git a/pubspec.lock b/pubspec.lock index 0b8071b4..b5f59132 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -145,6 +145,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.9.0" + lint: + dependency: "direct dev" + description: + name: lint + sha256: d758a5211fce7fd3f5e316f804daefecdc34c7e53559716125e6da7388ae8565 + url: "https://pub.dev" + source: hosted + version: "2.3.0" matcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 00fd81cb..d622fa04 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,4 +5,5 @@ environment: flutter: ">=3.24.0 <4.0.0" dev_dependencies: - melos: ^6.1.0 \ No newline at end of file + melos: ^6.1.0 + lint: ^2.1.2 \ No newline at end of file