jonataslaw / getx

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

A TextEditingController was used after being disposed #2970

Open BBUBBA opened 9 months ago

BBUBBA commented 9 months ago

Describe the bug If an existing getXcontroller is deleted late, a controller Dispose error such as texteditcontroller and scrollbarcontroller occurs.

  1. An error occurs when moving the menu quickly. (An error occurs if the same controller has not yet been deleted.) ( If my client's hand is fast, can see a red error. )

  2. when try refresh self Page by Get.offAllNamed <-- dispose error.. textedingcontroller scrollbarcontroller...

**Reproduction code

if your getxcontroller name is "/" and have texteditingcontroller. call Get.offAllNamed('/'); you can See Error...

example:

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      initialRoute: '/',
      getPages: [
        GetPage(
          name: '/',
          page: () => Page1(),
          binding: BindingsBuilder(() => Get.lazyPut(() => Controller1())),
        ),
      ],
    );
  }
}

class Controller1 extends GetxController
{

  final textController = TextEditingController();

  @override
  void onClose()
  {
    textController.dispose();
    super.onClose();
  }

}

class Page1 extends GetView<Controller1> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          TextFormField(
            controller: controller.textController,
          ),
          TextButton(
            onPressed: () {
              Get.offAllNamed('/');
            },
            child: Text('go page2'),
          )
        ],
      ),
    );
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Run
  2. go home click
  3. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots

case 1. if hand is fast..

https://github.com/jonataslaw/getx/assets/17864839/70934d34-ad80-4341-9324-70527c4f93c9

case 2. refresh self page..

https://github.com/jonataslaw/getx/assets/17864839/e7cd3c2f-b38d-4a0b-9d3c-c5cf54823c54

Flutter Version: 3.16

Getx Version: 4.6.6

Describe on which device you found the bug: Web

jhembedded commented 1 month ago

I encountered the same problem, have you solved it?

jhembedded commented 1 month ago

I encountered the same problem, have you solved it?

android 11, flutter_windows_3.13.5-stable

BBUBBA commented 1 week ago

I encountered the same problem, have you solved it?

android 11, flutter_windows_3.13.5-stable

I don't remember it well because it's over time, I think I injected my dependency dynamically by injecting guid into Controller1.