I am trying to add an action extension to my app. Users can share selected photos directly from the Share sheet to the application.
Action extension call the application like myapp://photo-share
So at this point, the application should handle this deep-link and open a nested screen. Here is the basic structure for routing.
/ Initial Route
-- home Home screen (Sheel route)
---- add-record Add Record Screen
------ take-photo Take photo screen
GoRoute(path: "/", pageBuilder: (BuildContext context, GoRouterState state) => const SplashScreen(showLoader: false)),
GoRoute(path: "home", pageBuilder: (BuildContext context, GoRouterState state) => const HomeScreen(),
routes: [
GoRoute(path:"add-record", pageBuilder: (BuildContext context, GoRouterState state) => const AddRecordScren(),
routes: [
GoRoute(path: "take-photo", pageBuilder: (BuildContext context, GoRouterState state) => const CupertinoPage(fullscreenDialog: true, child: TakePhotoScreen())),
]),
])
Normally users open the app, go to Add Record Screen, and tap the Take Photo button. Which opens a fullScreenDialog for taking a photo. Now I want to use the Action extension to directly send the selected photo to Take Photo Screen.
I tried several things but I couldn't find the correct way.
The first thing I tried, was directly call the take-photo route. Because it is the child of add-record, so assumed that GoRouter could handle nested navigation. Unfortunately, it didn't work like I was expecting.
Then I tried to add-record-with-photo route and called the same screen. I passed a constructor variable here then I checked that variable in initState or didChangeDependencies like below.
// route declarations
GoRoute(path: "/", pageBuilder: (BuildContext context, GoRouterState state) => const SplashScreen(showLoader: false)),
GoRoute(path: "home", pageBuilder: (BuildContext context, GoRouterState state) => const HomeScreen(),
routes: [
GoRoute(path:"add-record", pageBuilder: (BuildContext context, GoRouterState state) => const AddRecordScren(),
routes: [
GoRoute(path: "take-photo", pageBuilder: (BuildContext context, GoRouterState state) => const CupertinoPage(fullscreenDialog: true, child: TakePhotoScreen())),
]),
GoRoute(path:"add-record-take-photo", pageBuilder: (BuildContext context, GoRouterState state) => const AddRecordScren(takePhoto:true),
)
])
// handling the variable in add-record screen
@override
void didChangeDependencies() {
super.didChangeDependencies();
if(widget.takePhoto){
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
context.push("/take-photo");
});
}
}
The last method worked but this time dialog screen has no close button on the left top. It wasn't working like push, it was working like go.
Also if I navigate via bottom navigation it throws an exception about GlobalKey
FlutterError (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:
- [GlobalObjectKey int#a4a92]
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:
- KeyedSubtree-[GlobalKey#9924e]
A GlobalKey can only be specified on one widget at a time in the widget tree.)
All I want is to open a nested page in fullscreen mode automatically with go_router.
Do you have any suggestions?