Platform specific constants and changes

This commit is contained in:
Ankit Mahato
2023-04-27 07:45:40 +05:30
parent 25813ae238
commit 315af01593
4 changed files with 63 additions and 63 deletions

View File

@ -9,6 +9,11 @@ const kDiscordUrl = "https://bit.ly/heyfoss";
const kGitUrl = "https://github.com/foss42/api-dash"; const kGitUrl = "https://github.com/foss42/api-dash";
const kIssueUrl = "$kGitUrl/issues"; const kIssueUrl = "$kGitUrl/issues";
final kIsMacOS = Platform.isMacOS;
final kIsWindows = Platform.isWindows;
final kIsLinux = Platform.isLinux;
final kIsDesktop = kIsMacOS || kIsWindows || kIsLinux;
final kColorTransparentState = final kColorTransparentState =
MaterialStateProperty.all<Color>(Colors.transparent); MaterialStateProperty.all<Color>(Colors.transparent);
const kColorTransparent = Colors.transparent; const kColorTransparent = Colors.transparent;
@ -46,6 +51,7 @@ const kPs8 = EdgeInsets.only(left: 8);
const kPh20v5 = EdgeInsets.symmetric(horizontal: 20, vertical: 5); const kPh20v5 = EdgeInsets.symmetric(horizontal: 20, vertical: 5);
const kPh20v10 = EdgeInsets.symmetric(horizontal: 20, vertical: 10); const kPh20v10 = EdgeInsets.symmetric(horizontal: 20, vertical: 10);
const kP10 = EdgeInsets.all(10); const kP10 = EdgeInsets.all(10);
const kPt24o8 = EdgeInsets.only(top: 24, left: 8.0, right: 8.0, bottom: 8.0);
const kPt5o10 = const kPt5o10 =
EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0, bottom: 10.0); EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0, bottom: 10.0);

View File

@ -31,7 +31,7 @@ class _CollectionPaneState extends ConsumerState<CollectionPane> {
); );
} }
return Padding( return Padding(
padding: kP8, padding: kIsMacOS ? kPt24o8 : kP8,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [

View File

@ -28,7 +28,7 @@ class _RequestEditorPaneState extends ConsumerState<RequestEditorPane> {
return const RequestEditorPaneHome(); return const RequestEditorPaneHome();
} else { } else {
return Padding( return Padding(
padding: kP8, padding: kIsMacOS ? kPt24o8 : kP8,
child: Column( child: Column(
children: const [ children: const [
EditorPaneRequestURLCard(), EditorPaneRequestURLCard(),

View File

@ -1,4 +1,3 @@
import 'dart:io';
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -7,32 +6,30 @@ import 'package:window_manager/window_manager.dart';
import '../consts.dart'; import '../consts.dart';
Future<void> setupInitialWindow(Size? sz) async { Future<void> setupInitialWindow(Size? sz) async {
if (!kIsWeb) { if (!kIsWeb && kIsDesktop) {
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { await window_size.getWindowInfo().then((window) {
await window_size.getWindowInfo().then((window) { final screen = window.screen;
final screen = window.screen; if (screen != null) {
if (screen != null) { final screenFrame = screen.visibleFrame;
final screenFrame = screen.visibleFrame; double width, height;
double width, height; if (sz == null) {
if (sz == null) { width = math.max(
width = math.max((screenFrame.width / 2).roundToDouble(), (screenFrame.width / 2).roundToDouble(), kMinInitialWindowWidth);
kMinInitialWindowWidth); height = math.max((screenFrame.height / 2).roundToDouble(),
height = math.max((screenFrame.height / 2).roundToDouble(), kMinInitialWindowHeight);
kMinInitialWindowHeight); } else {
} else { width = sz.width;
width = sz.width; height = sz.height;
height = sz.height;
}
final left = ((screenFrame.width - width) / 2).roundToDouble();
final top = ((screenFrame.height - height) / 3).roundToDouble();
final frame = Rect.fromLTWH(left, top, width, height);
window_size.setWindowFrame(frame);
window_size.setWindowMinSize(kMinWindowSize);
window_size.setWindowMaxSize(Size.infinite);
window_size.setWindowTitle(kWindowTitle);
} }
}); final left = ((screenFrame.width - width) / 2).roundToDouble();
} final top = ((screenFrame.height - height) / 3).roundToDouble();
final frame = Rect.fromLTWH(left, top, width, height);
window_size.setWindowFrame(frame);
window_size.setWindowMinSize(kMinWindowSize);
window_size.setWindowMaxSize(Size.infinite);
window_size.setWindowTitle(kWindowTitle);
}
});
} }
} }
@ -41,42 +38,39 @@ Future<void> resetWindowSize() async {
} }
Future<void> setupWindow({Size? sz, Offset? off, bool center = false}) async { Future<void> setupWindow({Size? sz, Offset? off, bool center = false}) async {
if (!kIsWeb) { if (!kIsWeb && kIsDesktop) {
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { double width = kMinInitialWindowWidth, height = kMinInitialWindowHeight;
double width = kMinInitialWindowWidth, height = kMinInitialWindowHeight; if (sz == null) {
if (sz == null) { await window_size.getWindowInfo().then((window) {
await window_size.getWindowInfo().then((window) { final screen = window.screen;
final screen = window.screen; if (screen != null) {
if (screen != null) { final screenFrame = screen.visibleFrame;
final screenFrame = screen.visibleFrame; width = math.max(
width = math.max((screenFrame.width / 2).roundToDouble(), (screenFrame.width / 2).roundToDouble(), kMinInitialWindowWidth);
kMinInitialWindowWidth); height = math.max((screenFrame.height / 2).roundToDouble(),
height = math.max((screenFrame.height / 2).roundToDouble(), kMinInitialWindowHeight);
kMinInitialWindowHeight); }
}
});
} else {
width = sz.width;
height = sz.height;
}
await windowManager.ensureInitialized();
WindowOptions windowOptions = WindowOptions(
size: Size(width, height),
center: center,
minimumSize: kMinWindowSize,
skipTaskbar: false,
title: kWindowTitle,
titleBarStyle: Platform.isMacOS ? TitleBarStyle.hidden : null,
);
if (off != null) {
await windowManager.setPosition(off);
}
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
}); });
} else {
width = sz.width;
height = sz.height;
} }
await windowManager.ensureInitialized();
WindowOptions windowOptions = WindowOptions(
size: Size(width, height),
center: center,
minimumSize: kMinWindowSize,
skipTaskbar: false,
title: kWindowTitle,
titleBarStyle: kIsMacOS ? TitleBarStyle.hidden : null,
);
if (off != null) {
await windowManager.setPosition(off);
}
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
} }
} }