add type to all Getx put/get/delete/isRegistered (#8550)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2024-06-30 21:24:18 +08:00 committed by GitHub
parent 15fa80fb26
commit 763174657b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 62 additions and 60 deletions

View File

@ -1428,7 +1428,7 @@ Future<void> initGlobalFFI() async {
_globalFFI = FFI(null); _globalFFI = FFI(null);
debugPrint("_globalFFI init end"); debugPrint("_globalFFI init end");
// after `put`, can also be globally found by Get.find<FFI>(); // after `put`, can also be globally found by Get.find<FFI>();
Get.put(_globalFFI, permanent: true); Get.put<FFI>(_globalFFI, permanent: true);
} }
String translate(String name) { String translate(String name) {

View File

@ -10,16 +10,16 @@ class PrivacyModeState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxString>(tag: key)) {
final RxString state = ''.obs; final RxString state = ''.obs;
Get.put(state, tag: key); Get.put<RxString>(state, tag: key);
} }
} }
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxString>(tag: key)) {
Get.delete(tag: key); Get.delete<RxString>(tag: key);
} else { } else {
Get.find<RxString>(tag: key).value = ''; Get.find<RxString>(tag: key).value = '';
} }
@ -33,9 +33,9 @@ class BlockInputState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxBool>(tag: key)) {
final RxBool state = false.obs; final RxBool state = false.obs;
Get.put(state, tag: key); Get.put<RxBool>(state, tag: key);
} else { } else {
Get.find<RxBool>(tag: key).value = false; Get.find<RxBool>(tag: key).value = false;
} }
@ -43,8 +43,8 @@ class BlockInputState {
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxBool>(tag: key)) {
Get.delete(tag: key); Get.delete<RxBool>(tag: key);
} }
} }
@ -56,9 +56,9 @@ class CurrentDisplayState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxInt>(tag: key)) {
final RxInt state = RxInt(0); final RxInt state = RxInt(0);
Get.put(state, tag: key); Get.put<RxInt>(state, tag: key);
} else { } else {
Get.find<RxInt>(tag: key).value = 0; Get.find<RxInt>(tag: key).value = 0;
} }
@ -66,8 +66,8 @@ class CurrentDisplayState {
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxInt>(tag: key)) {
Get.delete(tag: key); Get.delete<RxInt>(tag: key);
} }
} }
@ -105,16 +105,16 @@ class ConnectionTypeState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<ConnectionType>(tag: key)) {
final ConnectionType collectionType = ConnectionType(); final ConnectionType collectionType = ConnectionType();
Get.put(collectionType, tag: key); Get.put<ConnectionType>(collectionType, tag: key);
} }
} }
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<ConnectionType>(tag: key)) {
Get.delete(tag: key); Get.delete<ConnectionType>(tag: key);
} }
} }
@ -127,9 +127,9 @@ class FingerprintState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxString>(tag: key)) {
final RxString state = ''.obs; final RxString state = ''.obs;
Get.put(state, tag: key); Get.put<RxString>(state, tag: key);
} else { } else {
Get.find<RxString>(tag: key).value = ''; Get.find<RxString>(tag: key).value = '';
} }
@ -137,8 +137,8 @@ class FingerprintState {
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxString>(tag: key)) {
Get.delete(tag: key); Get.delete<RxString>(tag: key);
} }
} }
@ -150,9 +150,9 @@ class ShowRemoteCursorState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxBool>(tag: key)) {
final RxBool state = false.obs; final RxBool state = false.obs;
Get.put(state, tag: key); Get.put<RxBool>(state, tag: key);
} else { } else {
Get.find<RxBool>(tag: key).value = false; Get.find<RxBool>(tag: key).value = false;
} }
@ -160,8 +160,8 @@ class ShowRemoteCursorState {
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxBool>(tag: key)) {
Get.delete(tag: key); Get.delete<RxBool>(tag: key);
} }
} }
@ -173,9 +173,9 @@ class ShowRemoteCursorLockState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxBool>(tag: key)) {
final RxBool state = false.obs; final RxBool state = false.obs;
Get.put(state, tag: key); Get.put<RxBool>(state, tag: key);
} else { } else {
Get.find<RxBool>(tag: key).value = false; Get.find<RxBool>(tag: key).value = false;
} }
@ -183,8 +183,8 @@ class ShowRemoteCursorLockState {
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxBool>(tag: key)) {
Get.delete(tag: key); Get.delete<RxBool>(tag: key);
} }
} }
@ -196,10 +196,10 @@ class KeyboardEnabledState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxBool>(tag: key)) {
// Server side, default true // Server side, default true
final RxBool state = true.obs; final RxBool state = true.obs;
Get.put(state, tag: key); Get.put<RxBool>(state, tag: key);
} else { } else {
Get.find<RxBool>(tag: key).value = true; Get.find<RxBool>(tag: key).value = true;
} }
@ -207,8 +207,8 @@ class KeyboardEnabledState {
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxBool>(tag: key)) {
Get.delete(tag: key); Get.delete<RxBool>(tag: key);
} }
} }
@ -220,9 +220,9 @@ class RemoteCursorMovedState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxBool>(tag: key)) {
final RxBool state = false.obs; final RxBool state = false.obs;
Get.put(state, tag: key); Get.put<RxBool>(state, tag: key);
} else { } else {
Get.find<RxBool>(tag: key).value = false; Get.find<RxBool>(tag: key).value = false;
} }
@ -230,8 +230,8 @@ class RemoteCursorMovedState {
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxBool>(tag: key)) {
Get.delete(tag: key); Get.delete<RxBool>(tag: key);
} }
} }
@ -243,9 +243,9 @@ class RemoteCountState {
static void init() { static void init() {
final key = tag(); final key = tag();
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxInt>(tag: key)) {
final RxInt state = 1.obs; final RxInt state = 1.obs;
Get.put(state, tag: key); Get.put<RxInt>(state, tag: key);
} else { } else {
Get.find<RxInt>(tag: key).value = 1; Get.find<RxInt>(tag: key).value = 1;
} }
@ -253,8 +253,8 @@ class RemoteCountState {
static void delete() { static void delete() {
final key = tag(); final key = tag();
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxInt>(tag: key)) {
Get.delete(tag: key); Get.delete<RxInt>(tag: key);
} }
} }
@ -266,9 +266,9 @@ class PeerBoolOption {
static void init(String id, String opt, bool Function() init_getter) { static void init(String id, String opt, bool Function() init_getter) {
final key = tag(id, opt); final key = tag(id, opt);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxBool>(tag: key)) {
final RxBool value = RxBool(init_getter()); final RxBool value = RxBool(init_getter());
Get.put(value, tag: key); Get.put<RxBool>(value, tag: key);
} else { } else {
Get.find<RxBool>(tag: key).value = init_getter(); Get.find<RxBool>(tag: key).value = init_getter();
} }
@ -276,8 +276,8 @@ class PeerBoolOption {
static void delete(String id, String opt) { static void delete(String id, String opt) {
final key = tag(id, opt); final key = tag(id, opt);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxBool>(tag: key)) {
Get.delete(tag: key); Get.delete<RxBool>(tag: key);
} }
} }
@ -290,9 +290,9 @@ class PeerStringOption {
static void init(String id, String opt, String Function() init_getter) { static void init(String id, String opt, String Function() init_getter) {
final key = tag(id, opt); final key = tag(id, opt);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxString>(tag: key)) {
final RxString value = RxString(init_getter()); final RxString value = RxString(init_getter());
Get.put(value, tag: key); Get.put<RxString>(value, tag: key);
} else { } else {
Get.find<RxString>(tag: key).value = init_getter(); Get.find<RxString>(tag: key).value = init_getter();
} }
@ -300,8 +300,8 @@ class PeerStringOption {
static void delete(String id, String opt) { static void delete(String id, String opt) {
final key = tag(id, opt); final key = tag(id, opt);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxString>(tag: key)) {
Get.delete(tag: key); Get.delete<RxString>(tag: key);
} }
} }
@ -314,9 +314,9 @@ class UnreadChatCountState {
static void init(String id) { static void init(String id) {
final key = tag(id); final key = tag(id);
if (!Get.isRegistered(tag: key)) { if (!Get.isRegistered<RxInt>(tag: key)) {
final RxInt state = RxInt(0); final RxInt state = RxInt(0);
Get.put(state, tag: key); Get.put<RxInt>(state, tag: key);
} else { } else {
Get.find<RxInt>(tag: key).value = 0; Get.find<RxInt>(tag: key).value = 0;
} }
@ -324,8 +324,8 @@ class UnreadChatCountState {
static void delete(String id) { static void delete(String id) {
final key = tag(id); final key = tag(id);
if (Get.isRegistered(tag: key)) { if (Get.isRegistered<RxInt>(tag: key)) {
Get.delete(tag: key); Get.delete<RxInt>(tag: key);
} }
} }

View File

@ -84,8 +84,10 @@ class DesktopSettingPage extends StatefulWidget {
} }
if (Get.isRegistered<PageController>(tag: _kSettingPageControllerTag)) { if (Get.isRegistered<PageController>(tag: _kSettingPageControllerTag)) {
DesktopTabPage.onAddSetting(initialPage: page); DesktopTabPage.onAddSetting(initialPage: page);
PageController controller = Get.find(tag: _kSettingPageControllerTag); PageController controller =
Rx<SettingsTabKey> selected = Get.find(tag: _kSettingPageTabKeyTag); Get.find<PageController>(tag: _kSettingPageControllerTag);
Rx<SettingsTabKey> selected =
Get.find<Rx<SettingsTabKey>>(tag: _kSettingPageTabKeyTag);
selected.value = page; selected.value = page;
controller.jumpToPage(index); controller.jumpToPage(index);
} else { } else {

View File

@ -20,7 +20,7 @@ class DesktopTabPage extends StatefulWidget {
static void onAddSetting( static void onAddSetting(
{SettingsTabKey initialPage = SettingsTabKey.general}) { {SettingsTabKey initialPage = SettingsTabKey.general}) {
try { try {
DesktopTabController tabController = Get.find(); DesktopTabController tabController = Get.find<DesktopTabController>();
tabController.add(TabInfo( tabController.add(TabInfo(
key: kTabLabelSettingPage, key: kTabLabelSettingPage,
label: kTabLabelSettingPage, label: kTabLabelSettingPage,

View File

@ -92,7 +92,7 @@ class _FileManagerPageState extends State<FileManagerPage>
_ffi.dialogManager _ffi.dialogManager
.showLoading(translate('Connecting...'), onCancel: closeConnection); .showLoading(translate('Connecting...'), onCancel: closeConnection);
}); });
Get.put(_ffi, tag: 'ft_${widget.id}'); Get.put<FFI>(_ffi, tag: 'ft_${widget.id}');
if (!isLinux) { if (!isLinux) {
WakelockPlus.enable(); WakelockPlus.enable();
} }

View File

@ -63,7 +63,7 @@ class _PortForwardPageState extends State<PortForwardPage>
isSharedPassword: widget.isSharedPassword, isSharedPassword: widget.isSharedPassword,
forceRelay: widget.forceRelay, forceRelay: widget.forceRelay,
isRdp: widget.isRDP); isRdp: widget.isRDP);
Get.put(_ffi, tag: 'pf_${widget.id}'); Get.put<FFI>(_ffi, tag: 'pf_${widget.id}');
debugPrint("Port forward page init success with id ${widget.id}"); debugPrint("Port forward page init success with id ${widget.id}");
widget.tabController.onSelected?.call(widget.id); widget.tabController.onSelected?.call(widget.id);
} }

View File

@ -107,7 +107,7 @@ class _RemotePageState extends State<RemotePage>
super.initState(); super.initState();
_initStates(widget.id); _initStates(widget.id);
_ffi = FFI(widget.sessionId); _ffi = FFI(widget.sessionId);
Get.put(_ffi, tag: widget.id); Get.put<FFI>(_ffi, tag: widget.id);
_ffi.imageModel.addCallbackOnFirstImage((String peerId) { _ffi.imageModel.addCallbackOnFirstImage((String peerId) {
showKBLayoutTypeChooserIfNeeded( showKBLayoutTypeChooserIfNeeded(
_ffi.ffiModel.pi.platform, _ffi.dialogManager); _ffi.ffiModel.pi.platform, _ffi.dialogManager);

View File

@ -36,7 +36,7 @@ class _DesktopServerPageState extends State<DesktopServerPage>
void initState() { void initState() {
gFFI.ffiModel.updateEventListener(gFFI.sessionId, ""); gFFI.ffiModel.updateEventListener(gFFI.sessionId, "");
windowManager.addListener(this); windowManager.addListener(this);
Get.put(tabController); Get.put<DesktopTabController>(tabController);
tabController.onRemoved = (_, id) { tabController.onRemoved = (_, id) {
onRemoveId(id); onRemoveId(id);
}; };