raylib FFI bindings for Dart. You can copy C code into Dart and usually get it running with only small changes.
Note
The raylib backend uses xmake. When you run Dart code, hooks automatically download xmake.
import 'package:raylib_dart/raylib_dart.dart';
int main()
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}- MemAlloc/MemRealloc/MemFree are no-ops.
char *is treated as a UTF-8 byte stream.- TextFormat/TraceLog support up to 9 arguments. This is only for compatibility with C code; Dart has better native options, such as string interpolation.
- TextCopy has a different function interface because Dart passes object references by value.
- C APIs shaped like
T* array, int countare exposed as DartList<T>, removing thecountparameter. When compatibility conflicts with simplicity, this package chooses simplicity. - Raw C
intparameters used for enums/macros are exposed as Dart enums for better semantics and dot-shorthand support. The original C constant names are also preserved. - LoadRandomSequence returns a pure Dart object. UnloadRandomSequence is a compatibility no-op.
- Vector2/Vector3/Matrix/Ray are represented by vector_math.
int main(void)int main()Dart uses ~/ for integer division instead of C's /.
This is defined in cdart.
float a = 1.0f;float a = 1.0.f;(int)(leftStickX*20)(leftStickX*20).toInt()- Keep function names unchanged.
- Preserve the original enums and constants.
For enums, dot-shorthand is recommended to simplify code. The original constants are kept, marked as deprecated, and paired with the recommended style.
Color color = RED; // Deprecated
Color color = .red; // Recommended
KeyboardKey key = KEY_A; // Deprecated
KeyboardKey key = .a; // Recommended- Port raylib examples.
- Support web.