Skip to content

Commit

Permalink
chore: Update example (remove preference_list dependency)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Aug 18, 2024
1 parent fc03b06 commit 34f7259
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 219 deletions.
29 changes: 1 addition & 28 deletions packages/screen_retriever/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
include: package:mostly_reasonable_lints/analysis_options.yaml
158 changes: 92 additions & 66 deletions packages/screen_retriever/example/lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
import 'package:preference_list/preference_list.dart';
import 'package:screen_retriever/screen_retriever.dart';
import 'package:screen_retriever_example/widgets/display_card.dart';

final hotKeyManager = HotKeyManager.instance;
final screenRetriever = ScreenRetriever.instance;

class _DisplayItem extends StatelessWidget {
final Display display;
class _ListSection extends StatelessWidget {
const _ListSection({required this.title, required this.children});

const _DisplayItem({Key? key, required this.display}) : super(key: key);
final Widget title;
final List<Widget> children;

@override
Widget build(BuildContext context) {
return PreferenceListItem(
title: Text('${display.name}'),
summary: Text(
[
'id: ${display.id}',
'size: ${display.size}',
'visiblePosition: ${display.visiblePosition}',
'visibleSize: ${display.visibleSize}',
'scaleFactor: ${display.scaleFactor}',
].join('\n'),
),
onTap: () {
BotToast.showText(text: '${display.toJson()}');
},
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(
left: 20,
top: 12,
bottom: 6,
),
child: DefaultTextStyle(
style: Theme.of(context).textTheme.titleMedium ?? const TextStyle(),
child: title,
),
),
...children,
],
);
}
}

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
const HomePage({super.key});

@override
State<HomePage> createState() => _HomePageState();
Expand All @@ -49,7 +52,7 @@ class _HomePageState extends State<HomePage> {
_init();
}

void _init() async {
Future<void> _init() async {
// 初始化快捷键
hotKeyManager.unregisterAll();
hotKeyManager.register(
Expand All @@ -70,54 +73,77 @@ class _HomePageState extends State<HomePage> {
);
}

Widget _buildBody(BuildContext context) {
return PreferenceList(
children: <Widget>[
if (_primaryDisplay != null)
PreferenceListSection(
title: const Text('Primary Display'),
children: [
_DisplayItem(display: _primaryDisplay!),
],
Widget _buildPrimaryDisplay(BuildContext context) {
if (_primaryDisplay != null) {
return _ListSection(
title: const Text('Primary Display'),
children: [
DisplayCard(_primaryDisplay!),
],
);
}
return const SizedBox();
}

Widget _buildAllDisplays(BuildContext context) {
if (_displayList.isNotEmpty) {
return _ListSection(
title: const Text('All Displays'),
children: [
for (var display in _displayList) DisplayCard(display),
],
);
}
return const SizedBox();
}

Widget _buildMethods(BuildContext context) {
return _ListSection(
title: const Text('Methods'),
children: [
Card(
child: ListTile(
title: const Text('getCursorScreenPoint'),
trailing: const Text('Alt+D'),
onTap: _handleGetCursorScreenPoint,
),
if (_displayList.isNotEmpty)
PreferenceListSection(
title: const Text('All Displays'),
children: [
for (var display in _displayList) _DisplayItem(display: display),
],
),
Card(
child: ListTile(
title: const Text('getPrimaryDisplay'),
onTap: () async {
_primaryDisplay = await screenRetriever.getPrimaryDisplay();
setState(() {});
BotToast.showText(
text: 'primaryDisplay: ${_primaryDisplay!.toJson()}',
);
},
),
PreferenceListSection(
title: const Text('Methods'),
children: [
PreferenceListItem(
title: const Text('getCursorScreenPoint'),
detailText: const Text('Alt+D'),
onTap: _handleGetCursorScreenPoint,
),
PreferenceListItem(
title: const Text('getPrimaryDisplay'),
onTap: () async {
_primaryDisplay = await screenRetriever.getPrimaryDisplay();
setState(() {});
BotToast.showText(
text: 'primaryDisplay: ${_primaryDisplay!.toJson()}',
);
},
),
PreferenceListItem(
title: const Text('getAllDisplays'),
onTap: () async {
_displayList = await screenRetriever.getAllDisplays();
setState(() {});
BotToast.showText(
text:
'allDisplays:\n${_displayList.map((e) => e.toJson()).join('\n')}',
);
},
),
],
),
Card(
child: ListTile(
title: const Text('getAllDisplays'),
onTap: () async {
_displayList = await screenRetriever.getAllDisplays();
setState(() {});
BotToast.showText(
text:
'allDisplays:\n${_displayList.map((e) => e.toJson()).join('\n')}',
);
},
),
),
],
);
}

Widget _buildBody(BuildContext context) {
return ListView(
padding: const EdgeInsets.all(16),
children: <Widget>[
_buildPrimaryDisplay(context),
_buildAllDisplays(context),
_buildMethods(context),
],
);
}
Expand All @@ -126,7 +152,7 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
title: const Text('Screen Retriever Example'),
),
body: _buildBody(context),
);
Expand Down
30 changes: 30 additions & 0 deletions packages/screen_retriever/example/lib/widgets/display_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:screen_retriever/screen_retriever.dart';

class DisplayCard extends StatelessWidget {
const DisplayCard(this.display, {super.key});

final Display display;

@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
title: Text('${display.name}'),
subtitle: Text(
[
'id: ${display.id}',
'size: ${display.size}',
'visiblePosition: ${display.visiblePosition}',
'visibleSize: ${display.visibleSize}',
'scaleFactor: ${display.scaleFactor}',
].join('\n'),
),
onTap: () {
BotToast.showText(text: '${display.toJson()}');
},
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80D4294CF70F00263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cocoa
import FlutterMacOS

@NSApplicationMain
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
Expand Down
Loading

0 comments on commit 34f7259

Please sign in to comment.