File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,12 +3,27 @@ import 'dart:io';
33import 'package:flutter/services.dart' ;
44import '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)
77Future <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 ());
You can’t perform that action at this time.
0 commit comments