migrate: riverpod + freezed (#870)

This commit is contained in:
lollipopkit🏳️‍⚧️
2025-08-31 00:55:54 +08:00
committed by GitHub
parent 9cb705f8dd
commit 53a7c0d8ff
67 changed files with 5012 additions and 1328 deletions

View File

@@ -1,56 +1,63 @@
import 'package:flutter/widgets.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:server_box/data/res/store.dart';
import 'package:xterm/core.dart';
class VirtKeyProvider extends TerminalInputHandler with ChangeNotifier {
VirtKeyProvider();
part 'virtual_keyboard.g.dart';
part 'virtual_keyboard.freezed.dart';
bool _ctrl = false;
bool get ctrl => _ctrl;
set ctrl(bool value) {
if (value != _ctrl) {
_ctrl = value;
notifyListeners();
@freezed
abstract class VirtKeyState with _$VirtKeyState {
const factory VirtKeyState({
@Default(false) final bool ctrl,
@Default(false) final bool alt,
@Default(false) final bool shift,
}) = _VirtKeyState;
}
@riverpod
class VirtKeyboard extends _$VirtKeyboard implements TerminalInputHandler {
@override
VirtKeyState build() {
return const VirtKeyState();
}
bool get ctrl => state.ctrl;
bool get alt => state.alt;
bool get shift => state.shift;
void setCtrl(bool value) {
if (value != state.ctrl) {
state = state.copyWith(ctrl: value);
}
}
bool _alt = false;
bool get alt => _alt;
set alt(bool value) {
if (value != _alt) {
_alt = value;
notifyListeners();
void setAlt(bool value) {
if (value != state.alt) {
state = state.copyWith(alt: value);
}
}
bool _shift = false;
bool get shift => _shift;
set shift(bool value) {
if (value != _shift) {
_shift = value;
notifyListeners();
void setShift(bool value) {
if (value != state.shift) {
state = state.copyWith(shift: value);
}
}
void reset(TerminalKeyboardEvent e) {
if (e.ctrl) {
ctrl = false;
}
if (e.alt) {
alt = false;
}
if (e.shift) {
shift = false;
}
notifyListeners();
state = state.copyWith(
ctrl: e.ctrl ? false : state.ctrl,
alt: e.alt ? false : state.alt,
shift: e.shift ? false : state.shift,
);
}
@override
String? call(TerminalKeyboardEvent event) {
final e = event.copyWith(
ctrl: event.ctrl || ctrl,
alt: event.alt || alt,
shift: event.shift || shift,
ctrl: event.ctrl || state.ctrl,
alt: event.alt || state.alt,
shift: event.shift || state.shift,
);
if (Stores.setting.sshVirtualKeyAutoOff.fetch()) {
reset(e);