jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.33k stars 1.62k forks source link

onClose not working after update #583

Closed Eng-MohamedGadala closed 4 years ago

Eng-MohamedGadala commented 4 years ago

Describe the bug @override onClose{ SystemChannels.textInput.invokeMethod('TextInput.hide'); } not working after upgrade to get: ^3.8.0

Flutter Version: Flutter 1.21.0-9.2.pre • channel beta

Getx Version: get: ^3.8.0

Minimal reproduce code @override onClose{ SystemChannels.textInput.invokeMethod('TextInput.hide'); }

eduardoflorence commented 4 years ago

The new sintax is:

@override
Future<void> onClose() {
  SystemChannels.textInput.invokeMethod('TextInput.hide');
  return super.onClose();
}
jonataslaw commented 4 years ago

I will change "Future" by FutureOr to prevent sintaxes errors. Thanks @eduardoflorence !

Eng-MohamedGadala commented 4 years ago

`class LoginController extends GetxController { AuthProvider authProvider = AuthProvider(); final RegExp p1 = RegExp(regex.passwordEasy); String userName; String password; bool isUserVerivid; bool isUserLogin; bool isFormValid; String qrCode; // List isSelected = [true, false]; @override onInit() { isFormValid = false; isUserLogin = false; super.onInit(); }

@override Future onClose() { SystemChannels.textInput.invokeMethod('TextInput.hide'); return super.onClose(); }` thanks but it doesn't work underline red color in onClose() and super.onClose(). how can I override onClose in a true way.

Eng-MohamedGadala commented 4 years ago

Screen Shot 2020-09-09 at 9 40 59 PM

Grohden commented 4 years ago

@jonataslaw @eduardoflorence I'm pretty sure that future is not the return yet.

Edit: oh, there's the latest tagged version DisposableInterface with FutureOr, but I don't get any warnings about that in my code using latest version 🤔

And void is still accepted (if you're refering to my PR on type analyzer stuff I've used FutureOR, so void is acceptable)

@Eng-MohamedGadala try using this: (and be sure that the super.onClose(); is always the latest call):

  @override
  void onClose() {
    SystemChannels.textInput.invokeMethod('TextInput.hide');
    super.onClose();
  }

Do you still get errors with the above signature?

Eng-MohamedGadala commented 4 years ago

Screen Shot 2020-09-09 at 9 54 10 PM Thanks but still not working if I change Future to FutureOR only error hide from super.onClose(); but still on onClose()

Grohden commented 4 years ago

@Eng-MohamedGadala which message is reported to you when you hover your mouse at those red lines?

Grohden commented 4 years ago

oh, unless I looked at the wrong version:

  @override
  void onClose() async {
    SystemChannels.textInput.invokeMethod('TextInput.hide');
    super.onClose();
  }

hopefully solves it

Eng-MohamedGadala commented 4 years ago

@Grohden when hold on super.onClose();

package:get/src/state_manager/simple/get_state.dart

Called before [onDelete] method. [onClose] might be used to dispose resources used by the controller. Like closing events, or streams before the controller is destroyed. Or dispose objects that can potentially create some memory leaks, like TextEditingControllers, AnimationControllers. Might be useful as well to persist some data on disk.

Copied from DisposableInterface.

The expression doesn't evaluate to a function, so it can't be invoked.dartinvocation_of_non_function_expression

No changes after using this

 @override
  void onClose() async {
    SystemChannels.textInput.invokeMethod('TextInput.hide');
    super.onClose();
  }
Eng-MohamedGadala commented 4 years ago

Screen Shot 2020-09-09 at 10 07 21 PM

Grohden commented 4 years ago

🤔 maybe a cache on dart analyzer? @eduardoflorence and @jonataslaw are right about 3.8.0 having only future (I couldn't find the 3.8.0 tag on the repo)

Future onClose() is the right signature

import 'package:flutter/services.dart';
import 'package:get/state_manager.dart';

class LoginController extends GetxController {
  @override
  Future onClose() {
    SystemChannels.textInput.invokeMethod('TextInput.hide');
    return super.onClose();
  }
}

Is accepted at my project using exactly 3.8.0 on AS. So I don't have any clue about why your analyzer is reporting errors.

You could try restarting it (if you don't know how, restarting vscode will probably restart the analysis server)

Eng-MohamedGadala commented 4 years ago

I did everything but not working the only working if I change get version to 3.4.6 Screen Shot 2020-09-09 at 10 24 05 PM Screen Shot 2020-09-09 at 10 25 36 PM

jpkontreras commented 4 years ago

tested in android studio with latest update get: "3.8.0"

Captura de Pantalla 2020-09-09 a la(s) 19 09 31

Could be the editor config ?

Eng-MohamedGadala commented 4 years ago

After using this part of the code no error but not working, onClose not calling any time.

@override
  Future get onClose async {
    SystemChannels.textInput.invokeMethod('TextInput.hide');
    return super.onClose;
  }

After using this part of the code show error and not working. on the android studio on the same project but after creating new project and add the same version on get: ^3.8.0

   @override
  Future onClose()  {
    SystemChannels.textInput.invokeMethod('TextInput.hide');
    return super.onClose();
  }

THIS IS MAGIC FOR ME after opening GetXController, I Found the reason like the image I add the same get:^3.8.0 in both project's but get_state.dart file not the same content and version old project 3.8.0 but new project 3.10.1 I don't now reason but that happened

Screen Shot 2020-09-10 at 11 43 58 AM Screen Shot 2020-09-10 at 11 45 56 AM

Thank's for everyone to try to help me.

jonataslaw commented 4 years ago

As I couldn't reproduce this in the last version, I'm closing it. If you face problems, you can open another issue, or use the platform channels to ask for quick help