Skip to content

Commit 4ca6249

Browse files
authored
Nov upgrade (#26)
* Nov upgrade * Nov upgrade
1 parent 121d8c8 commit 4ca6249

13 files changed

+127
-63
lines changed

.github/actions/setup-flutter/action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ runs:
66
steps:
77
- uses: subosito/flutter-action@v2
88
with:
9-
flutter-version: "3.13.8"
9+
flutter-version: "3.16.0"
1010
channel: "stable"
1111
cache: true

.github/workflows/pull_request.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
analyze:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- uses: ./.github/actions/setup-flutter
1414
- run: flutter analyze
1515
- run: dart format -o none --set-exit-if-changed .
@@ -18,6 +18,6 @@ jobs:
1818
needs: analyze
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222
- uses: ./.github/actions/setup-flutter
2323
- run: flutter test

.github/workflows/release_android.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
release-android:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- uses: ./.github/actions/setup-flutter
1414
- name: Build
1515
run: flutter build apk --split-per-abi --release

.github/workflows/release_desktop.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
# build-dir: build/windows/runner/Release
2323
runs-on: ${{ matrix.runs-on }}
2424
steps:
25-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
2626
- uses: ./.github/actions/setup-flutter
2727
- if: ${{ matrix.before-build }}
2828
run: ${{ matrix.before-build }}

.github/workflows/release_web.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
release-web:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- uses: ./.github/actions/setup-flutter
1414
- name: Build
1515
run: flutter build web --no-web-resources-cdn --base-href /mdi/

lib/_data.dart

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:mdi/apps/manual_count.dart';
55
import 'package:mdi/apps/some_grid_view.dart';
66
import 'package:mdi/apps/some_split_view.dart';
77
import 'package:mdi/apps/tik_tak_toe.dart';
8+
import 'package:mdi/apps/use_keyboard.dart';
89
import 'package:mdi/desktop/desktop_app.dart';
910

1011
const groupedApps = <String, List<DesktopApp>>{
@@ -14,6 +15,11 @@ const groupedApps = <String, List<DesktopApp>>{
1415
Icons.insert_drive_file,
1516
TikTakToe(),
1617
),
18+
DesktopApp(
19+
'Use Keyboard',
20+
Icons.keyboard,
21+
UseKeyboard(),
22+
),
1723
],
1824
'Misc': [
1925
DesktopApp(

lib/_extensions/build_context_ext.dart

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ import 'package:flutter/material.dart';
22

33
extension BuildContextExt on BuildContext {
44
TextTheme get tt => Theme.of(this).textTheme;
5+
6+
Size get screenSize => MediaQuery.sizeOf(this);
57
}

lib/apps/tik_tak_toe.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class _TikTakToeState extends State<TikTakToe> {
100100
}
101101
}
102102
if (foundType != null) {
103-
return _showDialog('The Winner is: ${describeEnum(foundType)}');
103+
return _showDialog('The Winner is: ${foundType.name}');
104104
}
105105
}
106106

lib/apps/use_keyboard.dart

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
3+
import 'package:mdi/apps/widgets/simple_grid_view.dart';
4+
5+
const xCount = 41;
6+
const yCount = 31;
7+
8+
class UseKeyboard extends StatefulWidget {
9+
const UseKeyboard();
10+
11+
@override
12+
State<UseKeyboard> createState() => _UseKeyboardState();
13+
}
14+
15+
class _UseKeyboardState extends State<UseKeyboard> {
16+
late final _focus = FocusNode()..requestFocus();
17+
18+
int xCurrent = xCount ~/ 2;
19+
int yCurrent = yCount ~/ 2;
20+
21+
@override
22+
void dispose() {
23+
_focus.dispose();
24+
super.dispose();
25+
}
26+
27+
@override
28+
Widget build(BuildContext context) => RawKeyboardListener(
29+
focusNode: _focus,
30+
onKey: (event) {
31+
if (event.runtimeType == RawKeyDownEvent) {
32+
if (event.logicalKey == LogicalKeyboardKey.arrowUp) {
33+
if (yCurrent != 0) {
34+
setState(() => yCurrent -= 1);
35+
}
36+
} else if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
37+
if (yCurrent != yCount - 1) {
38+
setState(() => yCurrent += 1);
39+
}
40+
} else if (event.logicalKey == LogicalKeyboardKey.arrowLeft) {
41+
if (xCurrent != 0) {
42+
setState(() => xCurrent -= 1);
43+
}
44+
} else if (event.logicalKey == LogicalKeyboardKey.arrowRight) {
45+
if (xCurrent != xCount - 1) {
46+
setState(() => xCurrent += 1);
47+
}
48+
}
49+
}
50+
},
51+
child: SimpleGridView(
52+
columnCount: xCount,
53+
rowCount: yCount,
54+
cellPadding: 0.2,
55+
cellBackgroundColor: Colors.blueAccent,
56+
cellBuilder: (context, xIndex, yIndex) =>
57+
xIndex == xCurrent && yIndex == yCurrent
58+
? const ColoredBox(color: Colors.red)
59+
: const SizedBox(),
60+
),
61+
);
62+
}

lib/desktop/desktop.dart

+16-26
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ class _DesktopState extends State<Desktop> {
6565
}
6666
}
6767

68-
void _addWindow(
69-
DesktopApp desktopApp,
70-
double screenWidth,
71-
double screenHeight,
72-
) {
68+
void _addWindow(DesktopApp desktopApp) {
7369
final key = UniqueKey();
7470
final window = Window(
7571
key: key,
@@ -90,8 +86,6 @@ class _DesktopState extends State<Desktop> {
9086
width: desktopApp.width,
9187
height: desktopApp.height,
9288
isFixedSize: desktopApp.isFixedSize,
93-
screenWidth: screenWidth,
94-
screenHeight: screenHeight,
9589
);
9690
setState(() {
9791
_windowKeys.add(key);
@@ -103,23 +97,19 @@ class _DesktopState extends State<Desktop> {
10397
Widget build(BuildContext context) {
10498
final groupedApps = widget.groupedApps;
10599
final standaloneApps = widget.standaloneApps;
106-
return LayoutBuilder(
107-
builder: (context, constraints) => Stack(
108-
fit: StackFit.expand,
109-
children: [
110-
if (groupedApps.isNotEmpty || standaloneApps.isNotEmpty)
111-
DesktopItems(
112-
groupedApps: groupedApps,
113-
standaloneApps: standaloneApps,
114-
onItemTap: (desktopApp) => _addWindow(
115-
desktopApp,
116-
constraints.maxWidth,
117-
constraints.maxHeight,
118-
),
119-
),
120-
..._windows.values,
121-
if (_windows.isNotEmpty)
122-
Dock(
100+
return Stack(
101+
fit: StackFit.expand,
102+
children: [
103+
if (groupedApps.isNotEmpty || standaloneApps.isNotEmpty)
104+
DesktopItems(
105+
groupedApps: groupedApps,
106+
standaloneApps: standaloneApps,
107+
onItemTap: _addWindow,
108+
),
109+
..._windows.values,
110+
if (_windows.isNotEmpty)
111+
ExcludeFocus(
112+
child: Dock(
123113
windowKeys: _windowKeys,
124114
minimizedWindowKeys: _minimizedWindowKeys,
125115
windows: _windows,
@@ -128,8 +118,8 @@ class _DesktopState extends State<Desktop> {
128118
_rebuildOnChange();
129119
},
130120
),
131-
],
132-
),
121+
),
122+
],
133123
);
134124
}
135125
}

lib/window/window.dart

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// ignore_for_file: avoid_multiple_declarations_per_line
21
import 'dart:async';
32
import 'dart:math';
43

54
import 'package:flutter/scheduler.dart';
65
import 'package:flutter/widgets.dart';
6+
import 'package:mdi/_extensions/build_context_ext.dart';
77
import 'package:mdi/_prefs.dart';
88
import 'package:mdi/window/title_bar.dart';
99

@@ -19,11 +19,7 @@ class Window extends StatefulWidget {
1919
required this.width,
2020
required this.height,
2121
required this.isFixedSize,
22-
required double screenWidth,
23-
required double screenHeight,
24-
}) : availableWidth = screenWidth + windowOuterPaddingTimes2,
25-
availableHeight = screenHeight - dockHeight + windowOuterPaddingTimes2,
26-
super(key: key);
22+
}) : super(key: key);
2723

2824
final String title;
2925
final Widget app;
@@ -35,8 +31,6 @@ class Window extends StatefulWidget {
3531
final double? width;
3632
final double? height;
3733
final bool isFixedSize;
38-
final double availableWidth;
39-
final double availableHeight;
4034

4135
@override
4236
State<Window> createState() => _WindowState();
@@ -53,6 +47,14 @@ class _WindowState extends State<Window> {
5347

5448
late final StreamSubscription<void> _unHideWindowSubscription;
5549

50+
(double, double) get _availableSize {
51+
final screenSize = context.screenSize;
52+
return (
53+
screenSize.width + windowOuterPaddingTimes2,
54+
screenSize.height - dockHeight + windowOuterPaddingTimes2,
55+
);
56+
}
57+
5658
@override
5759
void initState() {
5860
super.initState();
@@ -62,13 +64,14 @@ class _WindowState extends State<Window> {
6264
.listen((_) => _toggleMinimize());
6365

6466
SchedulerBinding.instance.addPostFrameCallback((_) {
67+
final (availableWidth, availableHeight) = _availableSize;
6568
setState(() {
66-
_width = widget.width ?? widget.availableWidth * 0.6;
67-
_height = widget.height ?? widget.availableHeight * 0.6;
69+
_width = widget.width ?? availableWidth * 0.6;
70+
_height = widget.height ?? availableHeight * 0.6;
6871
_checkMinSize();
6972

70-
_dx = _random.nextDouble() * (widget.availableWidth - _width);
71-
_dy = _random.nextDouble() * (widget.availableHeight - _height);
73+
_dx = _random.nextDouble() * (availableWidth - _width);
74+
_dy = _random.nextDouble() * (availableHeight - _height);
7275
});
7376
});
7477
}
@@ -133,8 +136,9 @@ class _WindowState extends State<Window> {
133136
_dxLast = _dx;
134137
_dyLast = _dy;
135138

136-
_width = widget.availableWidth;
137-
_height = widget.availableHeight;
139+
final (availableWidth, availableHeight) = _availableSize;
140+
_width = availableWidth;
141+
_height = availableHeight;
138142
_dx = _dy = -windowOuterPadding;
139143
}
140144
});

pubspec.lock

+14-14
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: collection
40-
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
40+
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "1.17.2"
43+
version: "1.18.0"
4444
fake_async:
4545
dependency: transitive
4646
description:
@@ -79,10 +79,10 @@ packages:
7979
dependency: transitive
8080
description:
8181
name: meta
82-
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
82+
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
8383
url: "https://pub.dev"
8484
source: hosted
85-
version: "1.9.1"
85+
version: "1.10.0"
8686
path:
8787
dependency: transitive
8888
description:
@@ -108,18 +108,18 @@ packages:
108108
dependency: transitive
109109
description:
110110
name: stack_trace
111-
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
111+
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
112112
url: "https://pub.dev"
113113
source: hosted
114-
version: "1.11.0"
114+
version: "1.11.1"
115115
stream_channel:
116116
dependency: transitive
117117
description:
118118
name: stream_channel
119-
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
119+
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
120120
url: "https://pub.dev"
121121
source: hosted
122-
version: "2.1.1"
122+
version: "2.1.2"
123123
string_scanner:
124124
dependency: transitive
125125
description:
@@ -140,10 +140,10 @@ packages:
140140
dependency: transitive
141141
description:
142142
name: test_api
143-
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
143+
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
144144
url: "https://pub.dev"
145145
source: hosted
146-
version: "0.6.0"
146+
version: "0.6.1"
147147
vector_math:
148148
dependency: transitive
149149
description:
@@ -164,10 +164,10 @@ packages:
164164
dependency: transitive
165165
description:
166166
name: web
167-
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
167+
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
168168
url: "https://pub.dev"
169169
source: hosted
170-
version: "0.1.4-beta"
170+
version: "0.3.0"
171171
sdks:
172-
dart: ">=3.1.4 <4.0.0"
173-
flutter: ">=3.13.8"
172+
dart: ">=3.2.0 <4.0.0"
173+
flutter: ">=3.16.0"

pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ description: Some widgets playground based on a desktop like UI.
33
version: 0.0.10
44

55
environment:
6-
sdk: ">=3.1.4 <4.0.0"
7-
flutter: ">=3.13.8"
6+
sdk: ">=3.2.0 <4.0.0"
7+
flutter: ">=3.16.0"
88

99
dependencies:
1010
flutter:

0 commit comments

Comments
 (0)