diff --git a/README-ZH.md b/README-ZH.md index 69bdd2f..9a45f6e 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -1,15 +1,12 @@ # screen_retriever -[![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] ![][visits-count-image] +[![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] [pub-image]: https://img.shields.io/pub/v/screen_retriever.svg [pub-url]: https://pub.dev/packages/screen_retriever - [discord-image]: https://img.shields.io/discord/884679008049037342.svg [discord-url]: https://discord.gg/zPa6EZ2jqb -[visits-count-image]: https://img.shields.io/badge/dynamic/json?label=Visits%20Count&query=value&url=https://api.countapi.xyz/hit/leanflutter.screen_retriever/visits - 这个插件允许 Flutter 桌面应用检索关于屏幕大小,显示,光标位置等信息。 --- @@ -21,15 +18,15 @@ -- [screen_retriever](#screen_retriever) - - [平台支持](#平台支持) - - [快速开始](#快速开始) - - [安装](#安装) - - [用法](#用法) - - [谁在用使用它?](#谁在用使用它) - - [API](#api) - - [ScreenRetriever](#screenretriever) - - [许可证](#许可证) +- [平台支持](#%E5%B9%B3%E5%8F%B0%E6%94%AF%E6%8C%81) +- [快速开始](#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B) + - [安装](#%E5%AE%89%E8%A3%85) + - [用法](#%E7%94%A8%E6%B3%95) + - [监听事件](#%E7%9B%91%E5%90%AC%E4%BA%8B%E4%BB%B6) +- [谁在用使用它?](#%E8%B0%81%E5%9C%A8%E7%94%A8%E4%BD%BF%E7%94%A8%E5%AE%83) +- [API](#api) + - [ScreenRetriever](#screenretriever) +- [许可证](#%E8%AE%B8%E5%8F%AF%E8%AF%81) @@ -37,7 +34,7 @@ | Linux | macOS | Windows | | :---: | :---: | :-----: | -| ✔️ | ✔️ | ✔️ | +| ✔️ | ✔️ | ✔️ | ## 快速开始 @@ -57,6 +54,7 @@ dependencies: screen_retriever: git: url: https://github.com/leanflutter/screen_retriever.git + path: packages/screen_retriever ref: main ``` @@ -73,6 +71,42 @@ void _init() async { } ``` +### 监听事件 + +```dart +class HomePage extends StatefulWidget { + const HomePage({Key? key}) : super(key: key); + + @override + State createState() => _HomePageState(); +} + +class _HomePageState extends State with ScreenListener { + @override + void initState() { + screenRetriever.addListener(this); + super.initState(); + } + + @override + void dispose() { + screenRetriever.removeListener(this); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + // ... + } + + @override + void onScreenEvent(String eventName) { + String log = 'Event received: $eventName)'; + print(log); + } +} +``` + > 请看这个插件的示例应用,以了解完整的例子。 ## 谁在用使用它? @@ -85,9 +119,9 @@ void _init() async { | Method | Description | Linux | macOS | Windows | | ---------------------- | --------------------------------------------- | ----- | ----- | ------- | -| `getCursorScreenPoint` | 返回 `Offset` - 鼠标指针的当前绝对位置。 | ✔️ | ✔️ | ✔️ | -| `getPrimaryDisplay` | 返回 `Display` - 主显示屏。 | ✔️ | ✔️ | ✔️ | -| `getAllDisplays` | 返回 `List` - 当前可用的显示器列表。 | ✔️ | ✔️ | ✔️ | +| `getCursorScreenPoint` | 返回 `Offset` - 鼠标指针的当前绝对位置。 | ✔️ | ✔️ | ✔️ | +| `getPrimaryDisplay` | 返回 `Display` - 主显示屏。 | ✔️ | ✔️ | ✔️ | +| `getAllDisplays` | 返回 `List` - 当前可用的显示器列表。 | ✔️ | ✔️ | ✔️ | ## 许可证 diff --git a/README.md b/README.md index b335f8d..5f2f573 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,12 @@ # screen_retriever -[![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] ![][visits-count-image] +[![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] [pub-image]: https://img.shields.io/pub/v/screen_retriever.svg [pub-url]: https://pub.dev/packages/screen_retriever - [discord-image]: https://img.shields.io/discord/884679008049037342.svg [discord-url]: https://discord.gg/zPa6EZ2jqb -[visits-count-image]: https://img.shields.io/badge/dynamic/json?label=Visits%20Count&query=value&url=https://api.countapi.xyz/hit/leanflutter.screen_retriever/visits - This plugin allows Flutter desktop apps to Retrieve information about screen size, displays, cursor position, etc. --- @@ -21,15 +18,15 @@ English | [简体中文](./README-ZH.md) -- [screen_retriever](#screen_retriever) - - [Platform Support](#platform-support) - - [Quick Start](#quick-start) - - [Installation](#installation) - - [Usage](#usage) - - [Who's using it?](#whos-using-it) - - [API](#api) - - [ScreenRetriever](#screenretriever) - - [License](#license) +- [Platform Support](#platform-support) +- [Quick Start](#quick-start) + - [Installation](#installation) + - [Usage](#usage) + - [Listening events](#listening-events) +- [Who's using it?](#whos-using-it) +- [API](#api) + - [ScreenRetriever](#screenretriever) +- [License](#license) @@ -37,7 +34,7 @@ English | [简体中文](./README-ZH.md) | Linux | macOS | Windows | | :---: | :---: | :-----: | -| ✔️ | ✔️ | ✔️ | +| ✔️ | ✔️ | ✔️ | ## Quick Start @@ -57,6 +54,7 @@ dependencies: screen_retriever: git: url: https://github.com/leanflutter/screen_retriever.git + path: packages/screen_retriever ref: main ``` @@ -73,6 +71,42 @@ void _init() async { } ``` +### Listening events + +```dart +class HomePage extends StatefulWidget { + const HomePage({Key? key}) : super(key: key); + + @override + State createState() => _HomePageState(); +} + +class _HomePageState extends State with ScreenListener { + @override + void initState() { + screenRetriever.addListener(this); + super.initState(); + } + + @override + void dispose() { + screenRetriever.removeListener(this); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + // ... + } + + @override + void onScreenEvent(String eventName) { + String log = 'Event received: $eventName)'; + print(log); + } +} +``` + > Please see the example app of this plugin for a full example. ## Who's using it? @@ -85,9 +119,9 @@ void _init() async { | Method | Description | Linux | macOS | Windows | | ---------------------- | ---------------------------------------------------------------------------- | ----- | ----- | ------- | -| `getCursorScreenPoint` | Returns `Offset` - The current absolute position of the mouse pointer. | ✔️ | ✔️ | ✔️ | -| `getPrimaryDisplay` | Returns `Display` - The primary display. | ✔️ | ✔️ | ✔️ | -| `getAllDisplays` | Returns `List` - An array of displays that are currently available. | ✔️ | ✔️ | ✔️ | +| `getCursorScreenPoint` | Returns `Offset` - The current absolute position of the mouse pointer. | ✔️ | ✔️ | ✔️ | +| `getPrimaryDisplay` | Returns `Display` - The primary display. | ✔️ | ✔️ | ✔️ | +| `getAllDisplays` | Returns `List` - An array of displays that are currently available. | ✔️ | ✔️ | ✔️ | ## License