mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-06-24 14:20:37 -04:00
home layout
This commit is contained in:
parent
f754f7d5ed
commit
ca6b00e021
45 changed files with 2168 additions and 561 deletions
83
lib/providers/window_control.dart
Normal file
83
lib/providers/window_control.dart
Normal file
|
@ -0,0 +1,83 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../tools/responsive.dart';
|
||||
|
||||
export 'package:window_manager/window_manager.dart' show TitleBarStyle;
|
||||
|
||||
part 'window_control.g.dart';
|
||||
|
||||
enum OrientationCapability {
|
||||
normal,
|
||||
portraitOnly,
|
||||
landscapeOnly,
|
||||
}
|
||||
|
||||
// Local account manager
|
||||
@riverpod
|
||||
class WindowControl extends _$WindowControl {
|
||||
/// Change window control
|
||||
@override
|
||||
FutureOr<bool> build() async {
|
||||
await _doWindowSetup(TitleBarStyle.hidden, OrientationCapability.normal);
|
||||
return true;
|
||||
}
|
||||
|
||||
static Future<void> initialize() async {
|
||||
if (isDesktop) {
|
||||
await windowManager.ensureInitialized();
|
||||
|
||||
const windowOptions = WindowOptions(
|
||||
size: Size(768, 1024),
|
||||
//minimumSize: Size(480, 640),
|
||||
center: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
skipTaskbar: false,
|
||||
);
|
||||
await windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _doWindowSetup(TitleBarStyle titleBarStyle,
|
||||
OrientationCapability orientationCapability) async {
|
||||
if (isDesktop) {
|
||||
await windowManager.setTitleBarStyle(titleBarStyle);
|
||||
} else {
|
||||
switch (orientationCapability) {
|
||||
case OrientationCapability.normal:
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
case OrientationCapability.portraitOnly:
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
]);
|
||||
case OrientationCapability.landscapeOnly:
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
/// Mutators and Selectors
|
||||
|
||||
/// Reorder accounts
|
||||
Future<void> changeWindowSetup(TitleBarStyle titleBarStyle,
|
||||
OrientationCapability orientationCapability) async {
|
||||
state = const AsyncValue.loading();
|
||||
await _doWindowSetup(titleBarStyle, orientationCapability);
|
||||
state = const AsyncValue.data(true);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue