Skip to content

Commit fb9a6c0

Browse files
authored
Use flutter_sdl_gamepads to compile SDL binaries (#175)
Shoutout to @Gold872 for putting in much of the work behind `package:flutter_sdl_gamepad`
1 parent 362a2da commit fb9a6c0

File tree

9 files changed

+23
-7
lines changed

9 files changed

+23
-7
lines changed

SDL3.dll

-2.34 MB
Binary file not shown.

lib/src/services/files.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class FilesService extends Service {
4949
/// The encoder to convert a Map<> to a json string with a nice indent
5050
final JsonEncoder jsonEncoder = const JsonEncoder.withIndent(" ");
5151

52+
bool _isInit = false;
53+
5254
/// Ensure that files and directories that are expected to be present actually
5355
/// exist on the system. If not, create them.
5456
@override
@@ -58,6 +60,7 @@ class FilesService extends Service {
5860
loggingDir = await Directory("${outputDir.path}/logs/${DateTime.now().timeStamp}").create(recursive: true);
5961
if (!settingsFile.existsSync()) await writeSettings(null);
6062
dataLogger = Timer.periodic(const Duration(seconds: 5), logAllData);
63+
_isInit = true;
6164
}
6265

6366
@override
@@ -139,6 +142,7 @@ class FilesService extends Service {
139142

140143
/// Outputs error to log file
141144
Future<void> logError(Object error, StackTrace stack) async{
145+
if (!_isInit) return;
142146
final file = loggingDir / "errors.log";
143147
await file.writeAsString("${DateTime.now().timeStamp} $error $stack\n", mode: FileMode.writeOnlyAppend);
144148
}

lib/src/services/gamepad/sdl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "package:sdl_gamepad/sdl_gamepad.dart" as sdl;
1+
import "package:flutter_sdl_gamepad/flutter_sdl_gamepad.dart" as sdl;
22

33
import "state.dart";
44
import "gamepad.dart";

lib/src/services/gamepad/service.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "package:sdl_gamepad/sdl_gamepad.dart";
1+
import "package:flutter_sdl_gamepad/flutter_sdl_gamepad.dart";
22

33
import "../service.dart";
44
import "gamepad.dart";
@@ -45,7 +45,9 @@ class GamepadService extends Service {
4545

4646
@override
4747
Future<void> init() async {
48-
SdlLibrary.init();
48+
if (!SdlLibrary.init()) {
49+
throw StateError("Could not initialize SDL libraries");
50+
}
4951
gamepads = List.generate(maxGamepads, MockGamepad.new);
5052
for (var i = 0; i < maxGamepads; i++) {
5153
await connect(i);

libSDL3.so

-3.24 MB
Binary file not shown.

linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
88
)
99

1010
list(APPEND FLUTTER_FFI_PLUGIN_LIST
11+
flutter_sdl_gamepad
1112
)
1213

1314
set(PLUGIN_BUNDLED_LIBRARIES)

pubspec.lock

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ packages:
207207
url: "https://pub.dev"
208208
source: hosted
209209
version: "3.0.0"
210+
flutter_sdl_gamepad:
211+
dependency: "direct main"
212+
description:
213+
name: flutter_sdl_gamepad
214+
sha256: "513910280591bdc5362dda0c0a8d53b310f0d9e5f53c4188ddaf13f7339847b0"
215+
url: "https://pub.dev"
216+
source: hosted
217+
version: "1.0.0"
210218
flutter_test:
211219
dependency: "direct dev"
212220
description: flutter
@@ -498,13 +506,13 @@ packages:
498506
source: hosted
499507
version: "0.1.34"
500508
sdl_gamepad:
501-
dependency: "direct main"
509+
dependency: transitive
502510
description:
503511
name: sdl_gamepad
504-
sha256: "5d1931dc4e4831dc298a1964b94d4e5a257b027ad5ce268620c6b5e15a46c70b"
512+
sha256: "3bce11dbf7da9a543ce17177342171d5033a2b7198dbfa51b5bee7cdc45d4ac2"
505513
url: "https://pub.dev"
506514
source: hosted
507-
version: "1.0.1"
515+
version: "1.0.2"
508516
sky_engine:
509517
dependency: transitive
510518
description: flutter

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies:
2222
url_launcher: ^6.1.10
2323
just_audio: ^0.9.36
2424
collection: ^1.18.0
25-
sdl_gamepad: ^1.0.1
25+
flutter_sdl_gamepad: ^1.0.0
2626

2727
# Prefer to use `flutter pub add --dev packageName` rather than modify this section by hand.
2828
dev_dependencies:

windows/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
88
)
99

1010
list(APPEND FLUTTER_FFI_PLUGIN_LIST
11+
flutter_sdl_gamepad
1112
)
1213

1314
set(PLUGIN_BUNDLED_LIBRARIES)

0 commit comments

Comments
 (0)