https://github.com/kingtous/flutter_custom_cursor
Create/Set a custom mouse cursor directly from a memory buffer easily! use with https://github.com/Kingtous/engine if you are using flutter stable on Windows currently.
https://github.com/kingtous/flutter_custom_cursor
cursor flutter flutter-desktop flutter-plugin linux macos windows
Last synced: 4 months ago
JSON representation
Create/Set a custom mouse cursor directly from a memory buffer easily! use with https://github.com/Kingtous/engine if you are using flutter stable on Windows currently.
- Host: GitHub
- URL: https://github.com/kingtous/flutter_custom_cursor
- Owner: Kingtous
- License: apache-2.0
- Created: 2022-12-11T09:46:28.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-02T02:59:52.000Z (almost 3 years ago)
- Last Synced: 2025-04-02T22:23:20.286Z (9 months ago)
- Topics: cursor, flutter, flutter-desktop, flutter-plugin, linux, macos, windows
- Language: C++
- Homepage:
- Size: 324 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_custom_cursor


This plugin allows to create/set a custom mouse cursor directly from a memory buffer.
Big thanks to imiskolee to create the [base of this plugin](https://github.com/imiskolee/flutter_custom_cursor).
## Platforms
- [x] macOS
- [x] Windows
- [x] Linux
Note: Currently, the api required by this plugin on Windows is included in flutter `master` branch. It means that u need to use this plugin with flutter master branch on Windows platform. See [flutter engine PR#36143](https://github.com/flutter/engine/pull/36143) for details.
Update: the latest Flutter `3.7.0` does not contain PR above, which merges to `flutter-3.7.0-candidate.2`, while Flutter stable `3.7.0` is using `flutter-3.7.0-candidate.1`. This limitation will be lifted maybe in the next Flutter stable release.
# Get prepared
## Register your custom cursor before
```dart
// register this cursor
cursorName = await CursorManager.instance.registerCursor(CursorData()
..name = "test"
..buffer =
Platform.isWindows ? memoryCursorDataRawBGRA : memoryCursorDataRawPNG
..height = img.height
..width = img.width
..hotX = 0
..hotY = 0);
```
Note that a String `cacheName` will be returned by the function `registerCursor`, which can be used to set this cursor to system or delete this cursor.
`CursorData.buffer` is a `Uint8List` which contains the cursor data. Be aware that on Windows, `buffer` is formatted by `rawBGRA`, other OS(s) are `rawPNG`.
see the example project for details.
## Set the custom cursor
We have implemented the `FlutterCustomMemoryImageCursor` class, which is a subclass of `MouseCursor`. This class will automatically set the memory cursor for you. Keep it simple.
```dart
MouseRegion(
cursor: FlutterCustomMemoryImageCursor(key: cursorName),
child: Row(
children: [
Text("Memory image here", style: style),
],
),
),
```
## Delete the cursor
You can delete a cursor with the `cursorName`.
```dart
await CursorManager.instance.deleteCursor("cursorName");
```