ldFrame function
Widget
ldFrame({
- required Widget child,
- LdThemeBrightnessMode brightnessMode = LdThemeBrightnessMode.light,
- LdThemeSize? size,
- LdFrameOptions ldFrameOptions = const LdFrameOptions(),
- Orientation orientation = Orientation.portrait,
- bool showBackButton = false,
Create a frame for a widget to be used in golden tests.
Implementation
Widget ldFrame({
required Widget child,
LdThemeBrightnessMode brightnessMode = LdThemeBrightnessMode.light,
LdThemeSize? size,
LdFrameOptions ldFrameOptions = const LdFrameOptions(),
Orientation orientation = Orientation.portrait,
bool showBackButton = false,
}) {
GoRouter router(Function(BuildContext, GoRouterState) app) {
return GoRouter(
initialLocation: showBackButton ? '/child' : '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) => app(context, state),
routes: [
GoRoute(
path: 'child',
builder: (context, state) => app(context, state),
),
],
),
],
);
}
return KeyedSubtree(
// force a new subtree each time a new frame is created in order to avoid
// state issues
key: UniqueKey(),
child: LdThemeProvider(
size: size,
platform: ldFrameOptions.platform,
brightnessMode: brightnessMode,
child: LdThemedAppBuilder(
appBuilder: (context, theme) => MaterialApp.router(
theme: theme,
debugShowCheckedModeBanner: false,
locale: LiquidLocalizations.supportedLocales.first,
supportedLocales: LiquidLocalizations.supportedLocales,
localizationsDelegates: [
...ldGoldenLocalizationsDelegates,
...LiquidLocalizations.localizationsDelegates,
],
routerConfig: router(
(context, state) {
var padding = ldFrameOptions.viewPaddig;
if (orientation == Orientation.landscape) {
// Rotate the padding, left
padding = EdgeInsets.only(
left: padding.top,
top: padding.right,
right: padding.bottom,
bottom: padding.left,
);
}
return MediaQuery(
data: MediaQuery.of(context).copyWith(
viewPadding: padding,
padding: padding,
viewInsets: padding,
),
child: SystemOverlayDetector(
builder: (context, style) {
if (ldFrameOptions.build != null) {
return ldFrameOptions.build!(
context,
orientation,
switch (style) {
null => switch (brightnessMode) {
LdThemeBrightnessMode.light =>
SystemUiOverlayStyle.dark,
LdThemeBrightnessMode.dark =>
SystemUiOverlayStyle.light,
_ => null
},
_ => style,
},
child,
);
}
return child;
},
),
);
},
),
),
),
),
);
}