getx icon indicating copy to clipboard operation
getx copied to clipboard

Issue when using multiple GetMaterialApp

Open prashant-angelbroking opened this issue 2 years ago • 3 comments

I have a container app, that uses getx. It uses GetMaterialApp at its root. I have another flutter module included as a path dependency in container apps pupspec.yaml file. The module is totally independent and separate. The module also uses getx for navigation with GetMaterialApp at its root. From my container app, when I navigate to the module view using Get.to(), I get a blank screen with error in console

Container App

void main() async {
  runApp(MainView());
}

class MainView extends StatelessWidget{
  String? themeFromDevice;

  MainView({String? theme}) {
    themeFromDevice = theme;
  }

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
        debugShowCheckedModeBanner: false,
        initialRoute: '/',
        navigatorObservers: <RouteObserver<ModalRoute<void>>>[routeObserver],
        getPages: [
          GetPage(
            name: '/',
            page: () => StatelessWidgetWrapper(screenWidget: HomeScreen(theme: themeFromDevice,)),
          ),
        ]
    );
  }
}

Container app pubspec

name: home_module
description: A new flutter module project.
version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  lottie: ^1.1.0
  device_info_plus: ^3.1.1
  dart_ipify: ^1.1.1
  webview_flutter: ^2.3.1
  url_launcher: ^6.0.17
  external_app_launcher: ^2.0.2
  package_info: ^2.0.2
  visibility_detector: ^0.2.2
  encrypt: ^5.0.1
  youtube_player_flutter: ^8.0.0
  module1:
    path: ../module1
  get: 4.6.1



dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^1.0.4


Module App

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

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

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
       
        primarySwatch: Colors.blue,
      ),
      home: const ModuleHomePage(title: 'Screen 1'),
    );
  }
}

From Container app, launch the module app using Get.to(() => MyApp()); (MyApp is from module app)

Error Produced:

======== Exception caught by widgets library ======================================================= The following assertion was thrown while finalizing the widget tree: Duplicate GlobalKey detected in widget tree.

The following GlobalKey was specified multiple times in the widget tree. This will lead to parts of the widget tree being truncated unexpectedly, because the second time a key is seen, the previous instance is moved to the new location. The key was:

  • [LabeledGlobalKey<ScaffoldMessengerState>#f27a2] This was determined by noticing that after the widget with the above global key was moved out of its previous parent, that previous parent never updated during this frame, meaning that it either did not update at all or updated before the widget was moved, in either case implying that it still thinks that it should have a child with that global key. The specific parent that did not update after having one or more children forcibly removed due to GlobalKey reparenting is:
  • Builder(dependencies: [MediaQuery]) A GlobalKey can only be specified on one widget at a time in the widget tree. When the exception was thrown, this was the stack: #0 BuildOwner.finalizeTree. (package:flutter/src/widgets/framework.dart:2991:15) #1 BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3016:8) #2 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:893:19) #3 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:370:5) #4 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146:15) #5 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1083:9) #6 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:997:5) #10 _invoke (dart:ui/hooks.dart:151:10) #11 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5) #12 _drawFrame (dart:ui/hooks.dart:115:31) (elided 3 frames from dart:async) ====================================================================================================

Getx Version: 4.6.1

prashant-angelbroking avatar Jul 13 '22 09:07 prashant-angelbroking

facing this issue, any update?

lalit3102 avatar Nov 25 '22 18:11 lalit3102

@jonataslaw are you checking this one?

lalit3102 avatar Nov 29 '22 14:11 lalit3102

use GetMaterialApp only on the MyApp only other pages just use materialapp

censusg avatar Apr 15 '24 09:04 censusg