fix: Resolve JavaScript integer compatibility for Isar schema generation
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:isar/isar.dart'; // Импорт Isar
|
||||
import 'app.dart'; // Import the new app root widget
|
||||
import 'database/database.dart'; // Импортируем наш IsarService
|
||||
import 'models/isar_transaction.dart'; // Импортируем схему Isar
|
||||
import 'utils/isar_web_helper.dart'; // Импортируем наш вспомогательный класс для веб
|
||||
|
||||
Future<void> main() async {
|
||||
// Необходимо для асинхронных операций перед runApp
|
||||
@@ -14,6 +15,11 @@ Future<void> main() async {
|
||||
// download: true скачает нужную библиотеку, если ее нет
|
||||
// await Isar.initializeIsarCore(download: true); // Больше не требуется с isar_flutter_libs
|
||||
|
||||
// Проверяем, запущено ли приложение на веб-платформе
|
||||
if (IsarWebHelper.isWeb) {
|
||||
print('Running on web platform - using JavaScript-safe integer IDs');
|
||||
}
|
||||
|
||||
// Открываем базу данных Isar с помощью статического метода в IsarService
|
||||
final isar = await IsarService.openDB();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ extension GetIsarTransactionCollection on Isar {
|
||||
|
||||
const IsarTransactionSchema = CollectionSchema(
|
||||
name: r'Transaction',
|
||||
id: 5320225499417954855,
|
||||
id: 5320225, // Reduced to a JavaScript-safe integer
|
||||
properties: {
|
||||
r'amount': PropertySchema(
|
||||
id: 0,
|
||||
@@ -45,7 +45,7 @@ const IsarTransactionSchema = CollectionSchema(
|
||||
idName: r'id',
|
||||
indexes: {
|
||||
r'category_name': IndexSchema(
|
||||
id: -3986107701717091180,
|
||||
id: -3986107, // Reduced to a JavaScript-safe integer
|
||||
name: r'category_name',
|
||||
unique: false,
|
||||
replace: false,
|
||||
@@ -58,7 +58,7 @@ const IsarTransactionSchema = CollectionSchema(
|
||||
],
|
||||
),
|
||||
r'transaction_date': IndexSchema(
|
||||
id: 1196378424800128741,
|
||||
id: 1196378, // Reduced to a JavaScript-safe integer
|
||||
name: r'transaction_date',
|
||||
unique: false,
|
||||
replace: false,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// Helper class for handling Isar compatibility issues with web platform
|
||||
class IsarWebHelper {
|
||||
/// Checks if the current platform is web
|
||||
static bool get isWeb => kIsWeb;
|
||||
|
||||
/// Returns a JavaScript-safe integer ID
|
||||
///
|
||||
/// When running on web, this will return a smaller integer that's safe for JavaScript
|
||||
/// When running on native platforms, it will return the original ID
|
||||
static int safeId(int originalId) {
|
||||
if (isWeb) {
|
||||
// For web, return a smaller integer by taking modulo with a safe JavaScript integer
|
||||
// Number.MAX_SAFE_INTEGER in JavaScript is 9007199254740991
|
||||
return originalId % 9007199;
|
||||
}
|
||||
// For native platforms, return the original ID
|
||||
return originalId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user