Skip to content

Commit d5d270c

Browse files
committed
Modifications to be able to load the library depending on the plattform
1 parent 5d3559e commit d5d270c

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

lib/utils/judger_loader.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@ import 'dart:io';
33
import 'package:flutter/services.dart';
44
import 'package:path_provider/path_provider.dart';
55

6-
// Load my library into a temporary directory
6+
// Load my library into a temporary directory (platform dependent)
77
Future<DynamicLibrary> loadJudgerLibrary() async {
8-
final byteData = await rootBundle.load('assets/native/linux/libjudger.so');
8+
late final String assetPath;
9+
late final String fileName;
910

11+
if (Platform.isLinux) {
12+
assetPath = 'assets/native/linux/libjudger.so';
13+
fileName = 'libjudger.so';
14+
} else if (Platform.isWindows) {
15+
assetPath = 'assets/native/windows/judger.dll';
16+
fileName = 'judger.dll';
17+
} else {
18+
throw UnsupportedError("Unsupported platform");
19+
}
20+
21+
// Load the asset
22+
final byteData = await rootBundle.load(assetPath);
23+
24+
// Copy to a temporary directory because DynamicLibrary.open() needs a real file
1025
final tempDir = await getTemporaryDirectory();
11-
final libPath = '${tempDir.path}/libjudger.so';
26+
final libPath = '${tempDir.path}/$fileName';
1227

1328
final file = File(libPath);
1429
await file.writeAsBytes(byteData.buffer.asUint8List());

0 commit comments

Comments
 (0)