1.0.0
Some checks failed
Code Coverage / upload (push) Has been cancelled
Gh-Pages / build (push) Has been cancelled
Code Verification / verify (push) Has been cancelled

This commit is contained in:
zypherift
2025-08-09 18:17:34 +02:00
commit c7e3f36b06
438 changed files with 79192 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import 'package:fl_chart_app/presentation/resources/app_resources.dart';
import 'package:fl_chart_app/urls.dart';
enum ChartType { line, bar, pie, scatter, radar, candlestick }
extension ChartTypeExtension on ChartType {
String get displayName => '$simpleName Chart';
String get simpleName => switch (this) {
ChartType.line => 'Line',
ChartType.bar => 'Bar',
ChartType.pie => 'Pie',
ChartType.scatter => 'Scatter',
ChartType.radar => 'Radar',
ChartType.candlestick => 'Candlestick',
};
String get documentationUrl => Urls.getChartDocumentationUrl(this);
String get assetIcon => AppAssets.getChartIcon(this);
}

View File

@@ -0,0 +1,28 @@
import 'dart:math' as math;
import 'package:url_launcher/url_launcher.dart';
class AppUtils {
factory AppUtils() {
return _singleton;
}
AppUtils._internal();
static final AppUtils _singleton = AppUtils._internal();
double degreeToRadian(double degree) {
return degree * math.pi / 180;
}
double radianToDegree(double radian) {
return radian * 180 / math.pi;
}
Future<bool> tryToLaunchUrl(String url) async {
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
return await launchUrl(uri);
}
return false;
}
}

View File

@@ -0,0 +1,45 @@
class CsvParser {
static List<List<String>> parse(String rawCsvData) {
final lines =
rawCsvData.split('\n').where((line) => line.isNotEmpty).toList();
final headers = _parseCsvLine(lines.first);
return [
headers,
...lines.skip(1).map((line) => _parseCsvLine(line)),
];
}
static List<String> _parseCsvLine(String line) {
final values = <String>[];
final buffer = StringBuffer();
bool insideQuotes = false;
for (int i = 0; i < line.length; i++) {
final char = line[i];
if (char == '"') {
if (insideQuotes && i + 1 < line.length && line[i + 1] == '"') {
// Handle escaped quotes
buffer.write('"');
i++; // Skip the next quote
} else {
// Toggle the insideQuotes flag
insideQuotes = !insideQuotes;
}
} else if (char == ',' && !insideQuotes) {
// End of value
values.add(buffer.toString());
buffer.clear();
} else {
// Normal character
buffer.write(char);
}
}
// Add the last value
values.add(buffer.toString());
return values;
}
}

View File

@@ -0,0 +1,46 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:universal_platform/universal_platform.dart';
enum FormFactorType { monitor, smallPhone, largePhone, tablet }
// Copied from https://github.com/gskinnerTeam/flutter-folio/blob/main/lib/_utils/device_info.dart
class DeviceOS {
// Syntax sugar, proxy the UniversalPlatform methods so our views can reference a single class
static bool isIOS = UniversalPlatform.isIOS;
static bool isAndroid = UniversalPlatform.isAndroid;
static bool isMacOS = UniversalPlatform.isMacOS;
static bool isLinux = UniversalPlatform.isLinux;
static bool isWindows = UniversalPlatform.isWindows;
// Higher level device class abstractions (more syntax sugar for the views)
static bool isWeb = kIsWeb;
static bool get isDesktop => isWindows || isMacOS || isLinux;
static bool get isMobile => isAndroid || isIOS;
static bool get isDesktopOrWeb => isDesktop || isWeb;
static bool get isMobileOrWeb => isMobile || isWeb;
}
class DeviceScreen {
// Get the device form factor as best we can.
// Otherwise we will use the screen size to determine which class we fall into.
static FormFactorType get(BuildContext context) {
var shortestSide = MediaQuery.of(context).size.shortestSide;
if (shortestSide <= 300) return FormFactorType.smallPhone;
if (shortestSide <= 600) return FormFactorType.largePhone;
if (shortestSide <= 900) return FormFactorType.tablet;
return FormFactorType.monitor;
}
// Shortcuts for various mobile device types
static bool isPhone(BuildContext context) =>
isSmallPhone(context) || isLargePhone(context);
static bool isTablet(BuildContext context) =>
get(context) == FormFactorType.tablet;
static bool isMonitor(BuildContext context) =>
get(context) == FormFactorType.monitor;
static bool isSmallPhone(BuildContext context) =>
get(context) == FormFactorType.smallPhone;
static bool isLargePhone(BuildContext context) =>
get(context) == FormFactorType.largePhone;
}

View File

@@ -0,0 +1,43 @@
import 'dart:ui';
extension ColorExtension on Color {
/// Convert the color to a darken color based on the [percent]
Color darken([int percent = 40]) {
assert(1 <= percent && percent <= 100);
final value = 1 - percent / 100;
return Color.fromARGB(
_floatToInt8(a),
(_floatToInt8(r) * value).round(),
(_floatToInt8(g) * value).round(),
(_floatToInt8(b) * value).round(),
);
}
Color lighten([int percent = 40]) {
assert(1 <= percent && percent <= 100);
final value = percent / 100;
return Color.fromARGB(
_floatToInt8(a),
(_floatToInt8(r) + ((255 - _floatToInt8(r)) * value)).round(),
(_floatToInt8(g) + ((255 - _floatToInt8(g)) * value)).round(),
(_floatToInt8(b) + ((255 - _floatToInt8(b)) * value)).round(),
);
}
Color avg(Color other) {
final red = (_floatToInt8(r) + _floatToInt8(other.r)) ~/ 2;
final green = (_floatToInt8(g) + _floatToInt8(other.g)) ~/ 2;
final blue = (_floatToInt8(b) + _floatToInt8(other.b)) ~/ 2;
final alpha = (_floatToInt8(a) + _floatToInt8(other.a)) ~/ 2;
return Color.fromARGB(alpha, red, green, blue);
}
// Int color components were deprecated in Flutter 3.27.0.
// This method is used to convert the new double color components to the
// old int color components.
//
// Taken from the Color class.
int _floatToInt8(double x) {
return (x * 255.0).round() & 0xff;
}
}

View File

@@ -0,0 +1,3 @@
extension IterableToMapExtension<K, V> on Iterable<MapEntry<K, V>> {
Map<K, V> get asMap => Map.fromEntries(this);
}

View File

@@ -0,0 +1,3 @@
extension ListToMapExtension<K, V> on List<MapEntry<K, V>> {
Map<K, V> get asMap => Map.fromEntries(this);
}