From cf1af613a5eeff52f4d09d53b33a0999920a230c Mon Sep 17 00:00:00 2001 From: Golek Date: Thu, 1 Dec 2022 11:32:09 +0700 Subject: [PATCH] feat: add monitoring --- android/app/build.gradle | 2 +- android/app/google-services.json | 134 +++++++++ ios/Runner/GoogleService-Info.plist | 36 +++ ios/firebase_app_id_file.json | 7 + lib/firebase_options.dart | 70 +++++ lib/golektruk.dart | 18 ++ lib/main.dart | 98 +++---- .../component_library/example/pubspec.lock | 264 ++++++++++++++++++ packages/monitoring/lib/monitoring.dart | 9 + 9 files changed, 575 insertions(+), 63 deletions(-) create mode 100644 android/app/google-services.json create mode 100644 ios/Runner/GoogleService-Info.plist create mode 100644 ios/firebase_app_id_file.json create mode 100644 lib/firebase_options.dart create mode 100644 lib/golektruk.dart create mode 100644 packages/component_library/example/pubspec.lock create mode 100644 packages/monitoring/lib/monitoring.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 77efff1..646c5f0 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -47,7 +47,7 @@ android { applicationId "com.golektruk.golek_flutter_new" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. - minSdkVersion flutter.minSdkVersion + minSdkVersion 19 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/android/app/google-services.json b/android/app/google-services.json new file mode 100644 index 0000000..e09a681 --- /dev/null +++ b/android/app/google-services.json @@ -0,0 +1,134 @@ +{ + "project_info": { + "project_number": "97591185685", + "project_id": "dev-talentkita-golek", + "storage_bucket": "dev-talentkita-golek.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:97591185685:android:f802b2a7a67c67388d991c", + "android_client_info": { + "package_name": "com.golektruk.dotcom" + } + }, + "oauth_client": [ + { + "client_id": "97591185685-t8vnlgqq3dnepi36b3bh51bltcpqonbp.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "com.golektruk.dotcom", + "certificate_hash": "0de3c1bdd00344c145e1f37e56a94c614b2490b4" + } + }, + { + "client_id": "97591185685-p4qccp7b4sqs6p5fmmoip1g8q2o9ek3m.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyDenqsPlc8hyhy_CRTBQolOWvEYp0QkiwU" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "97591185685-p4qccp7b4sqs6p5fmmoip1g8q2o9ek3m.apps.googleusercontent.com", + "client_type": 3 + }, + { + "client_id": "97591185685-e4r8sejq76g4osq0regtb7ngr9usndsk.apps.googleusercontent.com", + "client_type": 2, + "ios_info": { + "bundle_id": "com.example.golekFlutter" + } + } + ] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:97591185685:android:2df08f4bdc5c06e68d991c", + "android_client_info": { + "package_name": "com.golektruk.golek_flutter_new" + } + }, + "oauth_client": [ + { + "client_id": "97591185685-p4qccp7b4sqs6p5fmmoip1g8q2o9ek3m.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyDenqsPlc8hyhy_CRTBQolOWvEYp0QkiwU" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "97591185685-p4qccp7b4sqs6p5fmmoip1g8q2o9ek3m.apps.googleusercontent.com", + "client_type": 3 + }, + { + "client_id": "97591185685-e4r8sejq76g4osq0regtb7ngr9usndsk.apps.googleusercontent.com", + "client_type": 2, + "ios_info": { + "bundle_id": "com.example.golekFlutter" + } + } + ] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:97591185685:android:aef45514f1f2aa9f8d991c", + "android_client_info": { + "package_name": "com.talenta.golektruk" + } + }, + "oauth_client": [ + { + "client_id": "97591185685-jjnuop65uak1u0vag6tesjgt1sfu2i60.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "com.talenta.golektruk", + "certificate_hash": "0de3c1bdd00344c145e1f37e56a94c614b2490b4" + } + }, + { + "client_id": "97591185685-p4qccp7b4sqs6p5fmmoip1g8q2o9ek3m.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyDenqsPlc8hyhy_CRTBQolOWvEYp0QkiwU" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "97591185685-p4qccp7b4sqs6p5fmmoip1g8q2o9ek3m.apps.googleusercontent.com", + "client_type": 3 + }, + { + "client_id": "97591185685-e4r8sejq76g4osq0regtb7ngr9usndsk.apps.googleusercontent.com", + "client_type": 2, + "ios_info": { + "bundle_id": "com.example.golekFlutter" + } + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/ios/Runner/GoogleService-Info.plist b/ios/Runner/GoogleService-Info.plist new file mode 100644 index 0000000..64d6797 --- /dev/null +++ b/ios/Runner/GoogleService-Info.plist @@ -0,0 +1,36 @@ + + + + + CLIENT_ID + 97591185685-papkbvrvnsurvorfna3d2nknasidckjs.apps.googleusercontent.com + REVERSED_CLIENT_ID + com.googleusercontent.apps.97591185685-papkbvrvnsurvorfna3d2nknasidckjs + ANDROID_CLIENT_ID + 97591185685-jjnuop65uak1u0vag6tesjgt1sfu2i60.apps.googleusercontent.com + API_KEY + AIzaSyBV3djMnp6iGQJog9RK0hwnKwBdmP4ZKkA + GCM_SENDER_ID + 97591185685 + PLIST_VERSION + 1 + BUNDLE_ID + com.golektruk.golekFlutterNew + PROJECT_ID + dev-talentkita-golek + STORAGE_BUCKET + dev-talentkita-golek.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:97591185685:ios:c408a8133e24a8258d991c + + \ No newline at end of file diff --git a/ios/firebase_app_id_file.json b/ios/firebase_app_id_file.json new file mode 100644 index 0000000..8b59a4e --- /dev/null +++ b/ios/firebase_app_id_file.json @@ -0,0 +1,7 @@ +{ + "file_generated_by": "FlutterFire CLI", + "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", + "GOOGLE_APP_ID": "1:97591185685:ios:c408a8133e24a8258d991c", + "FIREBASE_PROJECT_ID": "dev-talentkita-golek", + "GCM_SENDER_ID": "97591185685" +} \ No newline at end of file diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart new file mode 100644 index 0000000..7201216 --- /dev/null +++ b/lib/firebase_options.dart @@ -0,0 +1,70 @@ +// File generated by FlutterFire CLI. +// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members +import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; +import 'package:flutter/foundation.dart' + show defaultTargetPlatform, kIsWeb, TargetPlatform; + +/// Default [FirebaseOptions] for use with your Firebase apps. +/// +/// Example: +/// ```dart +/// import 'firebase_options.dart'; +/// // ... +/// await Firebase.initializeApp( +/// options: DefaultFirebaseOptions.currentPlatform, +/// ); +/// ``` +class DefaultFirebaseOptions { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for web - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return android; + case TargetPlatform.iOS: + return ios; + case TargetPlatform.macOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for macos - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.windows: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for windows - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.linux: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for linux - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + default: + throw UnsupportedError( + 'DefaultFirebaseOptions are not supported for this platform.', + ); + } + } + + static const FirebaseOptions android = FirebaseOptions( + apiKey: 'AIzaSyDenqsPlc8hyhy_CRTBQolOWvEYp0QkiwU', + appId: '1:97591185685:android:2df08f4bdc5c06e68d991c', + messagingSenderId: '97591185685', + projectId: 'dev-talentkita-golek', + storageBucket: 'dev-talentkita-golek.appspot.com', + ); + + static const FirebaseOptions ios = FirebaseOptions( + apiKey: 'AIzaSyBV3djMnp6iGQJog9RK0hwnKwBdmP4ZKkA', + appId: '1:97591185685:ios:c408a8133e24a8258d991c', + messagingSenderId: '97591185685', + projectId: 'dev-talentkita-golek', + storageBucket: 'dev-talentkita-golek.appspot.com', + androidClientId: '97591185685-jjnuop65uak1u0vag6tesjgt1sfu2i60.apps.googleusercontent.com', + iosClientId: '97591185685-papkbvrvnsurvorfna3d2nknasidckjs.apps.googleusercontent.com', + iosBundleId: 'com.golektruk.golekFlutterNew', + ); +} diff --git a/lib/golektruk.dart b/lib/golektruk.dart new file mode 100644 index 0000000..c1f1937 --- /dev/null +++ b/lib/golektruk.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; + +class GolekTruk extends StatelessWidget { + const GolekTruk({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: const Scaffold( + body: Text('HomePage GolekTruk'), + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index d535b79..1099329 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,66 +1,40 @@ +import 'dart:async'; +import 'dart:isolate'; + import 'package:flutter/material.dart'; +import 'package:golek_flutter_new/golektruk.dart'; +import 'package:monitoring/monitoring.dart'; + +import 'firebase_options.dart'; void main() { - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - primarySwatch: Colors.blue, - ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text(widget.title), - ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), - ); - } + // Has to be late so it doesn't instantiate before the + // `initializeMonitoringPackage()` call. + late final errorReportingService = ErrorReportingService(); + + runZonedGuarded>( + () async { + WidgetsFlutterBinding.ensureInitialized(); + await initializeMonitoringPackage(DefaultFirebaseOptions.currentPlatform); + + FlutterError.onError = errorReportingService.recordFlutterError; + + Isolate.current.addErrorListener( + RawReceivePort((pair) async { + final List errorAndStacktrace = pair; + await errorReportingService.recordError( + errorAndStacktrace.first, + errorAndStacktrace.last, + ); + }).sendPort, + ); + + runApp(const GolekTruk()); + }, + (error, stack) => errorReportingService.recordError( + error, + stack, + fatal: true, + ), + ); } diff --git a/packages/component_library/example/pubspec.lock b/packages/component_library/example/pubspec.lock new file mode 100644 index 0000000..8ea0544 --- /dev/null +++ b/packages/component_library/example/pubspec.lock @@ -0,0 +1,264 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.9.0" + auto_size_text: + dependency: transitive + description: + name: auto_size_text + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.0" + component_library: + dependency: "direct main" + description: + path: ".." + relative: true + source: path + version: "0.0.0" + device_frame: + dependency: transitive + description: + name: device_frame + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.1" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + flutter_localizations: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + flutter_svg: + dependency: transitive + description: + name: flutter_svg + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.6" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "0.15.0" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" + json_annotation: + dependency: transitive + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "4.7.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + nested: + dependency: transitive + description: + name: nested + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" + path_drawing: + dependency: transitive + description: + name: path_drawing + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + path_parsing: + dependency: transitive + description: + name: path_parsing + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "5.1.0" + provider: + dependency: transitive + description: + name: provider + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.4" + recase: + dependency: transitive + description: + name: recase + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + storybook_flutter: + dependency: "direct main" + description: + name: storybook_flutter + url: "https://pub.dartlang.org" + source: hosted + version: "0.8.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.12" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" +sdks: + dart: ">=2.18.0 <3.0.0" + flutter: ">=2.11.0-0.1.pre" diff --git a/packages/monitoring/lib/monitoring.dart b/packages/monitoring/lib/monitoring.dart new file mode 100644 index 0000000..5131d3a --- /dev/null +++ b/packages/monitoring/lib/monitoring.dart @@ -0,0 +1,9 @@ +import 'package:firebase_core/firebase_core.dart'; + +export 'src/analytics_service.dart'; +export 'src/error_reporting_service.dart'; +export 'src/explicit_crash.dart'; +export 'src/remote_value_service.dart'; + +Future initializeMonitoringPackage(FirebaseOptions? options) => + Firebase.initializeApp(options: options);