flutter_custom_cursor
直接從記憶體緩衝區建立/設定自訂滑鼠游標。
輕鬆直接從記憶體緩衝區建立/設定自訂滑鼠游標!若目前在 Windows 上使用 Flutter 穩定版,請搭配 https://github.com/Kingtous/engine 使用。
{"sdk":"flutter"}{"sdk":"flutter"}^3.0.0以下為英文專案原文快照,最新內容請造訪 GitHub。
https://img.shields.io/pub/v/flutter_custom_cursor?color=green https://img.shields.io/pub/publisher/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.
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 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.
// 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.
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.
MouseRegion(
cursor: FlutterCustomMemoryImageCursor(key: cursorName),
child: Row(
children: [
Text("Memory image here", style: style),
],
),
),
You can delete a cursor with the cursorName.
await CursorManager.instance.deleteCursor("cursorName");