createRoute method
Creates the Route that corresponds to this page.
The created Route must have its Route.settings property set to this Page.
Implementation
@override
Route<T> createRoute(BuildContext context) {
final t = ComicTheme.of(context);
// Read as it builds: a window that grows takes the sheet with it.
double most(BuildContext sheetContext) =>
MediaQuery.sizeOf(sheetContext).height * .9;
Widget current(BuildContext sheetContext) {
final page = ModalRoute.of(sheetContext)?.settings;
return page is ComicSheetPage ? page.child : child;
}
// A sheet on a desktop is a phone-wide panel, so its parts lay out as they do on a phone: one column, phone type.
Widget card(BuildContext sheetContext) {
final media = MediaQuery.of(sheetContext);
return MediaQuery(
data: media.copyWith(
size: Size(
media.size.width < 560 ? media.size.width : 560,
media.size.height,
),
),
child: ComicTheme(
data: t,
child: RoutePresentationScope(
presentation: RoutePresentation.sheet,
child: DecoratedBox(
decoration: ShapeDecoration(
color: t.colors.card,
shape: t.shapes.large.copyWith(
side: BorderSide(color: t.colors.nightLine, width: t.rim(3)),
),
),
child: Material(
type: MaterialType.transparency,
child: current(sheetContext),
),
),
),
),
);
}
if (fullScreen) {
return MaterialPageRoute<T>(
settings: this,
fullscreenDialog: true,
builder: (sheetContext) => RoutePresentationScope(
presentation: RoutePresentation.sheet,
child: ColoredBox(
color: t.colors.background,
child: current(sheetContext),
),
),
);
}
if (t.desk) {
return ComicDialogRoute<T>(
screenInk: t.colors.scrim,
settings: this,
barrierDismissible: true,
barrierLabel: DesignLocalizations.of(context).closeButtonLabel,
builder: (sheetContext) => Center(
child: SizedBox(
width: 560,
height: drawer ? null : most(sheetContext),
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: most(sheetContext)),
child: card(sheetContext),
),
),
),
);
}
// The route stands the panel above the keyboard.
return ComicBottomSheetRoute<T>(
screenInk: t.colors.scrim,
settings: this,
builder: (sheetContext, _) => ConstrainedBox(
constraints: BoxConstraints(maxHeight: most(sheetContext)),
child: SizedBox(
height: drawer ? null : most(sheetContext),
child: card(sheetContext),
),
),
);
}