Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
SchabanBo committed Jul 17, 2024
2 parents b83c195 + e3679b1 commit eec4d25
Show file tree
Hide file tree
Showing 36 changed files with 776 additions and 275 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
.svn/
migrate_working_dir/
windows/
web/

# IntelliJ related
*.iml
Expand Down
16 changes: 8 additions & 8 deletions .metadata
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# 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.
# This file should be version controlled and should not be manually edited.

version:
revision: cd41fdd495f6944ecd3506c21e94c6567b073278
channel: stable
revision: "abb292a07e20d696c4568099f918f6c5f330e6b0"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
base_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
- platform: windows
create_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
base_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
create_revision: abb292a07e20d696c4568099f918f6c5f330e6b0
base_revision: abb292a07e20d696c4568099f918f6c5f330e6b0
- platform: web
create_revision: abb292a07e20d696c4568099f918f6c5f330e6b0
base_revision: abb292a07e20d696c4568099f918f6c5f330e6b0

# User provided section

Expand Down
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "localic",
"request": "launch",
"type": "dart"
},
{
"name": "localic (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "localic (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
19 changes: 19 additions & 0 deletions lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Generated file. Do not edit.
//

// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars
// ignore_for_file: depend_on_referenced_packages

import 'package:file_picker/_internal/file_picker_web.dart';
import 'package:shared_preferences_web/shared_preferences_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
FilePickerWeb.registerWith(registrar);
SharedPreferencesPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
9 changes: 6 additions & 3 deletions lib/global/provider_observer.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'services/logging_service.dart';

class ProviderLogger extends ProviderObserver {
@override
void didUpdateProvider(
Expand All @@ -8,7 +10,7 @@ class ProviderLogger extends ProviderObserver {
Object? newValue,
ProviderContainer container,
) {
print(
logger.d(
'${provider.name ?? provider.runtimeType}: $previousValue -> $newValue');
}

Expand All @@ -17,7 +19,7 @@ class ProviderLogger extends ProviderObserver {
ProviderBase provider,
ProviderContainer container,
) {
print('${provider.name ?? provider.runtimeType}: disposed');
logger.d('${provider.name ?? provider.runtimeType}: disposed');
}

@override
Expand All @@ -26,6 +28,7 @@ class ProviderLogger extends ProviderObserver {
Object? value,
ProviderContainer container,
) {
print('${provider.name ?? provider.runtimeType}: added with value $value');
logger
.d('${provider.name ?? provider.runtimeType}: added with value $value');
}
}
97 changes: 97 additions & 0 deletions lib/global/services/logging_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import 'dart:developer';

import 'package:logger/logger.dart';

import '../../helpers/extensions/int_extension.dart';

final logger = LoggingService().createLogger();

class LoggingService {
Logger createLogger() {
return Logger(
filter: _LogFilter(),
printer: _LogPrinter(),
output: _ConsoleLogOutput(),
);
}
}

class _LogFilter extends LogFilter {
@override
bool shouldLog(LogEvent event) => true;
}

class _LogPrinter extends LogPrinter {
@override
List<String> log(LogEvent event) {
var message = event.message;
var error = event.error;
var stackTrace = event.stackTrace;
var level = event.level;

var builder = StringBuffer();
const spacer = '|';
builder.write(_getTime());
builder.write(spacer);
builder.write(_logLevel(level));
builder.write(spacer);
builder.write(_getLogLocation());
builder.write(spacer);
builder.write(message);

var errorString = error.toString();
if (errorString != 'null') {
var errorLines = errorString.split('\n');
errorLines = errorLines.map((line) => ' $line').toList();
builder.write('\n${errorLines.join('\n')}');
builder.write('\n');
}

var stackTraceString = stackTrace.toString();
if (stackTraceString != 'null') {
var stackTraceLines = stackTraceString.split('\n');
stackTraceLines =
stackTraceLines.map((line) => ' $line').take(100).toList();
builder.write('\n${stackTraceLines.join('\n')}');
}
return [builder.toString()];
}

String _logLevel(Level level) {
return level.name.substring(0, 3).toUpperCase();
}

String _getLogLocation() {
final stack = StackTrace.current.toString().split('\n');
final line = stack[4];
return line.substring(
line.lastIndexOf('/') + 1,
line.indexOf('.dart'),
);
}

String _getTime() {
var now = DateTime.now().toUtc();
var h = now.hour.twoDigits();
var min = now.minute.twoDigits();
var sec = now.second.twoDigits();
var ms = now.millisecond.threeDigits();
return '$h:$min:$sec.$ms';
}
}

class _ConsoleLogOutput extends LogOutput {
@override
void output(OutputEvent event) {
final color = _color(event.level);
var message = color + event.lines.join('\n');
log(message);
}

String _color(Level level) => switch (level) {
Level.error => '\u001b[1;31m',
Level.warning => '\u001b[1;33m',
Level.info => '\u001b[1;32m',
_ => '\u001b[0m'
};
}
18 changes: 12 additions & 6 deletions lib/global/services/translators/google_translator_service.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import 'package:dio/dio.dart';

import '../../../helpers/extensions/string_extension.dart';
import '../../../models/local_data/local.dart';
import '../../../ui/widgets/error_notification.dart';
import '../logging_service.dart';

class GoogleTranslatorService {
final String apiKey;
final Dio _dio = Dio();
GoogleTranslatorService(this.apiKey);

Future<LocalItem> translate(LocalItem item, String from) async {
Future<LocalItem> translate(LocalItem item, String from,
{bool overwrite = false}) async {
try {
for (var i = 0; i < item.values.length; i++) {
final key = item.values.keys.elementAt(i);
if (key == from || item.values.values.elementAt(i).isNotEmpty) {
continue;
}
item.values[key] = await getTranslation(item.values[from]!, from, key);
if (key == from) continue;
if (item.values.values.elementAt(i).isNotEmpty && !overwrite) continue;
final valueFrom = item.values[from];
if (valueFrom.isNullOrEmpty) continue;
item.values[key] = await getTranslation(valueFrom!, from, key);
}
} on Exception catch (e) {
} catch (e, s) {
logger.e('Error Translating $e', error: e, stackTrace: s);
showNotification('Error Translating', e.toString());
}
return item;
}

Future<String> getTranslation(String value, String from, String to) async {
logger.d('Translating $value from $from to $to');
final request = await _dio.get(
'https://translation.googleapis.com/language/translate/v2',
queryParameters: {
Expand Down
9 changes: 5 additions & 4 deletions lib/helpers/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'package:flutter/material.dart';

class AppColors {
static const Color icon = Colors.white;
static const Color border = Color(0xFF202020);
static const Color item = Color(0xFF050505);
static const Color node = Color(0xFF101010);
static const Color background = Color(0xFF111217);
static const Color border = Color(0xFF0c0c0f);
static const Color item = Color(0xFF15151a);
static const Color node = Color(0xFF202127);
static const Color drag = Color(0xFF101010);
static const Color secondary = Color(0xffB7B327);
static const Color primary = Colors.amber;
static const Color primary = Color(0xFFe89f23);
}

const animationDuration = Duration(milliseconds: 500);
Expand Down
21 changes: 21 additions & 0 deletions lib/helpers/extensions/int_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extension NullIntExtension on int? {
bool get isNull => this == null;
bool get isNotNull => this != null;
bool get asBool => this == 1;

bool get isNotNullOrZero => this != null && this != 0;
bool get isNullOrZero => this == null || this == 0;
}

extension IntExtension on int {
String twoDigits() {
if (this >= 10) return '$this';
return '0$this';
}

String threeDigits() {
if (this >= 100) return '$this';
if (this >= 10) return '0$this';
return '00$this';
}
}
28 changes: 28 additions & 0 deletions lib/helpers/extensions/string_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extension StringExtension on String? {
bool get isNullOrEmpty => this == null || this!.trim().isEmpty;

bool get isNotNullOrEmpty => !isNullOrEmpty;

bool get asBool {
if (isNullOrEmpty) return false;
switch (this!.toLowerCase()) {
case 'true':
case '1':
return true;
case 'false':
case '0':
return false;
default:
throw Exception('Invalid boolean value: $this');
}
}

/// remove all whitespace from the string
String removeAllWhitespace() {
return this!.trim().replaceAll(' ', '');
}

bool containsIgnoreCase(String other) {
return this!.toLowerCase().contains(other.toLowerCase());
}
}
Loading

0 comments on commit eec4d25

Please sign in to comment.