juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.09k stars 504 forks source link

Back Button on App Bar is not working in Iphone Real Device #965

Open asbn223 opened 1 week ago

asbn223 commented 1 week ago

Describe the bug Back Button on App Bar is not working in Iphones. I tried everything but it didn't work

My Code

class CustomUnityArScreen extends StatefulWidget {
  const CustomUnityArScreen({
    super.key,
  });

  @override
  State<CustomUnityArScreen> createState() => _CustomUnityArScreenState();
}

class _CustomUnityArScreenState extends State<CustomUnityArScreen> {
  late UnityWidgetController _unityWidgetController;

  void _sendMessageToUnity() async {
    await _unityWidgetController.postMessage(
      'MainOrigin',
      'OnMessage',
      'Hello From Flutter with token',
    );
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          // leading: IconButton(
          //   icon: const Icon(Icons.arrow_back),
          //   onPressed: () async {
          //     if (await _unityWidgetController.isReady() ?? false) {
          //       _unityWidgetController.unload();
          //       _unityWidgetController.dispose();
          //     }
          //     Get.back();
          //   },
          // ),
          ),
      body: UnityWidget(
        onUnityCreated: _onUnityCreated,
        onUnityMessage: onUnityMessage,
        onUnitySceneLoaded: onUnitySceneLoaded,
        useAndroidViewSurface: true,
        fullscreen: false,
        hideStatus: false,
        uiLevel: 0,
        gestureRecognizers: {},
        borderRadius: const BorderRadius.all(Radius.circular(70)),
      ),
    );
  }

  void onUnityMessage(message) {
    print('Received message from unity: ${message.toString()}');
  }

  void onUnitySceneLoaded(SceneLoaded? scene) {
    if (scene != null) {
      print('Received scene loaded from unity: ${scene.name}');
      print('Received scene loaded from unity buildIndex: ${scene.buildIndex}');
    } else {
      print('Received scene loaded from unity: null');
    }
  }

  // Callback that connects the created controller to the unity controller
  void _onUnityCreated(UnityWidgetController controller) async {
    _unityWidgetController = controller;
    await Future.delayed(const Duration(milliseconds: 2000));
    await _unityWidgetController.resume();
  }

// void _onUnityCreated(controller) async {
//   controller.resume();
//   _unityWidgetController = await controller;
//
//   if (widget.isInit) {
//     Future.delayed(
//       const Duration(milliseconds: 300),
//       () async {
//         await _unityWidgetController.unload();
//         Get.back();
//         Future.delayed(
//           const Duration(milliseconds: 500),
//         ).then(
//           (value) => widget.initCallback(),
//         );
//       },
//     );
//   }
// }
}

Screenshots If applicable, add screenshots to help explain your problem.

Unity (please complete the following information):

Smartphone (please complete the following information):