Home > database >  How to open bottom sheet without context(deep link)
How to open bottom sheet without context(deep link)

Time:07-01

I tried to open bottom sheet with the help of deep link but it couldn't make it due to the context.

CodePudding user response:

You can set a global key for your navigation

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

Pass into MaterialApp

MaterialApp(
      title: 'MyDemoApp',
      onGenerateRoute: generateRoute,
      navigatorKey: navigatorKey,
    );

Push to routes or open bottom sheet using global context. Exp:

navigatorKey.currentState.pushNamed('/someRoute');

See also

2nd option is get_it

CodePudding user response:

Use get plugin like this

ElevatedButton(
  child: Text('Show bottomsheet'),
  onPressed: () {
    Get.bottomSheet( 
      Container(
        height: 150,
        color: Colors.greenAccent,
        child: Column(
          children: [
            Text('Text'),
          ],
        )
      ),
      barrierColor: Colors.red[50],
      isDismissible: false,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
        side: BorderSide(
          width: 5,
          color: Colors.black
        )
      ),
      enableDrag: false,
    );
  },
),

CodePudding user response:

 Get.bottomSheet(//your widget);
  • Related