This repository has been archived by the owner on Feb 25, 2022. It is now read-only.
Support for ModalRoute #119
ricksondpenha
started this conversation in
General
Replies: 1 comment
-
I'm happy to consider a PR.
…On Fri, Oct 29, 2021, 9:39 PM Rickson Dpenha ***@***.***> wrote:
Hi, I've a requirement wherein during web (desktop mode) i want the page
to look like a overlay modal instead of a complete page covering up the
screen. I've tried using customTransitionPage where i made the barrier
color transparent and opaque = false, but i am still not able to see the
contents behind this page. It might be because the customPageTransition
extends page and page route, we might need a new class for extending
ModalRoute to overlay widgets in such cases.
this code for modal route works for me, is there any way to bake in this
feature in go_router itself?
class TutorialOverlay extends ModalRoute<void> {
@OverRide
Duration get transitionDuration => Duration(milliseconds: 500);
@OverRide
bool get opaque => false;
@OverRide
bool get barrierDismissible => false;
@OverRide
Color get barrierColor => Colors.black.withOpacity(0.5);
@OverRide
String get barrierLabel => null;
@OverRide
bool get maintainState => true;
@OverRide
Widget buildPage(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
) {
// This makes sure that text and other content follows the material style
return Material(
type: MaterialType.transparency,
// make sure that the overlay content is not cut off
child: SafeArea(
child: _buildOverlayContent(context),
),
);
}
Widget _buildOverlayContent(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'This is a nice overlay',
style: TextStyle(color: Colors.white, fontSize: 30.0),
),
RaisedButton(
onPressed: () => Navigator.pop(context),
child: Text('Dismiss'),
)
],
),
);
}
@OverRide
Widget buildTransitions(
BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
// You can add your own animations for the overlay content
return FadeTransition(
opacity: animation,
child: ScaleTransition(
scale: animation,
child: child,
),
);
}
}
// Example application:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Playground',
home: TestPage(),
);
}
}
class TestPage extends StatelessWidget {
void _showOverlay(BuildContext context) {
Navigator.of(context).push(TutorialOverlay());
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Test')),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Center(
child: RaisedButton(
onPressed: () => _showOverlay(context),
child: Text('Show Overlay'),
),
),
),
);
}
}```
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#118>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AATTAPOH5DYILVSLLKN3T43UJNZG5ANCNFSM5HAUDNNA>
.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I've a requirement wherein during web (desktop mode) i want the page to look like a overlay modal instead of a complete page covering up the screen. I've tried using customTransitionPage where i made the barrier color transparent and opaque = false, but i am still not able to see the contents behind this page. It might be because the customPageTransition extends page and page route, we might need a new class for extending ModalRoute to overlay widgets in such cases.
this code for modal route works for me, is there any way to bake in this feature in go_router itself?
Beta Was this translation helpful? Give feedback.
All reactions