Skip to content

Commit

Permalink
Initial Commit (#2)
Browse files Browse the repository at this point in the history
Initial Commit
  • Loading branch information
ibrahim-mubarak authored Apr 10, 2019
1 parent 3f6adf4 commit 01bc2f0
Show file tree
Hide file tree
Showing 46 changed files with 1,241 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .flutter-plugins
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path_provider=/Users/ibrahim/development/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-0.5.0+1/
shared_preferences=/Users/ibrahim/development/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.1+2/
74 changes: 74 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
pubspec.lock
.flutter-plugins
.packages
.pub-cache/
.pub/
/build/
*.g.dart

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

coverage/
10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 8661d8aecd626f7f57ccbcb735553edc05a2e713
channel: stable

project_type: package
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add Author Info here.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## [0.0.1] - TODO: Add release date.

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# flrx

A new Flutter package project.

## Getting Started

This project is a starting point for a Dart
[package](https://flutter.io/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.

For help getting started with Flutter, view our
[online documentation](https://flutter.io/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

##TODO

Add Command Line Tools to generate files
17 changes: 17 additions & 0 deletions lib/api/api_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:dio/dio.dart';

class ApiClient extends Dio {
ApiClient({BaseOptions options}) : super(options) {
interceptors.add(LogInterceptor(
error: true,
request: true,
requestBody: true,
requestHeader: true,
responseBody: true,
responseHeader: true));
}

void setDefaultHeader(Map<String, String> headers) {
options.headers = headers;
}
}
15 changes: 15 additions & 0 deletions lib/application.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flrx/components/error/error_handler.dart';
import 'package:flrx/components/error/error_reporter.dart';
import 'package:flrx/components/registrar/service_registrar.dart';

class Application {
static final ServiceRegistrar registrar = ServiceRegistrar();

static void init(void Function() initApp,
void Function(ServiceRegistrar) setupSingletons) {
setupSingletons(registrar);
ErrorHandler.init(reporter: get<ErrorReporter>()).runApp(initApp);
}

static T get<T>() => registrar<T>();
}
3 changes: 3 additions & 0 deletions lib/components/error/error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'error_handler.dart';
export 'error_reporter.dart';
export 'sentry_error_reporter.dart';
60 changes: 60 additions & 0 deletions lib/components/error/error_handler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'dart:async';

import 'package:flrx/components/error/error_reporter.dart';
import 'package:flrx/components/logger/logger.dart';
import 'package:flrx/config/config.dart';
import 'package:flutter/widgets.dart';

class ErrorHandler {
//Create new Error Handler
factory ErrorHandler.init({@required ErrorReporter reporter}) {
_instance ??= ErrorHandler._internal(reporter);
return _instance;
}

ErrorHandler._internal(this.reporter)
: reportErrorOnDebug = reporter.reportOnDebug ?? false {
_setupFlutterErrorHandler();
}

static void dispose() => _instance = null;

final ErrorReporter reporter;

static ErrorHandler _instance;

final bool reportErrorOnDebug;

static ErrorHandler get instance {
return _instance;
}

void _setupFlutterErrorHandler() {
// This captures errors reported by the Flutter framework.
FlutterError.onError = (FlutterErrorDetails details) async {
if (Config.isInDebugMode && !reportErrorOnDebug) {
// In development mode and Debug Mode reporting is disabled. Simply log it
log(details);
} else {
// In production mode report to the application zone
Zone.current.handleUncaughtError(details.exception, details.stack);
}
};
}

void runApp(Function appFunction) {
runZoned<Future<void>>(() async {
appFunction();
}, onError: reportError);
}

void reportError(dynamic error, StackTrace stackTrace) async {
if (Config.isInDebugMode && !reportErrorOnDebug) {
log('Caught error: $error');
log(stackTrace);
log('In dev mode. Not reporting Error');
return;
}
_instance.reporter.reportError(error, stackTrace);
}
}
5 changes: 5 additions & 0 deletions lib/components/error/error_reporter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abstract class ErrorReporter {
bool reportOnDebug = false;

void reportError(dynamic error, StackTrace stackTrace);
}
28 changes: 28 additions & 0 deletions lib/components/error/sentry_error_reporter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flrx/components/error/error_reporter.dart';
import 'package:flrx/components/logger/logger.dart';
import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';

/// Sentry Error Reporter from [https://flutter.dev/docs/cookbook/maintenance/error-reporting]
class SentryErrorReporter with ErrorReporter {
SentryErrorReporter({@required String dsn})
: _sentry = SentryClient(dsn: dsn);

final SentryClient _sentry;

/// Reports [error] along with its [stackTrace] to Sentry.io.
@override
void reportError(dynamic error, StackTrace stackTrace) async {
log('Reporting to Sentry.io...');
final SentryResponse response = await _sentry.captureException(
exception: error,
stackTrace: stackTrace,
);

if (response.isSuccessful) {
log('Success! Event ID: ${response.eventId}');
} else {
log('Failed to report to Sentry.io: ${response.error}');
}
}
}
20 changes: 20 additions & 0 deletions lib/components/localization/base_localizer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flrx/application.dart';
import 'package:flutter/widgets.dart';

abstract class Localizer {
String translate(final BuildContext context, final String key,
{final Map<String, String> translationParams});

String plural(
final BuildContext context, final String key, final int pluralValue);

void setLocale(final BuildContext context, final Locale locale);

LocalizationsDelegate<Object> getLocalizationDelegate();
}

// ignore: unused_element, non_constant_identifier_names
String translate(final BuildContext context, final String key,
{final Map<String, String> translationParams}) =>
Application.get<Localizer>()
.translate(context, key, translationParams: translationParams);
36 changes: 36 additions & 0 deletions lib/components/localization/json_localizer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:flrx/components/localization/base_localizer.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_i18n/flutter_i18n_delegate.dart';

class JsonLocalizer extends Localizer {
JsonLocalizer(
{@required this.fallbackFile,
@required this.path,
@required this.useCountryCode});

final String fallbackFile;
final String path;
final bool useCountryCode;

@override
String translate(final BuildContext context, final String key,
{final Map<String, String> translationParams}) =>
FlutterI18n.translate(context, key, translationParams);

@override
String plural(final BuildContext context, final String key,
final int pluralValue) =>
FlutterI18n.plural(context, key, pluralValue);

@override
void setLocale(final BuildContext context, final Locale locale) =>
FlutterI18n.refresh(context, locale);

@override
LocalizationsDelegate<Object> getLocalizationDelegate() =>
FlutterI18nDelegate(
fallbackFile: fallbackFile,
path: path,
useCountryCode: useCountryCode);
}
2 changes: 2 additions & 0 deletions lib/components/localization/localization.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'base_localizer.dart';
export 'json_localizer.dart';
7 changes: 7 additions & 0 deletions lib/components/logger/base_logger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:flrx/application.dart';

abstract class Logger {
void log(dynamic message);
}

void log(dynamic message) => Application.get<Logger>().log(message);
12 changes: 12 additions & 0 deletions lib/components/logger/console_logger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flrx/components/logger/base_logger.dart';
import 'package:flutter/widgets.dart';

class ConsoleLogger extends Logger {
@override
void log(dynamic message) {
if (message is FlutterErrorDetails) {
FlutterError.dumpErrorToConsole(message);
} else
debugPrint(message.toString());
}
}
2 changes: 2 additions & 0 deletions lib/components/logger/logger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'base_logger.dart';
export 'console_logger.dart';
3 changes: 3 additions & 0 deletions lib/components/registrar/service_registrar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:get_it/get_it.dart';

class ServiceRegistrar extends GetIt {}
21 changes: 21 additions & 0 deletions lib/config/base_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flrx/config/flavors/flavor_config.dart';
import 'package:flrx/flrx.dart';

abstract class Config {
static bool get isInDebugMode {
bool inDebugMode = false;
assert(inDebugMode = true);
return inDebugMode;
}

Config();

Config of(Flavor flavor);

static T get<T extends Config>() {
return FlavorConfig.instance.configList.firstWhere(
(Config config) => config is T,
orElse: () =>
throw Exception("Config $T is not registered in ConfigList"));
}
}
4 changes: 4 additions & 0 deletions lib/config/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'base_config.dart';
export 'config_error.dart';
export 'flavors/flavor.dart';
export 'flavors/flavor_config.dart';
13 changes: 13 additions & 0 deletions lib/config/config_error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flrx/config/flavors/flavor.dart';
import 'package:meta/meta.dart';

class ConfigNotImplementedError extends UnimplementedError {
ConfigNotImplementedError({@required this.configType, @required this.flavor});

String configType;
BaseFlavor flavor;

@override
String toString() =>
"ConfigNotImplementedError: $configType Has not been implemented for $flavor";
}
Loading

0 comments on commit 01bc2f0

Please sign in to comment.