Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RouterReportManager base on _current to delete Controller is Not a good idae #3078

Open
gaoxuefeng opened this issue Apr 16, 2024 · 3 comments
Assignees

Comments

@gaoxuefeng
Copy link

when pageA pop dialogB use Get.bottomSheet to show a dialog ,RouterReportManager._current will change to dialogB ,if AController generate late than dialogB, AController will bind to dialogB; only dialogB Close , AController will call onClose and onDelete

@gaoxuefeng
Copy link
Author

it should find it really Route by context,then bind Controller key to route

@jonataslaw
Copy link
Owner

Thank you for your report.
Could you please provide a reproducible code snippet?

@gaoxuefeng
Copy link
Author

gaoxuefeng commented Apr 24, 2024

import 'package:flutter/material.dart';
import 'package:get/get.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      getPages: [
        GetPage(
            participatesInRootNavigator: true,
            name: '/first',
            page: () => const First()),
      ],
      debugShowCheckedModeBanner: false,
    );
  }
}

class FirstController extends GetxController {
  RxBool isShowedTip = RxBool(false);

  @override
  void onInit() async {
    super.onInit();
  }

  @override
  void onClose() {
    print('on close first');
    super.onClose();
  }
}

class First extends StatefulWidget {
  const First({Key? key}) : super(key: key);

  @override
  State<First> createState() => _FirstState();
}

class _FirstState extends State<First> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FirstController>(
        init: FirstController(),
        tag: "first_controller",
        builder: (controller) {
          return Scaffold(
            body: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                GestureDetector(
                  onTap: () {
                    Future.delayed(Duration(milliseconds: 100), () {
                      controller.isShowedTip.value = true;
                    });
                    Get.bottomSheet(
                      Container(
                        color: Colors.blue,
                        height: 100,
                      ),
                      settings: RouteSettings(name: "test-route"),
                    );
                  },
                  child: Container(
                    width: 100,
                    height: 50,
                    color: Colors.green,
                    child: Center(
                      child: Text("show bottom sheet"),
                    ),
                  ),
                ),
                Obx(() {
                  if (controller.isShowedTip.value) {
                    return ChildWidget();
                  } else {
                    return Center();
                  }
                }),
              ],
            ),
          );
        });
  }
}

class ChildWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<ChildWidgetController>(
      init: ChildWidgetController(),
      builder: (controller) {
        return Center(
          child: Container(
            width: 100,
            height: 100,
            color: Colors.blue,
            child: Text("child view"),
          ),
        );
      },
    );
  }
}

class ChildWidgetController extends GetxController {
  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onClose() {
    print('on close child');
    super.onClose();
  }
}

run code in demo., click 'show bottom sheet' ,after bottom sheet show at least 2 second ,close bottoon sheet , console will print "on close child" ;
the ChildWidgetController was bind to BottomSheet ,so it was deleted when BottomSheet dismiss. GetController shound not bind to top roure, it should bind to really route get by view context

@jonataslaw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants