Skip to content

Commit b24279b

Browse files
authored
fix: broken web build (#3261)
1 parent 125cc17 commit b24279b

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

lib/console_helper.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'dart:ffi' as ffi;
2+
3+
void attachParentConsole() {
4+
const attachParentProcess = 0xFFFFFFFF;
5+
final kernel32 = ffi.DynamicLibrary.open('kernel32.dll');
6+
final attachConsole = kernel32.lookupFunction<ffi.Int32 Function(ffi.Uint32),
7+
int Function(int)>('AttachConsole');
8+
attachConsole(attachParentProcess);
9+
}

lib/console_helper_dummy.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
void attachParentConsole() {
2+
throw UnsupportedError(
3+
'attachParentConsole is not supported on this platform');
4+
}

lib/main.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import 'dart:ffi' as ffi;
21
import 'dart:io';
32

3+
import 'package:pslab/console_helper_dummy.dart'
4+
if (dart.library.io) 'package:pslab/console_helper.dart' as console_helper;
5+
46
import 'package:pslab/providers/sht21_provider.dart';
57
import 'package:flutter/foundation.dart';
68
import 'package:flutter/material.dart';
@@ -42,7 +44,7 @@ void main(List<String> args) async {
4244
(Platform.isWindows || Platform.isLinux || Platform.isMacOS) &&
4345
args.any((a) => a == '-v' || a == '--version')) {
4446
if (Platform.isWindows) {
45-
_attachParentConsole();
47+
console_helper.attachParentConsole();
4648
}
4749
final info = await PackageInfo.fromPlatform();
4850
stdout.writeln('${info.appName} ${info.version}+${info.buildNumber}');
@@ -175,14 +177,6 @@ class _LocaleAware extends StatelessWidget {
175177
}
176178
}
177179

178-
void _attachParentConsole() {
179-
const attachParentProcess = 0xFFFFFFFF;
180-
final kernel32 = ffi.DynamicLibrary.open('kernel32.dll');
181-
final attachConsole = kernel32.lookupFunction<ffi.Int32 Function(ffi.Uint32),
182-
int Function(int)>('AttachConsole');
183-
attachConsole(attachParentProcess);
184-
}
185-
186180
void _preCacheImages(BuildContext context) {
187181
for (final path in instrumentIcons) {
188182
precacheImage(AssetImage(path), context);

0 commit comments

Comments
 (0)