Skip to content

Commit

Permalink
feat: centralized package lint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
abc873693 committed Oct 13, 2024
1 parent b5e63d9 commit c2b8ad8
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion packages/ap_common/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 0 additions & 45 deletions packages/ap_common_core/analysis_options.yaml

This file was deleted.

1 change: 0 additions & 1 deletion packages/ap_common_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions packages/ap_common_firebase/lib/apcommonfirebase.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library apcommonfirebase;

/// A Calculator.
class Calculator {
/// Returns [value] plus 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> setCurrentScreen(
String screenName,
String screenClassOverride,
Expand All @@ -37,11 +38,13 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil {
);
}

@override
Future<void> setUserId(String id) async {
await analytics?.setUserId(id: id);
debugPrint('setUserId succeeded');
}

@override
Future<void> setUserProperty(
String name,
String? value,
Expand All @@ -53,6 +56,7 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil {
debugPrint('setUserProperty $name succeeded');
}

@override
Future<void> logEvent(
String name, {
Map<String, dynamic>? parameters,
Expand All @@ -63,6 +67,7 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil {
);
}

@override
Future<void> logUserInfo(UserInfo? userInfo) async {
if (userInfo == null) return;
if (userInfo.department != null && userInfo.department!.isNotEmpty) {
Expand Down Expand Up @@ -93,8 +98,12 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil {
debugPrint('logUserInfo succeeded');
}

Future<void> logApiEvent(String type, int status,
{String message = ''}) async {
@override
Future<void> logApiEvent(
String type,
int status, {
String message = '',
}) async {
await analytics?.logEvent(
name: 'ap_api',
parameters: <String, dynamic>{
Expand All @@ -116,6 +125,7 @@ class FirebaseAnalyticsUtils extends AnalyticsUtil {
debugPrint('log CalculateUnits succeeded');
}

@override
Future<void> logTimeEvent(String name, double seconds) async {
await analytics?.logEvent(
name: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ 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();
}

static bool get isSupported =>
!kIsWeb && (Platform.isAndroid || Platform.isIOS || Platform.isMacOS);

FirebaseCrashlyticsUtils() {
if (isSupported) crashlytics = FirebaseCrashlytics.instance;
}

FirebaseCrashlytics? crashlytics;

@override
Expand All @@ -31,13 +32,13 @@ class FirebaseCrashlyticsUtils extends CrashlyticsUtil {

@override
Future<void> recordError(
exception,
dynamic exception,
StackTrace stack, {
reason,
dynamic reason,
Iterable<Object>? information,
bool? printDetails,
}) async {
information ??= const [];
information ??= const <Object>[];
await crashlytics?.recordError(
exception,
stack,
Expand Down
53 changes: 23 additions & 30 deletions packages/ap_common_firebase/lib/utils/firebase_message_utils.dart
Original file line number Diff line number Diff line change
@@ -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<bool> isBrowserSupported() async {
return FirebaseMessaging.instance.isSupported();
}

FirebaseMessagingUtils() {
if (isSupported) {
messaging = FirebaseMessaging.instance;
}
}

FirebaseMessaging? messaging;

Future<void> init({
Expand All @@ -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 ?? '',
Expand All @@ -63,34 +64,26 @@ class FirebaseMessagingUtils {
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
debugPrint("onMessageOpenedApp: $message");
debugPrint('onMessageOpenedApp: $message');
await navigateToItemDetail(
message,
onClick,
customOnClickAction,
);
});
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(
Expand All @@ -106,12 +99,12 @@ class FirebaseMessagingUtils {
Function(RemoteMessage)? onClick,
bool customOnClickAction,
) async {
final data = message.data;
final Map<String, dynamic> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit c2b8ad8

Please sign in to comment.