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,16 +6,15 @@ 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((screenFrame.width / 2).roundToDouble(), width = math.max(
kMinInitialWindowWidth); (screenFrame.width / 2).roundToDouble(), kMinInitialWindowWidth);
height = math.max((screenFrame.height / 2).roundToDouble(), height = math.max((screenFrame.height / 2).roundToDouble(),
kMinInitialWindowHeight); kMinInitialWindowHeight);
} else { } else {
@ -34,23 +32,21 @@ Future<void> setupInitialWindow(Size? sz) async {
}); });
} }
} }
}
Future<void> resetWindowSize() async { Future<void> resetWindowSize() async {
await setupWindow(center: true); await setupWindow(center: true);
} }
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((screenFrame.width / 2).roundToDouble(), width = math.max(
kMinInitialWindowWidth); (screenFrame.width / 2).roundToDouble(), kMinInitialWindowWidth);
height = math.max((screenFrame.height / 2).roundToDouble(), height = math.max((screenFrame.height / 2).roundToDouble(),
kMinInitialWindowHeight); kMinInitialWindowHeight);
} }
@ -67,16 +63,14 @@ Future<void> setupWindow({Size? sz, Offset? off, bool center = false}) async {
minimumSize: kMinWindowSize, minimumSize: kMinWindowSize,
skipTaskbar: false, skipTaskbar: false,
title: kWindowTitle, title: kWindowTitle,
titleBarStyle: Platform.isMacOS ? TitleBarStyle.hidden : null, titleBarStyle: kIsMacOS ? TitleBarStyle.hidden : null,
); );
if (off != null) { if (off != null) {
await windowManager.setPosition(off); await windowManager.setPosition(off);
} }
windowManager.waitUntilReadyToShow(windowOptions, () async { windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show(); await windowManager.show();
await windowManager.focus(); await windowManager.focus();
}); });
} }
} }
}