Skip to content

Commit 451d383

Browse files
committed
Fix windows version detection
1 parent 604ebd3 commit 451d383

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/src/theme.dart

+22-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ RoundedRectangleBorder get _roundedShape {
130130
);
131131
}
132132

133+
bool isNumeric(String s) {
134+
if (s == null) {
135+
return false;
136+
}
137+
return double.tryParse(s) != null;
138+
}
139+
140+
double getWindowsBuild() {
141+
final osVer =
142+
Platform.operatingSystemVersion.replaceAll(RegExp(r'[^\w\s\.]+'), '');
143+
144+
final splitOsVer = osVer.split(' ');
145+
146+
final nums = splitOsVer.where((element) => isNumeric(element)).toList();
147+
return double.parse(nums.last);
148+
}
149+
133150
Color platformBackgroundColor(BuildContext context) {
134151
final themeBrightness = Theme.of(context).brightness;
135152
final platformBrightness = MediaQuery.of(context).platformBrightness;
@@ -140,13 +157,15 @@ Color platformBackgroundColor(BuildContext context) {
140157
if (Platform.isMacOS) {
141158
return Colors.transparent;
142159
} else if (Platform.isWindows) {
143-
if (Platform.operatingSystemVersion.contains('11')) {
160+
if (getWindowsBuild() >= 22449) {
161+
print("Windows 11");
144162
Window.setEffect(
145163
effect: WindowEffect.mica,
146-
color: Theme.of(context).cardColor.withAlpha(140),
164+
color: Colors.transparent,
147165
);
148166
return Colors.transparent;
149-
} else if (Platform.operatingSystemVersion.contains('10')) {
167+
} else if (getWindowsBuild() >= 10240) {
168+
print("Windows 10");
150169
Window.setEffect(
151170
effect: WindowEffect.aero,
152171
color: Theme.of(context).cardColor.withAlpha(220),

0 commit comments

Comments
 (0)